Hot Deploy on Heroku with No Downtime

How to prevent downtime on Node.js web server

You can use some process manager for node.js like PM2. You can setup restart strategies for your nodejs server. When it crush PM2 will restart it. See this docs. Also it can running you nodejs app in cluster mode - you can have separate instances of you app and PM2 will distribute all request between them.

Also if you nodejs process crash because some errors happen, try to process this errors in right way, without finish process. Add try catch when it necessary, handle async errors, etc..

How exactly does the Heroku deployment process work?

Here is what happens during a Heroku deploy (current as of 10/20/2011*)[1]:

  • Heroku receives your git push
  • A new release is compiled from the latest version of your app and stored
  • [These happen roughly simultaneously]
    • The dyno grid is signalled to terminate[2] all running processes for your app
    • The dyno grid is signalled to start new processes for your app
    • The dyno grid is signalled to unidle all idle processes of your app
    • The HTTP router is signalled to begin routing HTTP traffic to the web dynos running the new release

The general takeaway is that to minimize any possible downtime you should minimize the boot time of your app.

By following careful migration practices, it is possible to push new code and then migrate while the app is running.
Here's an example for Rails: http://pedro.herokuapp.com/past/2011/7/13/rails_migrations_with_no_downtime/

To minimize dropped connections during a restart, use a webserve that responds appropriately to SIGTERM by beginning a graceful shutdown (finish existing connections, dont take new ones). Newer versions of thin will handle SIGTERM correctly.

  1. This subject is the topic of much discussion internally and may
    change in the future.
  2. SIGTERM followed 10s later by SIGKILL if
    still running

Can Heroku be configured to do a true seamless deployment?

Regarding the dynos spin-up time, Heroku has a beta feature to address just that:

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

It basically boots your new dynos first, waits a while, switched traffic and only then kills the old ones. My app saw a marked improvement in performance during deploys. You can read it here:

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

Easy way to prevent Heroku idling?

You can install the free New Relic add-on. It has an availability monitor feature that will ping your site twice per minute, thus preventing the dyno from idling.

More or less the same solution as Jesse but maybe more integrated to Heroku... And with a few perks (performance monitoring is just great).

Availability monitoring

Note: to all those saying it doesn't work: the important part in my answer is "availability monitor". Just installing the addon won't help. You also need to setup the availability monitoring with the URL of your heroku app.

How to deploy an ASP.NET Application with zero downtime

You need 2 servers and a load balancer. Here's in steps:

  1. Turn all traffic on Server 2
  2. Deploy on Server 1
  3. Test Server 1
  4. Turn all traffic on Server 1
  5. Deploy on Server 2
  6. Test Server 2
  7. Turn traffic on both servers

Thing is, even in this case you will still have application restarts and loss of sessions if you are using "sticky sessions". If you have database sessions or a state server, then everything should be fine.



Related Topics



Leave a reply



Submit