Blog Support FAQs Contact Login
NEED TO TALK?
1.877.426.6834
  • Business Needs
  • Solutions
  • Why Contegix
  • Company
  • Customers
  • Resources



Uncategorized  ::  Mod Proxy AJP Versus Mod JK – Round 1

Mod Proxy AJP Versus Mod JK – Round 1


02
Feb 2009
5
Comments



Prior to the existence of Mod Proxy AJP being built into Apache HTTP we used Mod JK for any Tomcat based instance we hosted here. All of our Resin containers would use Mod Caucho, and all the Tomcat containers used Mod JK, and all was well in the world. We never had any significant complaints with Mod JK (Caucho’s another story for another day), other than it being a bit of a pain to setup, and it needing to be built from source. This created a situation where maintaining Mod JK was problematic, because it wouldn’t automatically be updated in our routine RHEL updates forcing us to manually rebuild for critical security updates. Then you added in the fact that the configuration files totalled in at three, with a mod_jk.conf, a worker.properties file, and the actually JkMount itself in the virtual host configuration, and you had yourself a maintenance headache. Not too mention the slightest of typos and a simple Apache reload turns into Apache going belly up like a poisoned whale.



Needless to say I suppose, when Proxy AJP came into our lives we as engineers were smitten. We were all quite familiar with ProxyPass, and simply swapping “http://” with “ajp://” to proxy to Tomcat containers seemed like the best solution we had ever seen. We were practically partying over the idea that we could finally ditch JK like a bad habit, and ride off into the sunset with our new ProxyPassing beast of a friend. The only downside is it required Apache 2.2, so our RHEL 5 boxes were all set, but the RHEL 4 boxes left us in the hands of old faithful, Mod JK. The ultimate question continued to linger though: Which would hold it’s own under high stress more effectively? In terms of average browsing, I don’t think you’d ever notice a difference, even after the tests I’ve done. The difference, to the human eye at least, is negligible. Nevertheless, I constructed a few test to put both through their paces.



Test Environment:

  • Apache 2.2
  • Tomcat 5.5.20
  • Java 1.6 64 bit
  • PostgreSQL 8.3.5 (tweaked for performance)
  • Confluence 2.10.1



Test Tools:

  • Pylot
  • BrowserMob



To get the ball rolling I started with Pylot. This was a quick and free way to start some preliminary testing. My initial tests fired up a constant flow of 200 (virtual) users at the instance for 10 minutes to see what would happen. To my initial surprise, Proxy AJP was a pretty clear winner to start things off. It was able to serve 1-2 more requests per second, while serving an average response time of roughly 1 second better than JK. Surely that couldn’t be right, it couldn’t possibly be that easy right? Right, not that easy. With some adjustments to Mod JK, like giving it a connection pool, I was able to get the results from my tests with Pylot to average out to be roughly the same. Under constant pounding from 200 agents, both were able to average an average response time of approximately 8.3 seconds, while serving roughly 23 requests per second. I was pretty pleased with my test environment at this point, and ready to kick it up a notch.



We got in touch with Patrick from BrowserMob, which is a site that offers real load testing with real browsers. I was hoping that with his service, I’d be able to find distinguishing differences between the two AJP connectors for Apache. After crafting myself a script using Selenium, and testing it ad nausem locally, I was prepared for my first test against Proxy AJP. I ran a 15 minutes ramp up to 100 users, and then put a constant load of 100 users across 45 minutes on the new kid in town. Surprisingly, the throughput looked pretty incredible:



 



If you click the image you can get a better view of the results, and see that we topped out around 140MB per minute being served. You’ll also see that the ebb and flow of data being pushed out was incredibly spiky. There are numerous jumps up and down the graph as more and less intense pages are hit throughout the tests. At first this seemed a bit scary, because I somewhat expected a smoother line across the board. I left all configurations the same though, and proceeded to test Mod JK, where I received the following throughput graph:





In a side by side comparison (or for better results lay the images over the top), Mod JK suffers from similar, but less severe spikes. It never quite reaches the highs that Proxy was able to reach, and never dips to the lows the Proxy had succumbed to. However, there’s something else at play here that caused this to happen. Mod JK caused Apache to reach MaxClients, and hold fairly steady there. There were only 100 users, and there were 256 MaxClients available in Apache, so numerically speaking, Mod JK should have been able to handle this without cracking under the pressure.



