Hosting Java Web Applications: Why Is It Still So Hard?
Hosting Java Web applications is far from trivial. Ask anyone who has tried it and you'll start to understand why Java Web applications are not popular outside the enterprise. On the other hand, another common type of Web application - PHP based - has no such hosting issues. While there is lots of information on this topic throughout the Internet, I thought about performing my own simple test and I focused on three representative hosting providers.
The benchmark
Our company has recently launched the Java translation of phpBB 2, branded as nBB2. It's open-source and you can get it from nbb2.sourceforge.net. So what I had at hand was the Java equivalent of a popular PHP forum engine. Same look, same behavior, only backed by a different programming language. If one wants to compare the hosting options for small-to-medium PHP and Java Web applications, the phpBB/nBB2 pair looked to me like a good test material.
My reasoning was to use a Java application that is the very close counterpart of something that runs on even the cheapest PHP hosting options. By "close counterpart" I mean they both carry out the same operations on system resources (e.g. writing files, using sockets, accessing databases).
Another concern I had was performance. I wanted to find out not only whether the Java application can run on a certain hosting plan, but also how fast. Again, the most reasonable benchmark was to compare performance with the original PHP application running in the same environment.
I started by setting up a testing scenario using Apache JMeter which performs the following workflow: main page → login page → main page (automatic redirect) → view forum → view topic → post reply → log out → main page (automatic redirect).
This scenario is executed by 10 concurrent threads (users), 30 times each. This produces 300 new topic posts at the end of the performance test. All JMeter project files are available on the CVS here.
Reference tests
Before using the hosting providers, I conducted reference testing on two of our machines (one Linux, one Windows). The results were consistent: phpBB 2 was 10-15% faster than nBB2.
I ran PHP 5.2.3 through the Apache 2.x PHP module, a pretty common setup. For nBB2, I used Apache Tomcat 5.5 (on J2SE 6) and I imposed a heap limit of 32 MB, close to what one can expect in a remote hosting environment. More performance tuning could produce better nBB2 results, but this was enough to prove that the performance of the two applications is comparable.
The JMeter aggregate reports are also on the CVS. In case you wonder why Java doesn't blow out PHP for speed (or vice-versa), do not forget that both applications share the same architecture.
Shared hosting
For Java Web applications, the basic hosting options I have encountered feature a setup in which several users share the same instance of Tomcat 5.x. Perhaps Caucho Resin would be a better choice, but that's another discussion.
After many attempts, I gave up on GoDaddy's cheap Linux-based Java hosting account (the Deluxe Plan with $6.99 per month). I can only say what many others do, that it isn't suitable for anything but the simplest servlets or JSP pages.
Their JVM is set up to be very restrictive. As a rule of thumb, any part of the Java API that requires security permissions will probably not work. Think of write access to your own account (or /tmp), reading of system properties, creation of URL stream handlers, FTP connections. Before dismissing the importance of write access, think about logging. You'll be forced to log to a database. Log4j JDBCAppender is your friend, but it can't replace a simple log file. But I digress.
Other basic hosting accounts forbid the use of third-party JARs, like the case of HostIgnition's StarterFire plan.
Deployment/redeployment is another issue, since you don't have direct access to the JVM and so you cannot restart it at your convenience. According to GoDaddy's documentation, they have scheduled restarts each night at 1 AM Arizona time. In practice, they seem to do restarts more often than that. Other providers have on demand restarts. Each user can request a certain number of restarts each day. The problem is that other users you are sharing the JVM with can temporarily take down your application.
Shared hosting using a private JVM was the next logical step in my quest. This took the monthly charge well over $10 (e.g. $14.95 for HostIgnition's LiteFire with the Level 2 JSP/Servlets option). At this level one needs to get used to 32 MB of heap, at best. Above that, prices increase steeply (e.g. $59.95 for 64 MB of heap at HostIgnition). Having your own JVM, you may restart it at your convenience and can see even the Tomcat logs directory through FTP.
But even using the private JVM doesn't mean that all will go well. For instance, on my test Hostignition LiteFire account, I occasionally encountered the java.lang.OutOfMemoryError: GC overhead limit exceeded error during performance testing. This is documented to occur when the -XX:-UseGCOverheadLimit JVM option is enabled, more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered. Now this could happen if a certain part of the heap resided in swap and could not be restored to RAM in a time-effective manner.
On a positive note, the performance of nBB2 slightly exceeded that of phpBB on my HostIgnition account - configuration options do help.
After all this, I see the shared hosting with private JVM as the cheapest viable Java hosting alternative. While the basic hosting services just won't do, this one is reasonable but starts to be a little pricey.
Virtual Private Servers (VPS)
After finding a reasonable Java Web hosting solution, I thought about going upwards in the price range. The next step is represented by the Virtual Private Servers. You get your own machine (Linux or Windows) and have full root/admin access through SSH/Remote Desktop. The catch is that all this is virtualized and you are sharing a physical machine with others. Depending on how many users are allocated to the same physical machine and on what they are doing at a given time, performance varies.
The downside is that, besides the JVM, you are in charge of the whole operating system. Setting up and maintaining the servers for DNS, email, database, Web etc. is no small task.
My Linux-based GoDaddy VPS (Economy Plan, $30+) had enough RAM (256 MB RAM + 1 GB of swap), but experienced occasional performance drops. This was really bad. I thought I'd try a different VPS provider.
On a LunarPages VPS also running on Linux, things were much better and consistent on the performance side. The problem was that I had only 512 MB of memory available, including swap space. I'd say that on a real machine this would be the equivalent of 128 MB RAM and 384 MB of swap. This memory was eaten up pretty fast by the running services and I had difficulties getting a JVM to fully use its 32 MB heap space (in client mode, since the server mode requires additional non-heap memory). This ate up all the memory and /proc/meminfo was consistently reporting low to critical memory resources. Under these circumstances, even simple Cron jobs were failing due to out of memory errors. Naturally, the JVM also required daily restarts, otherwise I'd get OutOfMemory errors there as well.
Had I skipped the Plesk administrative interface and disabled some non-essential services, I might have been able to fully use the 32 MB of heap space and have some memory to spare. But it seemed pointless to pay twice the price of a private JVM on a shared host to get the same level of performance at best.
Performance-wise, when the Java application DID work, the results were consistent with what I had obtained on our local machines.
Dedicated Hosting
It surely works great, but it is in a completely different price range. I find a $100+ monthly charge to be rarely justified for low to medium traffic sites running small sized Web applications. The JVM is snappy, while experiencing the same comparative performance as on my local tests. Memory is no issue since all dedicated plans come with at least 512 MB of RAM and a swap space for which you have exclusive use. It's a physical machine for your use only.
The conclusion
With all this effort, I managed to find out nothing new :-) Java runs well in an enterprise environment (good up-scaling) and lags outside of it (bad down-scaling). The memory overhead of the JVM translates into memory problems for the applications in a budget-friendly hosting environment, making the comparable performance (when/while things do run) a small consolation.
But PHP works well outside the enterprise. Its simple development and deployment life-cycles are ideal for shared hosting environments, just as if the language was been built with this in mind – well, actually, it was.
While Java comes out a little bruised from this comparison, future evolutions might change the balance of power. If the MVM (multi-tasking virtual machine) from JSR 121 that promises to run multiple isolated virtual machines inside the same JVM process will ever be released, this could make it easy and cost-effective for hosting providers to give full access to a JVM per account even in their basic hosting plans. Another possibility is for the embedded J2SE platform to be used by hosting providers, if it catches on.
- Login or register to post comments
- 9182 reads
- Flag as offensive
- Email this Story
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Eric MacAdie replied on Fri, 2008/04/04 - 8:54pm
Peter Blakeley replied on Fri, 2008/04/04 - 9:35pm
in response to: Budoray
I would like to second this comment we have been using eapps.com for 4 years and the support is great these guys know J2EE. We now have several clients running their web apps their as well as our own apps, also host 20 odd web sites as domains all accessing our webapps on tomcat.
pb...
Robert Enyedi replied on Sat, 2008/04/05 - 2:53am
in response to: mw51287
Did you also look at other phpBB ports to java? There a quite a few of them and nBB2 is the result of an automated migration. I would expect it to have quite poor performance compared to a 'real' java implementation.
No, I did not look at the Java clones of phpBB. What I was interested in were the issues with hosting the closest equivalent of phpBB 2, meaning that both do the same things in the same order, access the same resources etc. Think of it as a small comparative research between PHP and Java hosting.
The performance of nBB2 in absolute numbers wasn't the problematic issue. I just wanted to check whether the comparative performance (e.g. how many percent slower/faster is nBB2 compared to phpBB) is the same on remote hosting as on local machines. What I found worrying instead was the state of the remote hosting setups, security permissions and fees for such a small application as a forum engine.
Behrang Saeedzadeh replied on Sat, 2008/04/05 - 6:58am
gent replied on Sun, 2008/04/06 - 1:03am
I'm using free java host from http://www.jdy.net/ for testing my jsp application .
LunarPages is using resin as java container.
Many webmasters discard java hosting and switch to php hosting because most of godd quality scripts written by PHP. javalobby is a good example. (running on drupal)
Steve Mayzak replied on Sun, 2008/04/06 - 3:56am
Robert Enyedi replied on Sun, 2008/04/06 - 5:43am
in response to: gent
Many webmasters discard java hosting and switch to php hosting because most of godd quality scripts written by PHP. javalobby is a good example. (running on drupal)
While I'm skeptic about the quality of most publicly available PHP scripts, fact is that JavaLobby and the whole DZone network do run on Drupal (which incidentally has an above average code quality). This is something to think about indeed.
David Lee replied on Sun, 2008/04/06 - 12:14pm
in response to: sky_HALud
It is something to think about and I have and it's only substantiates the hosting problem noted in the article. There are fewer free java apps like drupal and joomla in part because of the hosting issue. If you wrote a drupal in java you'd surely need a dedicated server, because the app would mostly like be bloated with libraries that would easliy run through most of the heap space you get with most of these shared plans. PHP's success, in part ,can easily be attributed to its low cost of everything, tools and hosting. Java's lack of success on the hosting side is clear, and this definitely has had an effect on the the what's available for java.
I suspect the drupal decision was made in part because of cost. Javalobby appeared to be running on resin and some jive software, and probably some other stuff. But the forum software and resin weren't always free. I suspect JL was running on licensed $ software, not the free versions. I also suspect when considering to update the site, the cost of java development vs the cost of using something like drupal made the decision easy from a cost/time perspective.
If you're an aspiring web developer, and you want to build the next great webapp, even if all else was equal , you have to consider where the app can and is likely to to be deployed. To give yourself the best chance of success, you have to conclude that you have far more hosting options by choosing to not go with java.
I say all of that to simply agree, again, with the article's original point, hosting java web apps is harder and more expensive than it needs to be.
Will Hartung replied on Sun, 2008/04/06 - 1:19pm
PHP apps are popular because PHP hosting is cheap, and most PHP apps are more than adequate for the tasks that they perform for a majority of users. Technologists may care about the underlying implementation, but Users can care less. They look at bang/$ ratios, and PHP wins this game hands down.
PHP is cheap to host because most shared hosting plans serve idle applications with little traffic, and PHP only consumes resources (modulo disk space) on the system when there is traffic, rather than Java which consumes resources based on the number of hosted applications. That's why all of the "cheap" Java plans have no memory, and why all of the "cheap" plans are nigh worthless. PHP costs the host disk space for each virtual host, Java costs the host memory. I'm sure you've all compared prices between RAM sticks and hard drives recently...
And there is nothing to be done about it. It is simply the nature of the beast. Shared Java hosting is unreliable (as mentioned in the original article), unless you go VPS which is expensive for a system of reasonable size (much less finding one well configured, like the 512MB host with no swap -- practically unusable). PHP hosting is effectively free today. ($5/month hosts with gazillion GB of hard drive space).
Simply, it's a cost of doing business with Java and needs to be factored in to your calculations regarding adoption of it or not.
Robert Enyedi replied on Mon, 2008/04/07 - 9:22am
in response to: whartung
Will, that's exactly the reason why PHP hosting is cheap and simple. This makes me conclude that if Java were to seriously compete with PHP on budget hosting it would be using a shared JVM hosting environment. This is the closest equivalent of the PHP model. You have one big JVM with all the available RAM allocated to it and, in theory, the web container manages the contexts as efficiently as possible. And the Java web application model does scale better than PHP.
Yet we now that shared hosting is a nightmare. I see two reasons for this happening:
-
Setting up such a web container is difficult and requires in-depth knowledge about Java and JVM internals, something the average hosting provider does not have. This could be solved by creating preconfigured standard packages of Tomcat/Resin/GlassFish etc. that are ready for such tasks.
- There are technology limits on what the JVM and web containers can do in isolating web contexts and providing proper context lifecycle management (deploy/redeploy/undeploy).
I suspect the most unconfortable reason (number 2) to be the issue here. As a sidenote, I've heard that GlassFish v3 will focus on this (see comment #2 from here), but I don't know specifics. Is there anyone more informed about this?Ray Kelm replied on Wed, 2008/04/09 - 12:17pm
If you'll pardon the shameless plug, I run dataslab.com, which provides a vps with 256M ram, 512M swap, and 20G disk for $20 (US) per month.
I wanted to note two things:
1. Those specs are excellent for running a tomcat instance.
2. The $20 price point is fairly common in the vps industry, as are those specs.
It doesn't take too much looking to find a VPS provider with similar specs for the same price. The $30 mentioned in the article is above the norm.
That said, I would have no problem with putting 10 virtual hosted php sites onto a single VPS, whereas putting a tomcat instance I'd recommend only one. Not that tomcat needs the full capacit, but that it's easier to manage those php virtual hosts.
I'm also a developer, and generally prefer java over php. I wish there were a better story for deploying java web apps. To that end, I've been working with OSGi, and I think there is something there worth using, but it's not yet at the point where it is easily deployed.
Jeroen Wenting replied on Fri, 2008/04/11 - 1:43am
I think a major part of the problem finding Java hosting on the low end of the market has nothing whatsoever to do with complexity of the work and everything with the type of people starting and running hosting companies at that end of the market.
Those people are typically Linux fanatics, with a decade of "hatred" of Microsoft and Java under their belts, so they won't even consider hosting Java even if they had skills exceeding those needed to create virtual hosts on Apache.
Some have bowed under pressure and started hosting Frontpage extensions because the home user and small business (their customers) often ask about those, since those users often use Frontpage to create their websites and Frontpage assumes Frontpage extensions to be available by default unless you tell it otherwise.
Java has no such penetration in the low end of the market of web designers (which is hardly surprising as Java was never aimed for web development at those people, where Microsoft very agressively targets ASP at them).
So it's a political/religious and economic issue more than a technology issue.
One could host a cluster of JBoss or Tomcat instances just as easily as a cluster of Apache instances. But these people don't want to, the very thought never even enters their mind, and they're still under the impression (from all the reports they saw on slashdot a decade ago and regurgitated there every few weeks) that "Java is slow", "Java is not secure", etc. etc.
Robert Enyedi replied on Fri, 2008/04/11 - 7:49am
in response to: rk29
That said, I would have no problem with putting 10 virtual hosted php sites onto a single VPS, whereas putting a tomcat instance I'd recommend only one. Not that tomcat needs the full capacit, but that it's easier to manage those php virtual hosts.
Ray, it's good to know that you are in the hosting business. Did you attempt to provide shared hosting for Java? We all would like to hear some more thoughts about this. Previous posts did mention Java's lack of control over threads as one of the reliability issues. Having the ability to impose limits on memory and processor usage, arbitrary interruption etc. would certainly be nice.
I'm also a developer, and generally prefer java over php. I wish there were a better story for deploying java web apps. To that end, I've been working with OSGi, and I think there is something there worth using, but it's not yet at the point where it is easily deployed.
What parts of OSGi do you think that could ease Java web deployments? Is that the fact that you have better application lifecycle management than those that come with the popular Java web containers?
Ray Kelm replied on Fri, 2008/04/11 - 9:28am
in response to: sky_HALud
Actually, my service is VPS hosting, which means I host instances of complete linux systems. What runs on top really doesn't matter to me. Memory is managed in a static fashion - each linux instance gets a fixed amount of RAM, and a fixed amount of disk. I can change the allocations, but I have it configured to NOT change them dynamically. This is intentional, since I want to guarantee that each instance has it's full allotment available. It makes the service more expensive, but it's serving a different purpose than simple virtual hosting.
Honestly, I really haven't looked much at shared Java hosting. I only know that from my limited experience with Tomcat, that it's not something that I would like to do.
I've not been too fond of the container model. It seems very heavy to me. Lately I've been embedding jetty into my applications, and OSGi allows me to dynamically install and remove services in a very clean fashion. I'm just exploring this area now, but I hope that it will lead to something that works well for me. Mainly I like the programming model that I can use with OSGi, where services are registered, and dynamically injected into other services using declarative services. There are still issues, but it's coming along.
Eric MacAdie replied on Mon, 2008/04/14 - 6:35pm
I think that for servlet hosting, VPS might be the way to go. Hosting companies that have good servlet hosting seem to wind up costing as much as VPS does, so why not go that route?
It seems like over the past few years, shared hosting has gone down in price significantly, especially considering that they now offer a lot more hard drive space and bandwidth than a few years ago. But servlet hosting prices have not really changed, and they do not seem to offer more memory or disk space than a few years ago.
Robert Enyedi replied on Tue, 2008/04/15 - 5:34am
in response to: emacadie
I think that for servlet hosting, VPS might be the way to go. Hosting companies that have good servlet hosting seem to wind up costing as much as VPS does, so why not go that route?
Eric, managing a VPS is a considerable task while a private JVM is managed by the hosting provider. Additionally, for shared hosting accounts you usually get a management console (CPanel/Plesk etc.) by default, something that you pay heavily for on a VPS (think of 10$+).
It seems like over the past few years, shared hosting has gone down in price significantly, especially considering that they now offer a lot more hard drive space and bandwidth than a few years ago. But servlet hosting prices have not really changed, and they do not seem to offer more memory or disk space than a few years ago.
From what I've seen, RAM prices didn't go down that much during the last couple of years, while disk space became way much cheaper and so did bandwith. And since Java web applications are much more memory hungry while idle (compared to the CGI execution model), this could explain it.
geolook replied on Tue, 2008/05/13 - 11:36pm
Ray Kelm replied on Wed, 2008/05/14 - 9:39am
in response to: geolook
Yeah, but it's $13 for a developer JVM with onyl 64M ram. It's $20 for a 128M JVM, which puts it at the same level as a typical VPS. Hmm. Actually, a little less since the $20 price point usually includes 256M RAM. For that you pay $25 on that site, which make sense since they are doing the maintenance.
All in all it looks very comparable to VPS.
geolook replied on Wed, 2008/05/14 - 10:05am