Restarting cloudfoundry apps without downtime

When running an application on Cloudfoundry it’s possible to start multiple instances of an application. This might be for performance reasons, but also by means of reliability. When restarting an application the default behaviour is first stopping all instances of an application and the starting them again. This results in a small downtime when there is no running instance available. Let’s see how to improve this approach.

But there is an alternative way of restarting all instances of an cloudfoundry application by using the cf recycle plugin.

The default behaviour

As already described, the default behaviour is stopping all instances of an application and then starting the applications again. Depending on the type of application the start time of the application differs. But this always results in a downtime. That might be a few seconds only, but could be a fat application server too, that requires minutes to start.

The following snipped describes what happens when restarting an application with two instances:

$ cf restart static-dummy
Stopping app static-dummy in org test / space test as user@example.com...
OK

At first all instances go down.

Starting app static-dummy in org test / space test as user@example.com...

0 of 2 instances running, 2 starting
2 of 2 instances running

App started

OK

App static-dummy was started using this command sh boot.sh

Showing health and status for app static-dummy in org test / space test as user@example.com...
OK

requested state: started
instances: 2/2
usage: 64M x 2 instances
urls: dummy.example.com
last uploaded: Thu Jan 1 00:00:00 UTC 1970
stack: cflinuxfs2
buildpack: https://github.com/cloudfoundry-incubator/staticfile-buildpack#v1.3.1

state since cpu memory disk details
#0 running 1970-01-01 00:00:00 AM 0.2% 5.7M of 64M 7.1M of 1G
#1 running 1970-01-01 00:00:00 AM 0.2% 8.6M of 64M 6.9M of 1G

In the second step both instances will be started again.

Installing the cf-recycle-plugin

In order to gain the advantage of having no downtime the plugin must be installed at first.

Installing the cf-recycle-plugin of course assumes that the cf client is installed properly. But it’s quite simple. Only run the following command on the shell:

cf install-plugin -r CF-Community "cf-recycle-plugin"

This installs the cf-recycle-plugin that is located in the “CF-Community plugin repository”.

Using the cf-recycle-plugin

After the installation was successful the plugin can be used. So let’s have some no downtime.

In order to recycle an app, simply run

cf recycle {app}

instead of

cf restart {app}

That’s it. Nothing more required. The cf recycle plugin handles all the other stuff. It picks all the running instances and then restarts the instances one by one.

What the output now looks like

The following snippet describes the command line output when using the cf recycle plugin.

Instance 0 Status: running
Restarting static-dummy instance: 0
Instance 0 Status: down
Instance 0 Status: down
Instance 0 Status: starting
Instance 0 Status: running
Instance 1 Status: running
Restarting static-dummy instance: 1
Instance 1 Status: down
Instance 1 Status: running

Compared to the cf restart command cf recycle restarts all the instances one by one instead of shutting them down completely and then starting all instances again. For this reason there will be no downtime as there is always at least one instance up and running.

Of course there must be at least two instances running in order to get the no downtime feature.
Furthermore recycling all instances of an application requires significantly more time, but at that cost there will be not downtime. I prefer minimizing the downtime.

Sources

cf-recycle-plugin
cloudfoundry.org
cloudfoundry plugin repository

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.