However, since it was at max connections, it didn’t have the downward spikes that Proxy did, because it was still trying to serve past requests. At the end of the day, we saw roughly 630 timeouts from JK in the tests, with the tests timing out at 30 seconds. Yes, I could have cranked up the timeouts to allow every step to completely finish, but this is real world testing. When was the last time you allowed a page more than 30 seconds to load? Proxy AJP on the other hand only sufferred from 450 such timeouts, showing me that it was able to pump out requests, and break off connections faster than Mod JK. The way I currently see it, JK failed to serve 200 people. That’s 200 people that think my site’s down, or heaven forbid, a Google bot that is prepping to denote me as a downed site. That’s 200 requests I’m not able to serve advertisements on, and thus not able to make money off of. Might not seem like much, but it is a big deal to some degree.



Now it would be interesting to crank up the MaxClients, and see what happens in that scenario. However, I needed to keep parity between the tests, so they were both performed within the exact same scenarios. We can always do more tweaking, and make more adjustments though. However, at the end of the day, Proxy has a lot going for it. It’s a built in module in 2.2, configuration is insanely easy, balancing is a cinch, it works with the balancer manager of mod_proxy_balancer, it receives automatic security fixes via RHEL updates, and so far, it out performs JK. We plan on doing more tests with altered configuration in the future, so look forward to future rounds. Perhaps JK can make up some ground in Round 2? Perhaps you’ll also get some insight on methods to tweak your Confluence installation to squeeze a bit more performance out of it as well. Many updates to come…




 mark.rogers      Posted in: Uncategorized     Tags: browsermob | load testing | mod_jk | mod_proxy_ajp



Responses



Reply
Peter Booth | March 6, 2009 at 9:07 pm

Mark,

Its possible that today mod_proxy performs better than mod_jk. It could also be mis-configuration issue – mod_jk documentation is fragmented and unclear.

mod_jk and mod_proxy really are quite different animals

mod_proxy is straightforward easy to understand and well documented.
mod_jk is substantially harder to grok because the documentation is quite fragmented.
mod_jk has substantial advantages over mod_proxy for complex installations or for applications that with high reliability requirements PROVIDED you are willing to learn the sparsely documented configuration syntax. If you don’t tune the dozen or more settings to match your application then its unlikely that a vanilla configuration will work in all situations. I suspect that less than 10% of installs are actually making effective use of mod_jk.

The big advantage of mod_jk is with reliability.

FOR MANY/MOST PEOPLE mod_proxy is the better choice

13 Scenarios where mod_jk is stronger than mod_proxy:

1. imagine that you have a pool of 4 TomCat instances that you are load balancing over. Now if one of these JVMs hangs with, say, an application deadlock thenm you really don’t want it to receive requests. With mod_jk the worker corresponding to the hung tomcat will be disabled as soon as a timeout triggers and no requests will be forwarded until it is healthy again.

2. if a TomCat dies and is restarted automatically by, say, monit then mod_jk will detect that the persistent connection is dead and will recycle connections.

3. If one of your 4 Tomcat is being beaten on by a batch process and as a result has 80% CPU consumed. WIth mod_proxy this instance will be assigned 1/4 of requests and these requests may back up and give user sa bad experience while three other Tomcats have free resources. mod_jk load balance can consider busyness when balancing

4. If you have HA requirements that trump response time then mod_jk can ping the TomCat and be sure it is healthy before forwarding each request

5. If you have a firewall between your Apache and your Tomcat that is configured to terminate “dead” connections mod_jk can make use of TCP keepalive

6. If your Tomcat receives a request and hangs, what do you want the user to see? mod_jk allows you to define a timeout and return an error to the user quickly rather than make the user wait 90 seconds or more.

7. If mod_jk doesn’t get a response on a socket it might be the Tomcat thread bound to the connector socket. You can configure mod_jk to grab another connection and retry the request

