Zero downtime on Heroku

試著忘記壹切 提交于 2019-12-03 12:21:47

I can't address migrations, but the part about restarting processes and avoiding wait time:

There is an beta feature for heroku called preboot. After a deploy, it boots your new dynos first and waits a while before switching traffic and killing the old ones:

https://devcenter.heroku.com/articles/labs-preboot/

I also wrote a blog post that has some measurements on my app's performance improvements using this feature:

http://ylan.segal-family.com/blog/2012/08/27/deploy-to-heroku-with-near-zero-downtime/

Michael van Rooijen

You might be interested in their feature called preboot.

Taken from their documentation:

This feature provides seamless deploys by booting web dynos with new code before killing existing web dynos.

Some apps take a long time to boot up, and this can cause unacceptable delays in serving HTTP requests during deployment.

There are a few caveats:

  • You must have at least two web dynos to use this feature. If you have your web process type scaled to 1 or 0, preboot will be disabled.
  • Whoever is doing the deployment will have to wait a few minutes before the new code starts serving user requests; this happens later than it would without preboot (but in the meanwhile, user requests are still served promptly by old dynos).
  • There will be a short period (a minute or two) where heroku ps shows the status of the new code, but user requests are still being served by old code.

There is much more information about it, so refer to their documentation.

It is possible, but requires a fair amount of forward planning. As of Rails 3.1 there's three tasks that need carrying out

  • Upload the new code
  • Run any database migrations
  • Sync the assets

Uploading code and restarting is fairly straightforward, the main problem lies with the other two, but the way round them is the pretty much the same.

Essentially you need to:

  • Make the code compatible with the migration you need to run
  • Run the migration, and remove any code written specifically for it

For instance, if you want to remove a column, you’ll need to deploy a patch telling ActiveRecord to ignore it first. Only then you can deploy the migration, and clean up that patch.

In short, you need to consider your database and the code compatability an work around them so that the two can overlap in terms of versioning.

An alternative to this method might be to have two versions of the application running on Heroku at the same time. When you deploy, switch the domain to the other version, do the deploy, and switch it back again. This will help in most instances, but again, database compat is an issue.

Personally, I would say that if your deployments are significant to require this sort of consideration, taking parts of the application offline are probably the safest answer. By breaking up an application into several smaller applications can help mitigate this and is a mechanism that I use regularly.

No - this is currently not possible using Unicorn on Heroku cedar. I've been bugging Heroku about this for weeks.

Here was Heroku Support's reply to my email on March 8, 2012:

Hi, you could enable maintenance mode when doing a deploy, at least your users would see a maintenance page instead of an error, and also request queue wouldn't build up.

We're definitely aware this is a pain and we're working to offer rolling / zero-downtime deploys in the future. We have no ETA to announce, though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!