Recent Posts

RSS Feeds

Tomcat and Java versions memory benchmark

Many Java web applications are running on older versions of Java and application servers / servlet containers like Apache Tomcat or Jetty with default parameters. I benchmarked the memory consumption of different combinations with different memory options to find out if an update would improve the memory efficiency significantly. All benchmarks in this entry are done on a 32-Bit Linux distribution with Sun JDKs. I took the vsz and rss size of the Java process after startup and requesting some web pages with different heap size options and different VM engine implementations. The absolute data may be different at your side but the relations I assume will be the same. My results are tainted by garbage collection effects and are far from being scientific. They should only give you an idea which combination might give you the best results.

Minimal Tomcat 5.5 / Java 5

How big is the overhead for an otherwise empty running old Tomcat?

JVM 1.5.0 32bit Linux, TC 5.5.23, App: ROOT
-client -Xms64m -Xmx256m 36900
-client -Xms128m -Xmx256m 42208
-server -Xms64m -Xmx256m 63556
-server -Xms128m -Xmx256m 68060

The server VM engine uses 60-70% more than the client engien. Of course performance benchmark would show the advantage of the server engine. It depends on your needs.

Overhead for Tomcat manager application

How much memory can be saved if I  do without the Tomcat manager application?

JVM 1.5.0 32bit Linux, TC 5.5.53, App: ROOT+Manager
-client -Xms64m -Xmx256m 38116
-client -Xms128m -Xmx256m 42408

Once the Java virtual machine and Tomcat are running, the manager application doesn't need much additional memory. You may use this extra service compared to Jetty without needing too much additional memory.

Java 6 memory savings

Is it worth the effort to upgrade from Java 5 to Java 6?

JVM 1.6.0 32bit Linux, TC 5.5.23, App: ROOT+Manager
-client -Xms32m -Xmx192m 27984
-client -Xms64m -Xmx256m 30628

Yes! There are big savings with Java 6 (without any loss of functionality and I guess even with better performance). And as long a Tomcat has no real applications, just some JSP pages, you may also lower the minimum heap space to get some more savings.

Tomcat 6 memory savings

How much influence does the upgrade to Tomcat 6 have on memory?

I took the default installation of Apache Tomcat with an empty ROOT application, manager application plus documentation. I lowered min and max heap space further and tried the effect of using these applications.

JVM 1.6.0 32bit Linux, Tomcat 6.0, App: ROOT + Manager + Docs
-client -Xmx32m -Xmx192m 25016 (just started)
-client -Xmx32m -Xms128m 26116 (after some browsing)
-client -Xms32m -Xmx192m 26132 (after some browsing)
-client -Xms64m -Xmx256m 28400 (after some browsing)

Yes! Another saving by upgrading to Tomcat 6! And again without loss of functionality or performance and on top of the Java 6 savings.

Is Jetty 6 even better than Tomcat 6?

Jetty in my rememberance is a very small and efficient servlet container suitable as an embedded component and used for example in the Grails framework. Would it be better to switch from Tomcat to Jetty as a standalone (reduced-to-the-max) application server?

JVM 1.5.0 32bit Linux, Jetty-6.1.5, no WebApp
-client -Xms64m -Xmx256m 31288 (TC55:36900)
-client -Xms128m -Xmx256m 34348 (TC55:42208)
-server -Xms128m -Xmx256m 38324 (TC55:68060)

Jetty wins against Tomcat5.5 on Java 5 so my impression was right. If you are stuck with Java 5 a switch to Jetty would help you. See below for a comparison to Tomcat 6 with an application.

Comparison using a real Java web application

Until now the servlet containers were almost empty. Now I use a real web application, this blogs software named Apache Roller version 3.1 with a MySQL database attached trough a JDBC datasource defined in the container.

JVM 1.6.0 32bit Linux, Tomcat 6.0, App: ROOT + Manager + Apache Roller 3.1
-client -Xms32m -Xmx192m 55656
-client -Xms64m -Xmx256m 58424
-server -Xms32m -Xmx192m 96672
-server -Xms128m -Xmx256m 112236

JVM 1.6.0 32bit Linux, Jetty 6.1.5, App: ROOT + Apache Roller 3.1
-client -Xms32m -Xmx192m 66484
-client -Xms64m -Xmx256m 66760
-server -Xms32m -Xmx192m 93380
-server -Xmx128m -Xmx256m 108600

Now this is interesting: Tomcat 6 beats Jetty 6 in client JVM mode, but Jetty 6 is better in server mode. I don't want to start a flame war and I really like Jetty and all but from my results I prefer Tomcat with the client JVM.

Grails versus a Java web application?

At last I took a minimalistic Grails (1.0.2) application (Books and authors in m:n relation using scaffolding) and deployed it parallel to Apache Roller.

JVM 1.6.0 32bit Linux, Tomcat 6.0, Apps: ROOT + Manager + Apache Roller 3.1 + GrailsApp(Book)
-client -Xms32m -Xmx192m 89080
-server -Xms32m -Xmx192m 178604

Apache Roller 3.1 uses 30 mb and my Grails 1.0.2 book application uses 33 mb in client mode. In server mode they use 70 mb and 81 mb. They don't have the same functionality so I compare Apples with Peaches. But they have a similar enough and use memory in the same order to say: Grails application are normal Java web applications and the memory penalty can be accepted.

And how about Sun Glassfish v3?

Sun Glassfish v3 TP2 (jdk 1.5.0):
Core + Admin + Grails Plugin + Grails App + Apache Roller 3.1 Blog
-client -Xmx512m 791164 204824 (Grails+Blog)
-client -Xmx512m 795536 254332 (Grails+Blog+GlassfishAdmin)

Sun Glassfish v3 TP2 (jdk 1.6.0):
-client -Xmx512m 687248 232568 (Grails+Blog+GlassfishAdmin)

The overhead of Glassfish is to big for a small (virtual private) server. Again Java 6 gives big savings in memory. And the Glassfish administration application, as good as it is, uses a big chunk of memory compared to the manager application in Tomcat. This comes as no surprise since Jetty and Tomcat are usually embedded as a component in Glassfish or JBoss.

Summary and Recommendations

Tomcat 6 with Java 6 is the most effective combination in terms of memory efficiency. You may use Jetty 6 instead if you like since the difference is minimal. A real application server like Sun Glassfish is too big for small VPS servers.


  Share

Permalink    

Related Articles:

Senden Sie einen Kommentar:
Kommentare sind ausgeschaltet.