Computer hardware has traditionally been a scarce, expensive resource. In the early days of computing developers had to share a single machine. Today each developer usually has their own machine but it’s rare for a developer to have more than one. This means that running performance tests often involves scavenging for machines. Likewise, replicating even just part of a production environment is a major undertaking. With Amazon’s Elastic Compute Cloud (EC2), however, things are very different. A set of Linux servers is now just a web service call away. Depending on the type of the servers you simply pay 10-80 cents per server per hour for up to 20 servers! No more upfront costs or waiting for machines to be purchased and configured.
To make it easier for enterprise Java developers to use EC2, I have created EC2Deploy. It’s a Groovy framework for deploying an enterprise Java application on a set of Amazon EC2 servers. EC2Deploy provides a simple, easy to use API for launching a set of EC2 instances; configuring MySQL, Apache and one or more Tomcat servers; and deploying one or more web applications. In addition, it can also run JMeter and collect performance metrics.
Here is an example script that launches some EC2 instances; configures MySQL with one slave, Tomcat and Apache; deploys a single web application on the Tomcat server; and runs a JMeter test with first one thread and then two.
class ClusterTest extends GroovyTestCase { void testSomething() { AWSProperties awsProperties = new AWSProperties("/…/aws.properties") def ec2 = new EC2(awsProperties) def explodedWar = '…/projecttrack/webapp/target/ptrack' ClusterSpec clusterSpec = new ClusterSpec() .schema("ptrack", ["ptrack": "ptrack"], ["src/test/resources/testdml1.sql", "src/test/resources/testdml2.sql"]) .slaves(1) .tomcats(1) .webApp(explodedWar, "ptrack") .catalinaOptsBuilder({builder, databasePrivateDnsName -> builder.arg("-Xmx500m") builder.prop("com.sun.management.jmxremote") builder.prop("com.sun.management.jmxremote.port", 8091) builder.prop("com.sun.management.jmxremote.authenticate", false) builder.prop("com.sun.management.jmxremote.ssl", false) builder.prop("ptrack.application.environment", "ec2") builder.prop("log4j.configuration", "log4j-minimal.properties") builder.prop("jdbc.db.server", databasePrivateDnsName)}) SimpleCluster cluster = new SimpleCluster(ec2, clusterSpec) cluster.loadTest("…/projecttrack/functionalTests/jmeter/SimpleTest.jmx", [1, 2]) cluster.stop() } }
Let’s look at each of the pieces.
First, we need to configure the framework as follows:
AWSProperties awsProperties = new AWSProperties("/…/aws.properties") def ec2 = new EC2(awsProperties)
The aws.properties file contains various properties including the Amazon WS security credentials and the EC2 AMI (i.e. OS image) to launch. All servers use my EC2 appliance AMI that has Java, MySQL, Apache, Tomcat, Jmeter and some other useful tools pre-installed.
Next we need to configure the servers:
ClusterSpec clusterSpec = new ClusterSpec() .schema("ptrack", ["ptrack": "ptrack"], ["src/test/resources/testdml1.sql", "src/test/resources/testdml2.sql"]) .slaves(1) .tomcats(1) .webApp(explodedWar, "ptrack") .catalinaOptsBuilder({builder, databasePrivateDnsName -> builder.arg("-Xmx500m") builder.prop("com.sun.management.jmxremote") builder.prop("com.sun.management.jmxremote.port", 8091) builder.prop("com.sun.management.jmxremote.authenticate", false) builder.prop("com.sun.management.jmxremote.ssl", false) builder.prop("ptrack.application.environment", "ec2") builder.prop("log4j.configuration", "log4j-minimal.properties") builder.prop("jdbc.db.server", databasePrivateDnsName)}) SimpleCluster cluster = new SimpleCluster(ec2, clusterSpec) This code first creates a ClusterSpec, which defines the configuration of the machines and the applications:
It then creates a cluster with that specification.
We then start the cluster:
cluster.start() At this point EC2Deploy will:
1. Launch the EC2 instances running my appliance AMI.
2. Initialize the MySql master database
3. Create the MySql slave
4. Create the database schema and the users
5. Run any DML scripts (these are cached on S3 in a bucket called “tmp-<schemaName>-dml” for the reasons described next)
6. Upload the web applications to Amazon S3 (Simple Storage Service) where they are cached in order to avoid time consuming uploads (over slow DSL connections, for example). EC2Deploy only uploads new and changed files, which means that the bulky 3rd party libraries are only uploaded once. Each web application is stored in an S3 bucket called <context>-tmp-war. If this bucket does not exist you will see some warning messages and the bucket will be created.
7. Deploy the web applications on each of the Tomcat servers
8. Configure Apache to load balance across the Tomcat servers
Once the cluster is started we can run a JMeter load test:
cluster.loadTest("…/projecttrack/functionalTests/jmeter/SimpleTest.jmx", [1, 2]) The first argument specifies the test to run and the second argument is a list of JMeter thread counts. In this example, EC2deploy first runs the load test with one thread and then two threads. For each test run, it generates a report describing CPU utilization for each machine, average response time and throughput.
Finally, we stop the EC2 instances:
cluster.stop()
As you can see, EC2Deploy makes it pretty easy to deploy and test your enterprise Java application. I’ve used it to clone a production environment and run load tests. NOTE 1/28/08: The source code EC2Deploy along with a very cool Maven plugin is now available !
Very interesting.
You mentioned 10cents per 20 cpu hour. I don't see such cheap rate on
Amazon EC2 site, it talks about 10cents per instance hour (which is not cpu
hour). Anyway, can you clarify it?
I've clarify the wording in my blog entry that describes the pricing.
EC2Deploy looks promising, is it meant just for easy development and
testing support, because this would be really cool also for production
deployment. But I still wonder about real production deployment in EC2: The
whole application is running on EC2, right? What about the size of your
databases? Isn't there some kind of restriction on the amount of disk
memory usable by an EC2 image? I mean, if your application does some
serious data juggling, ala "I want my own Ebay", where is all that data
going to? Is there some "well-known" pattern for using EC2 for this kind of
data-intense applications?
Is the Java web app environment AMI is already available in EC2 or do I
have to creaete one.
Hey Chris, I happen to be after a similar idea but bottom up. I am
currently looking for an rPath equivalent but for Java that is a *small* VM
(for VMWare, for EC2, for Xen whatever) with a JVM in there already
available. Period. I have tried Ubuntu 7.1 jeOS (available from VMWare
forum, less than 200M) but that one is a pain to convert to EC2. I have
tried rPath as well (500M) but the rBuilder Online is not really nice to
work with and the rPath Linux is somewhat not something I want to
familiiarize with. From what I read you have started from CentOS 5 AMI. Few
questions: how big are they, how much useless stuff in there if I *just*
run Java JSE ?, etc.
I think this would be terrific to provide a VM with just JSE inside, in
multiple hypervisor formats but with some common shared how-to for java
folks (and why not later on an http appliance admin ala rPath rAPA). Drop
me a note if you are after that.
Alex, try CohesiveFT's Elastic Server On-Demand (es.cohesiveft.com) which
allows on the fly provisioning of virtual machines for a number of
different virtualization platforms (vmware, parallels, xen, even
auto-deploy to Amazon's EC2).
Nice to see hear about this project. Do you able to have the AMI's for public so we can test ec2deploy?
Hi Chris... nice work! Are the AMI's now publicly available?
Great article Chris. Thank you. I'm also right now using your Grails EC2
Plugin. I'm new to Amazon EC2 services. I have used a public AMI and got a
lot of issues my grails application itself not running in Amazon EC2. Can I
use the AMI that you have created? Thanks, Lalapet
Send me your numeric amazon account id
(http://www.chrisrichardson.net/contactus.html) and I will give you access
to the AMIs - they are all set up to work with the Maven and Grails
plugins.
One day soon I plan to make the AMIs public.