title: Web Sockets + Tomcat/Glassfish + Cluster + Load Balancing - What are the options?
body: <p>I'm working on a Java SE 7 / Java EE 6 application that may use either Tomcat 7 or Glassfish 3.1 (probably GlassFish, but this has not been decided yet). The application will take advantage of the new WebSockets technology that has recently achieved widespread adoption across all major browsers.</p>
  
  <p>Through much research, forum reading and mailing list monitoring I have determined that (currently, AFAICT) neither mod_jk/isapi_redirect nor mod_proxy reliably (or at all) support WebSockets. Since these are the two tried and tested methods for load balancing/directing traffic in a Tomcat or GlassFish cluster, this obviously represents a problem.</p>
  
  <p>On the other hand, however, Tomcat and GlassFish both have built-in web servers that are widely touted to be just as efficient at serving static content as Apache or IIS, and therefore it is generally not recommended to place Apache or IIS in front of one of these servers UNLESS you need redundancy/load balancing.</p>
  
  <p>So, all of this leads me to these questions:</p>
  
  <ol>
  <li>Is Apache or IIS even needed anymore to load balance in a Tomcat/GlassFish cluster? Wouldn't it be just as efficient (or more so?) to simply place a standard load balancer, like what you would use in any other scenario, in front of a cluster of Tomcat or GlassFish servers and forego the intermediary web server altogether? Or is there still some technical reason that standard load balancers won't work with TC/GF? Assuming a standard load balancer could be used, one could simply find one that supports WebSockets (like Coyote) and use it.</li>
  <li>If a standard load balancer will simply not work with Tomcat/GlassFish, what other options are there? How can one effect performant and reliable WebSocket technology using Java EE?</li>
  </ol>
  
  <p><strong>Caveat</strong>: I prefer not to consider load-balancing technologies that are limited to dumb round-robin protocols (such as Round-Robin DNS). I do not consider these options reliable/redundant, as one could easily be sent to a server that was down or already handling a much larger number of connections than another server in the cluster. Obviously I know that something like Round-Robin DNS could easily be used with WebSockets without any compatibility concerns.</p>