简体   繁体   English

heroku独角兽超时在下载文件时不起作用

[英]heroku unicorn timeout doesn't work when downloading files

I'm running a rails 4 app on Heroku with Unicorn. 我正在与Unicorn一起在Heroku上运行Rails 4应用程序。

This app creates a fairly large xls file 这个应用程式会建立一个相当大的xls档案

To give it enough time, I increased the timeout via config/unicorn.rb: 为了给它足够的时间,我通过config / unicorn.rb增加了超时时间:

timeout 240 超时240

This doesn't work when I run the page generating the xls file, a timeout occurs after 3001ms. 当我运行生成xls文件的页面时,此方法不起作用,3001ms之后发生超时。

Why? 为什么?

This is my log: 这是我的日志:

2014-04-29T13:43:27.323190+00:00 app[web.1]: I, [2014-04-29T13:43:27.323084 #8]  INFO -- : Started GET "/live_sales.xls?action=index&controller=live_sales" for 81.244.45.218 at 2014-04-29 13:43:27 +0000
2014-04-29T13:43:27.340252+00:00 app[web.1]: D, [2014-04-29T13:43:27.340190 #8] DEBUG -- : logged in? true
2014-04-29T13:43:27.339294+00:00 app[web.1]: I, [2014-04-29T13:43:27.339181 #8]  INFO -- : Processing by LiveSalesController#index as XLS
2014-04-29T13:43:27.345465+00:00 app[web.1]: D, [2014-04-29T13:43:27.345383 #8] DEBUG -- :   ItemRef Load (3.1ms)  SELECT gamme FROM "item_refs" WHERE (gamme is not null and gamme <> '') GROUP BY gamme
2014-04-29T13:43:28.577687+00:00 app[web.1]: D, [2014-04-29T13:43:28.577526 #8] DEBUG -- :   LiveSale Load (1210.0ms)  SELECT invoice_date, item_refs.item_brand, item_refs.item_label, item_refs.gamme, item_refs.sub_gamme, item_refs.id, item_refs.item_reference, item_refs.date_published, item_refs.date_unpublished, item_refs.price_purchase, item_refs.current_stock, item_refs.item_published,
2014-04-29T13:43:28.577694+00:00 app[web.1]:  sum(price_purchase * current_stock) as stock_value,sum(quantity) as quantity,
2014-04-29T13:43:28.577697+00:00 app[web.1]:  sum(price_purchase * quantity) as total_purchase FROM "live_sales" left join item_refs on item_refs.id = live_sales.item_ref_id and item_refs.item_published is true and item_refs.disabled is false WHERE ((invoice_date between '2014-03-29 13:43:27 +0000' and '2014-04-29 13:43:27 +0000')) GROUP BY invoice_date, item_refs.item_brand, item_refs.item_label, item_refs.gamme, item_refs.sub_gamme, item_refs.id, item_refs.item_reference, item_refs.date_published, item_refs.date_unpublished, item_refs.price_purchase, item_refs.current_stock, item_refs.item_published ORDER BY invoice_date asc, 
2014-04-29T13:43:57.331088+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/live_sales.xls?action=index&controller=live_sales host=azzanalytics.herokuapp.com request_id=6e67b74e-3db8-4853-b5c6-c1f884eaa31e fwd="81.244.45.218" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0

Thanks! 谢谢!

the suggestion is: use a background process! 建议是:使用后台进程!

there is no way around it! 没有其他办法了! it is a best practice in web-apps to return to the client as fast as possible, because it frees up resources. 在网络应用中,最好的做法是尽快释放客户端,因为这样可以释放资源。 when you have just one dyno running at heroku and you have multiple requests, they will get blocked for your timeout and no user is able to access your page. 当您在heroku上仅运行一个dyno且您有多个请求时,它们将因您的超时而被阻止,并且没有用户能够访问您的页面。 you can easily have denial of service cases when you have such longrunning processes. 如果您的流程如此漫长,您很容易拒绝服务案例。 heroku timed out at 30 second regardless of you override it on your thin server 无论您在瘦服务器上覆盖它,heroku都会在30秒后超时

in case you do not want to do background processes because of the cost, have a look at freemium: https://github.com/phoet/freemium or delayed_job 如果您由于成本而不想执行后台处理,请查看免费增值服务: https : //github.com/phoet/freemiumdelay_job

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM