开发者

Is it ok to check the Heroku queue depth/wait_time and set dynos accordingly after every action in my app?

开发者 https://www.devze.com 2023-02-17 15:57 出处:网络
I am trying to work out how to respond to increasing/decreasing traffic to my Heroku site with dynos management from within the app itself.

I am trying to work out how to respond to increasing/decreasing traffic to my Heroku site with dynos management from within the app itself.

I know you can access HTTP_X_HEROKU_QUEUE_DEPTH or HTTP_X_HEROKU_QUEUE_WAIT_TIME and use those to set the amount of dynos. What I'm wondering is what process to use to do the checking.

Is it okay to add an after_filter to every action in the app to do a check against some threshold, and if a threshold has b开发者_运维知识库een met, change the number of dynos? I would only have 5/6 thresholds, so for vast majority of users the only impact would be the increased time it takes to do the check, and then for a handful of users it would be the check + the changing of dynos time.

Would it be too much of an inconvenience to the users? Is there a better way?


This could slow every request down to the point of turning away users. I haven't tried it though. There are ways of tackling this by using background processes.

Have a look at what others have done:

  • http://blog.darkhax.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
  • https://www.heroscale.com/ is actually a business that's built around what you're trying to do.

Other examples:

  • https://github.com/ddollar/heroku-autoscale
  • https://github.com/pedro/delayed_job/tree/autoscaling
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号