TomcatExpert

Myth or truth: One should always use Apache httpd in front of Apache Tomcat to improve performance?

posted by mthomas on April 14, 2010 11:14 PM

The short answer is that this is a myth. The longer answer is that back in the days of Tomcat 3 there was some truth to this depending on circumstances. However, for the versions of Tomcat in use today (5.5.x and 6.0.x) then there is no need to use httpd for purely performance reasons. Tomcat now supports the native/APR connector which uses the same native library (the Apache Portable Runtime—APR) as httpd for the low-level I/O and therefore can achieve similar performance to httpd. When serving static content there is ever so slightly more overhead when using Tomcat compared to httpd but the differences are so small they are unlikely to be noticeable in production systems.

If you research the httpd vs Tomcat performance issue, you will find a variety of load and performance benchmarks that show a range of results. An often quoted result shows that Tomcat's pure Java connector is consistently faster than httpd.

This particular result is the opposite of what is expected. httpd should be significantly faster than Tomcat's pure Java connector. This result is probably caused by the size of the file used. Tomcat caches small static files in memory by default and this will provide a significant performance improvement. httpd does not cache files in memory by default. This demonstrates quite nicely how the definition of the benchmark can have a significant impact on the results.

The performance testing performed by Christopher Schultz, a regular on the Tomcat users mailing list, used a wider range of file sizes and provides – in my view – better results. The results of his tests are shown in the graph below.

Click to see larger image

These results are much more in line with what is expected, although there are a few interesting points to note:

  • Apache httpd and Coyote APR/native show similar performance levels.
  • Coyote NIO isn't too far behind httpd and Coyote APR/native.
  • There appears to be a limit on the usefulness of sendfile. This may be a hardware limitation but is worthy of further attention. I've added this to my todo list.
  • For small file sizes (less than ~10KiB) the static file caching in Tomcat provides a significant performance boost.

The detailed results for any performance test will vary with a number of factors such as the hardware used, the number of concurrent requests, the use of keep-alive and the use of caching. These factors can change the results of a particular test but the broad performance results will remain the same:

  • httpd and Coyote APR/native typically have similar performance.
  • Coyote NIO is typically just behind Coyote APR/native (further behind for SSL).
  • Coyote BIO will typically offer the lowest performance.

The settings to achieve the best performance will vary from application to application. The best settings for an application will depend significantly on the size of the resources, the ratio of static to dynamic content, the number of concurrent users, the usage patterns of those users and so on. Generally, performance can be improved by increasing the cacheMaxSize for the context, increasing the number of connector threads (using maxThreads [4]) available to process requests and enabling keep-alive (using maxKeepAliveRequests) but all of these come at the cost of increased resource usage. There is a trade-off to make here between performance and resource usage that will be different for each application.

It should also be noted that there is no magic "make it run faster" option in Tomcat. If your application takes 15s to generate a request, there is nothing that Tomcat can do to improve that. You'll need to profile your application to understand why requests are taking that long and then tune your application code appropriately.

While raw performance for static content may not be a good reason to use httpd, there are a number of good reasons why you might want to use httpd with Tomcat. The most frequent reason is to provide load-balancing to two or more Tomcat instances. httpd isn't the only option to so this - hardware load balancers or other reverse proxies can be used - but it is a popular choice amongst system administrators as many of them are already familiar with httpd. I'll write more on using httpd as a load-balancer in a future article.

httpd is also used with Tomcat when there is a requirement to support technologies other than Java. While Tomcat can support PHP or Perl, the support for these is better in httpd. Therefore, for sites that need a mix of technologies httpd can be used as the front-end web server, directing requests to mod_php, mod_fastcgi, mod_proxy_http (for Tomcat) or any other module as appropriate.

httpd's support for integrated Windows authentication is also a reason for using httpd in front of Tomcat. There are Tomcat based solutions for integrated windows authentication and, as these gain acceptance through wider use, this particular reason for using httpd may become less important. However, at the moment, it remains one of the more frequently cited reasons for using httpd with Tomcat.

In summary, there are good reasons for using httpd with Tomcat but raw performance for static content isn't one of them. If you are using httpd solely to improve static content performance then I recommend taking a look at the Coyote APR/native connector for Apache Tomcat.

