I have no special talent. I'm only passionately curious - Albert Einstein
August 05, 2010
My take on running Java apps in the Cloud
Posted by Dave Malone
in Grails,
Java,
Technology
I recently began exploring the latest technology buzzword, the Cloud. As a Java developer, I was most interested in learning how to run Java applications purely in the Cloud, or integrating Java applications with Cloud based services. After some brief searching on Google, I began evaluating the Google App Engine (GAE), and the Amazon S3 (Simple Storage Services) and EC2 (Elastic Cloud Computing) products. I wanted to learn what it takes to run a Grails application in the cloud, and how much it would cost me to do so.
Amazon's Cloud Services (EC2 and S3)
I began exploring Amazon's EC2 pricing, and just about had a heart attack. They claim to allow you to only "pay for what you use", but when I found their Simple Monthly Calculator, and selected the Common Customer Samples for Web Applications, the estimated monthly bill came out to be $10,200.94 (yes, MONTHLY)! I didn't think that could be accurate, and I was still interested in exploring my options with Amazon's EC2 services in case a small business wanted to use it (or even myself as an individual). Again, thinking I wouldn't pay for anything I didn't use, I entered my credit card information, set up a single simple EC2 server instance, and let it run overnight (without running any applications on it). After abour 8 hours, I had already accrued about $4 in cost. I canceled the service right away. That means that without even using their "pay as you go" services, you pay an average of $12 a day just to keep a simple virtual server instance up and running - averaging out to about $365 a month when not even using the server. That's a bit high, in my opinion.
Google App Engine (GAE)
Next, I wanted to explore Google's App Engine. I watched a quick video on how their pricing works, and it seemed to be the same concept - pay as you go. Getting an application up and running wasn't as user friendly as setting up an Amazon EC2 instance - you have to sign up for Google Apps Premier Edition, then use your account there to hook up into GAE, and then you can finally run an app on their system. Here's where things got interesting. You can deploy a standard WAR file on their app engine, but they require users to use JPA JDO for accessing databases (this is their implementation choice, but it sucks that they force you to use their choice and don't provide other options). So, standard Hibernate was out of the picture now. Sure, there's a JPA JDO plugin for Grails, so you can use JPA JDO over standard instead of Hibernate, but it's not a simple plug-n-play option. And, you lose the power of Hibernate's Criteria queries. Next, I discovered that Google has an approved Whitelist of classes you can use from the JDK. What?!! Java was designed to write once, run anywhere. Now Google wants to force their customers to comb their codebase to ensure we aren't using a blacklist JDK class? How many open source frameworks would I have to also comb to ensure that they are GAE compatible? One assumption I came up with is they don't want people writing their own custom Image scaling utility. I admit, this kind of utility is easy to implement incorrectly. But, it turns out Google wants to charge users to scale images using their Image scaling services. Ok Google, GAE is out of the picture.
Conclusion
The conclusion I've come up with is that to build a scalable, completely elastic cloud based Java application, with the most availability, it's going to cost you, but I'd recommend Amazons EC2 services. If you want a cheaper option, where you're forced into more restrictions, use Google's App Engine.
I have another recommendation, however. I believe it would be cheaper overall to go with a smaller Java hosting company, like Oxxus.net, that provides VPS Java hosting for a base price of $19.99 a month. Then, use Amazon's S3 services to serve your sites rich media and static content, like videos, images, css and javascript files. The S3 servers are distributed across the world, so they are set up to handle broad distribution of static content, and at a fairly low cost. This kind of integration can help developers build scalable applications integrating with the cloud on shoestring budgets.
Amazon's S3 pricing can be found here. Amazon provides a pretty good Java API, as well as a Grails plugin that can be used to make integration with S3 pretty straightforward. I'll write an article later with a detailed example in Grails to help you get up and running.