Skip to content

Zero downtime restart

fatum edited this page Jan 2, 2015 · 7 revisions

Goliath could be restarted seamlessly using shared socket manager Einhorn without dropping any requests.

How it works?

Your should run goliath using einhorn -n COUNT -b 127.0.0.1:3000 ruby app.rb --einhorn command.

Then Einhorn will open socket on master process and spawn goliath's processes which will receive socket's file descriptor number using environment variable. Goliath should be spawned with --einhorn option which tell them to attach server to already opened socket.

Einhorn should wait for an explicit acknowledgement from the process, by default, Einhorn will use a timer ack of 1 second. That means that if your process hasn't exited after 1 second, it is considered ACK'd and healthy. You can modify this timeout to be more appropriate for your application (and even set to 0 if desired). Just pass a -m FLOAT.

Also you can use -m manual option if you want to send manual ack from your process when it's ready for serving requests. For example

require 'einhorn/worker'
Einhorn::Worker.ack!

When you need to upgrade your code simple run einhornsh -e upgrade command. Once the new workers have been spawned and ack'd, Einhorn will send each old worker a SIGUSR2. SIGUSR2 should be interpreted as a request for a graceful shutdown.

Additional

  • You can dynamically change the number of goliath processes (einhornsh -e 'set_workers N').
  • Einhorn has no dependencies outside of the Ruby standard library.

Example

https://github.com/fatum/goliath-zero-downtime