Mark Thomas is a Senior Software Engineer for the SpringSource Division of VMware, Inc. (NYSE: VMW). Mark has been using and developing Tomcat for over six years. He first got involved in the development of Tomcat when he needed better control over the SSL configuration than was available at the time. After fixing that first bug, he started working his way through the remaining Tomcat bugs and is still going. Along the way Mark has become a Tomcat committer and PMC member, volunteered to be the Tomcat 4 & 7 release manager, created the Tomcat security pages, become a member of the ASF and joined the Apache Security Committee. He also helps maintain the ASF's Bugzilla instances. Mark has a MEng in Electronic and Electrical Engineering from the University of Birmingham, United Kingdom.

Comments

Configuring Response Headers

We're currently using Apache Httpd to handle such things as expires by type and gzip configuration. I wonder if these things can be set up in tomcat, thereby eliminating the httpd layer for us.

I invite you to the page

I invite you to the page where see how much we have in common. save the marriage system Review

I invite you to the page

I invite you to the page where see how much we have in common. How To Get Your Ex Back

Cool you write, the

Cool you write, the information is very good and interesting, I'll give you a link to my site. Survive In Bed Review

For many people this is

For many people this is important, so check out my profile: family doctor

Cool you inscribe, the info

Cool you inscribe, the info is really salubrious further fascinating, I'll give you a connect to my scene. How To Give A Hand Job

I invite you to the page

I invite you to the page where see how much we have in common. How to Turn a Guy On

Excellent article. The

Excellent article. The information is just the thing I wanted to read today. It's hard to find relevant information on this topic. Thanks to your article though, I now have all the relevant information that I need. Search engine marketing

Great article once more from

Great article once more from your side. Man, you are really good at this writing stuff. I always enjoy reading your articles. You truly are a gem of a writer and I just hope you'll continue to give more articles like this. WHEN DO BABY START TEETHING

You've shown here once again

You've shown here once again why you possess the ability to become one of the best writers of all time. You seem to have the passion of becoming the best. Your skills are phenomenal as well. You might become the best if you keep giving stuff like this. funny instagram bios

From my long experience,

From my long experience, assembling an organization of in-house on the internet promoters, developers and promoters to do the job will never succeed as none of them has enough experience in promotion my website.

his is a mind blowing

his is a mind blowing article! I've not read an article as good as this in a very long time. I want to thank you for giving us this article today. I am extremely grateful to you for this. Keep up the good work! la viagra

There you can download for

There you can download for free, see the first of these data. The Bonding Code

This is such a great post

This is such a great post that you've submitted today. Without a doubt, this is the best post that I've read in a long time. Thanks a lot for sharing this with us, mate. I really appreciate this! latest jobs in nigeria

This is the best thing that

This is the best thing that I've read on the internet in a very long time. Everything here is of the highest quality and I definitely could not have asked for a better article than this one. Thanks a lot for writing this today. I appreciate this! Apartments in Pittsburg ks

The 'big' look for phrases

The 'big' look for phrases are not everything. It is better to be on the first web page for a few smaller look for phrases, than try to position for bigger look for phrases and not be on the first web page at all useful content .

This is such a beautifully

This is such a beautifully written article, mate. I had the best time of my life reading this sensational article. I just hope that you will continue to give me more great articles like this. Cheers! Queens Peak

This is an amazing article. I

This is an amazing article. I was really amazed after reading this. The information here was absolutely magnificent. The font used here was top notch as well. I must say extremely well done job here. watch hentai

Very good topic, similar

Very good topic, similar texts are I do not know if they are as good as your work out. seguridadcomercios

Your work has always

Your work has always impressed me. You certainly have the skills of a perfect writer and you write extremely well. I just hope that you will continue to keep writing amazing articles like this. audio hire melbourne

This is an excellent article.

This is an excellent article. The amount of good information you've got here is just fantastic. I can safely say that this is one of the best articles I've read in my entire life. Very happy to read this! Queens Peak MCC Land

This is a fantastic article.

This is a fantastic article. I enjoyed reading this article very much. I could not have asked for a much better article to read than this today. Thanks a lot for publishing this today. Keep up the good work! find out more

Mate, your work is class.

Mate, your work is class. Without a single doubt in my mind, I know that you are the best writer of this era. You've proved this time and time again. Keep going like this, you'll be the best of all time. Cheers! City Electrical Factors

This is just the best article

This is just the best article that I've read on the internet in a long while. I always knew that you had the skills to deliver brilliant articles like this and you've shown that today. Continue to do more work like this! bluewatercomics

Excellent post. Brilliant

Excellent post. Brilliant information provided here. The font used to display this information is top notch as well. I really enjoyed reading this post. Keep it up. Note 6 Edge

This article is just one of

This article is just one of the best articles that you've posted on your blog. The information, the font here is just absolutely incredible. I've never read a much more detailed article than this one in my whole life. upbed