8. If a JSP is being recompiled or a class being deployed live then its possible for tomcat to return a 404 when issued a valid response at the “wrong” time. mod_jk can avoid marking the tomcat as bad.

9. If the application is one that has occasional administrative queries that are very slow then mod_jk can be told to ignore a small number of slow requests without marking the tomcat bad

10. An admin console can used to mark a worker as disabled or stopped so that no requests or no new sessions are directed to that instance. Useful for rolling restarts to mitigate memory leaks, similarly if you know that your app has a memory leak that will cause it to fail after 3 days, and if the app takes ten minutes to startup then mod_jk can be configured to give a new Tomcat N minutes before trying to forward real request.

11. If you have an uber-cluster of 40 Tomcats then you can partition them so that session replacement isn’t a 40 way replication

12. hot standby tomcats can be preinstalled and will be preferentially chosen by mod_jk when a tomcat fails

13. If you have a commercial product than can only run on one tomcat host then you might want all requests of teh form /expensivegraph/plot to be directed to Tomcat 1 an dall other requests to be balanced across the pool. mod_jk supports this.


Reply
Peter Booth | March 6, 2009 at 9:10 pm

Sorry for the length of this! Perhaps if you posted your Apache and Tomcat config files it would be easier to compare them?

I suspect that a non-obvious architecture that will offer better throughput than the usual is to use nginx for static content and straight Tomcat for the dynamic. Obviously this has drawbacks too.


Reply
Peter Daugavietis | June 2, 2009 at 7:50 am

To the first point — I think most of these are handled by various config options on either the ProxyPass line, or as part of the balancer config (keepalive, timeouts, hotstandbys, etc.) in Apache. But again — YMMV.


Reply
Apache, Tomcat and mod_jk for load balancing | November 28, 2010 at 10:25 pm

[...] article on mod_jk/proxy-ajp: http://thoughts.contegix.com/2009/02/02/mod-proxy-ajp-versus-mod-jk-round-1/ September 28, 2010 8:48 am pHk I’ve figured out an additional way of doing this [...]


Reply
Magnolia Oconnor | May 10, 2011 at 7:08 pm

Awesome blog, thanks for the advice. I will be subscribing to this today, keep up the good work.


Leave a Reply

Your email address will not be published. Required fields are marked *





  Cancel Reply

  • Categories

    • Culture
    • Employees
    • Events
    • Knowledge
    • News
    • Staff Development
    • Tech
    • Technology
    • Uncategorized
  • Archives

  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • July 2011
  •    More »

    Popular Posts

    Contegix Announces Our New Controller

    Contegix is happy to announce the newest addition to our…

    January 19, 2012

    Best & Brightest Wanted Here!

    Here at Contegix we are once again looking to add…

    January 16, 2012

    Welcome to the Team!

    We are pleased to announce the addition of Matt Steiner…

    December 20, 2011

    Hyper Wars: IT Industry Disrupted by Multihypervisor Approach

    For the past month, InformationWeek has featured several pieces covering…

    December 14, 2011

  • NEED SOME ASSISTANCE?
    We’re here to help you, 24/7/365. Give us a call at 877.4.CONTEGIX or drop us a line.
    1.877.426.6834
    sales@contegix.com




  • Contegix Headquarters
    900 Walnut Street, Suite 110
    Saint Louis, MO 63102

    Phone: 314.622.6200
    Toll-Free: 877.4.CONTEGIX
    or 877.426.6834
    Fax: 314.621.4422

  • Locations

    Contegix Data Center – STL1
    900 Walnut Street
    Saint Louis, MO 63102

    Contegix Data Center – STL2
    1111 Olive Street

    Saint Louis, MO 63101

    Contegix Data Center – LDN1
    11 Hanbury Street
    London
    E1 6QR
    England

    ©2011 Contegix LLC, All Rights Reserved.

  • Recent Tweets

    • RT @dzhu: Really impressed by @contegix support's response time and expertise today.
    • @dzhu thanks! Let us know if you need anything!
    • Happy New Year!
    • RT @appfusions: Smooth website upgrades & data imports in process w/ @Contegix today - Good stuff! #atlassian #Skilled #ManagedHosting