CloudFoundry Tips and Flapping

Posted by {"display_name"=>"greg", "login"=>"greg", "email"=>"", "url"=>""} on December 24, 2011 · 3 mins read

I've been using CloudFoundry as a PaaS solution for a Grails application for several months now.  I tested it out with a small test application at first and it worked great but as I deployed a larger application I had regular issues. In particular, I had issues with failures in updating the application and starting the app.

I'm using the Grails CloudFoundry Plugin by Bert Beckwith and the CloudFoundry VMC command line tool.

I've come up with some guidelines and a procedure for updating my application that has been working well for the past few weeks. Some of these tips are Grails specific but are probably applicable to other apps.

Memory Configuration

There's a very good SpringSource blog posting by Peter Ledbrook called One-step Deployment with Grails and Cloud Foundry and although it doesn't say anything specifically about memory requirements, the example shows a grails app with a 1Gb memory setting. The Grails FAQ has a question on memory requirements which appears to have been written around the 1.0 release and it considers 512Mb to be a large memory configuration.

In the end, I think a small memory configuration can cause intermittent problems starting apps under CloudFoundry.  I believe 1Gb is a minimum for most applications and if you're having problems, go to 2Gb's to insure that memory is not your issue.  Once the app is stable, you can do testing with a lower memory configuration.

Updating, Startup and Flapping

I had lots of problems updating the app and getting it to start. Several different failures during the update or start process that I can't remember now but the process running in a "flapping" state is a common theme. I initially used the cloudfoundry plugin for grails but I had to start using the CloudFoundry VMC command options to diagnose the problems I was having.

In the end, I use the following process to update an existing grails application on CloudFoundry and I'm have much more success:

Stop grails app if running locally

$ vmc stop <appname>

Before I push the updated application I like to update DataSource.groovy and files at least with a new version number and build date. I then execute these commands relative to the Grails project root:

$ rm target/*
$ grails prod cf-update

If it succeeds, do vmc start and wait several minutes, ignore errors and check apps/instances

If it fails, first verify state with vmc apps & instances command, if flapping, allow time

$ vmc stop <appname>
$ rm target/*
$ grails prod war
$ cd target
$ vmc update <appname>
$ vmc start <appname>