使用nginx时为什么会超时?

时间:2014-06-03 23:46:20

标签: ruby-on-rails ruby-on-rails-3 nginx

我在nginx上运行rails。然后,我可以立即向所有被监禁的用户发送电子邮件 我确实运行了这个,但它有时间错误。我怎样才能解决这个问题?如何修改配置?

控制器(超过10000个用户,这意味着此邮件程序重复10000次)

users.each do |user|
    if user.nomail.blank?
        CallMailer.call_email_to(user.email, subject, body).deliver
        sent_to_count = sent_to_count + 1
    end
end

然后它会出现这个超时错误。

The connection has timed out
The server www.foofooexample.com is taking too long to respond.

这是我的nginx的conf

等/ nginx的/ conf.d / foo.conf

server {
    listen 80;
    server_name foofooexample.com;
    root /var/www/html/foo/public;
    client_max_body_size 5M;

    keepalive_timeout  1200;
    proxy_connect_timeout 1200;
    proxy_read_timeout    1200;
    proxy_send_timeout    1200;
.
.
.

1 个答案:

答案 0 :(得分:1)

正如上面提到的评论之一,您希望使用sidekiq之类的内容将其卸载给后台工作人员,后者附带ActionMailer扩展名,用于在后台发送电子邮件。

安装后,而不是

CallMailer.call_email_to(user.email, subject, body).deliver

你会使用:

CallMailer.delay.call_email_to(user.email, subject, body)

此外,我建议您使用find_each代替each。这是因为each会将所有User个对象加载到内存中,而find_each会将它们分批加载。有关示例用法,请参阅链接的文档。