Glassfish_logo.svgI manage a small application that is hosted on a single Linux virtual machine and have noticed some occasional performance and stability issues.

The server runs CentOS, MySQL and a GlassFish server. I chose GlassFish several years ago because at the time it was the only EJB3 container around, as well as being very well integrated with the NetBeans IDE.

Like most JavaEE containers, it also makes clustering and scaling easier.

So to begin the process of improving the performance of the application, I decided to migrate the database to a shiny new RackSpace Cloud Database.

Setting up the database is easily done through their “MyCloud” control panel, just name the instance, add a DB and user and it’s ready to roll (almost). Just like the local database on the VM, it’s not available outside the firewall, but as long as you have a VM, you can use the SSH tunnel connection (available in most of the MySQL tools).

The next step is to make sure and shut down the application (just in case anybody is trying to update in the wee hours of the weekend) to make sure no data is lost. So I simply ssh to the server in question, and shut down the service:

And just to be certain, I bounce MySQL:

Once that is done, I know there are no more connections to the DB, so I run the backup command (replacing database_name with the name of the DB in question following the instructions at importing-data-to-cloud-databases):

With SQL in hand, I can then send it directly to the new Cloud Database with:

Now we have a copy of the database, it’s time to adjust the server to point to it. Luckily with a good JavaEE application, this is as simple as repointing the JDBC pool. Going to the GlassFish admin console, I drill down to the connection:

glassfish_jdbc

For this, all I have to do is change the serverName and URL to use the hostname from the instance control panel and replace “localhost” with that name. Once the change is made, I simply go to the main tab and click the “Ping” button to make sure it works.

Some minor cleanup is still left to make sure the MySQL database doesn’t start up on the GlassFish server, and for my application there were some minor tweaks I had to make to allow it to function (like increasing the max_allowed_packets on the cloud database).

So with this quick change, I have moved from a single tier to a two tier setup. This will hopefully help me figure out where the contention is happening, and decide if I need to scale up the database or the application server.