This article is excellent. I

This article is excellent. I enjoyed reading this very much. I have to say this is the best article I've read recently. You really know how to write top notch articles, mate. I salute you for that! dog storage locker man

This is a magnificent

This is a magnificent article. The information here is just brilliant. I have not read information as brilliant as this one in a long time. Thank you very much for giving us this magnificent article. Keep it up! storage locker man dog

Brilliant work from you here.

Brilliant work from you here. This is staggering work from you. I did not anticipate this kind of wonderful work from you but you've completely blown my away with this and proved me wrong. I just hope you'll keep doing this in the future as well. dog storage locker man

Great article. This article

Great article. This article has the best information that I could find on this topic. You've really satisfied me today with this great article. I hope that you'll give more brilliant stuff like this. storage locker dog man

This is the best article that

This is the best article that I've read in a long time. The information here, the font used here, everything is just top notch here. A big thanks to the writer for submitting this article today. I appreciate it! Darren Craddock

Whether you are transitioning

Whether you are transitioning residency between Canada and the U.S. or you have already made the move, it is important to understand the benefits of a cross-border financial plan. Learn how Cardinal Point can help when holding investment assets or financial interests in the U.S. or Canada. cross border estate planning

I'm extremely impressed with

I'm extremely impressed with the work you've done here. This article has to be one of the greatest articles that I've read on the internet in my whole life. Your work is just phenomenal. Keep it up! fee based financial planner san jose

This is a very good article.

This is a very good article. The information is excellent. The font used is top notch as well. I really liked reading this article. Thanks a lot for posting this. Cheers, mate. Fibroid Books

This article is magnificent.

This article is magnificent. I really enjoyed reading this article. You've done a very good job here. I must say that this is better than most of the articles out there. Thanks for writing this. Keep up the brilliant work! Free Recharge

This article is wonderful. It

This article is wonderful. It has got everything that I look for in a spectacular article. This article is one of the best articles that I've read on the internet in a while. Thanks a lot for publishing this article. Cheers! exotic american bully

This article is fabulous. I

This article is fabulous. I have read lots of articles over the years but I've never read an article of this high quality. You've done a really impressive job here today and I hope that you'll keep it going on. xem truc tiep bong da

This is a good article. I

This is a good article. I really liked this article. The information here is excellent. I really enjoyed reading this information. I hope that you'll give more more informative articles like this. Green Electricity Saver

This is another beautiful

This is another beautiful article published by you here. You've really stepped up your game over the past few weeks. And I am loving it! Please, continue doing this more often. wordsmatter

This is a fantastic article

This is a fantastic article to read. The content here is top notch. And one could not have asked for a much detailed content on this topic than this article has. Extremely pleased with this. SJD Guy

I am pleased to read this

I am pleased to read this great article. This has to be one of the best articles that I've read in all my life. Thanks for writing this great article today. I hope you'll be giving us more great articles like this. xarelto remedy

This is a fantastic article.

This is a fantastic article. I am really impressed by this. The information you've given here is just wonderful to read. The font you've used here is absolutely top notch. Well done! GE Monogram refrigerator repair in Orange County

The content here is

The content here is absolutely amazing. I found all of the content here very interesting. I could not have asked for a much better content article than this one today. Thanks a lot for this. Portland movers

Beautiful article, mate. I

Beautiful article, mate. I really liked reading this informative article. I could not have asked for a much better article than this today. Thanks a lot for writing this. I hope you'll keep it up. jamaica blue

Your articles are always

Your articles are always great to read. I always get some amazing information while going through your articles. I just hope you can continue this up in the future as well. Cheers! Chip Daily

Great article from your side

Great article from your side once again. You really have all the tools in your bag. I always enjoy reading your articles. And I just hope that I'll get to read more articles from your side in the future. shiatsu foot massager with heat by brookstone

Your work is just beautiful

Your work is just beautiful to see and read. You always provide the most useful information in your posts and that is why you are my favorite writer. I hope you'll give more stuff like this in the future. belly workout

This is great work from you,

This is great work from you, mate. You have some special abilities to write wonderful articles everytime. You really are one of the best writers of this generation and you prove it day in day out. I love it! Smartphones

I had a great time reading

I had a great time reading this fantastic article. You've really notched up your work with this article. You are going very good right now and I just hope that you'll keep it that way. tai lich euro 2016

This is a beautifully written

This is a beautifully written post. The information here is just absolutely amazing. The font used is also top notch. I really enjoyed reading this post. I hope you will give more posts like this in the future. geniux brain

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.