views:

1262

answers:

6

I have been writing a pure java web server specifically customized for a website I'm making. I've grown tired of reinventing the wheel though, and am now investigating moving over to java servlets. Basically I just want to run server side java code while leveraging the servlet technology to avoid writing http protocol specific code.

It would also be nice if its easy to retain some of the fine grain control I had when writing the server from scratch(such as specifying what URLs do what, and being able to specify where media is read and written on disk).

It seems like Tomcat is the most popular container, but it seems to support much more than I need, is there a better solution out there for non-enterprisey uses?

+3  A: 
  1. Tomcat
  2. Jetty
Itay
+13  A: 

Most definitely Jetty

non sequitor
Winstone is smaller and for the most-part just as capable.
Mondain
+2  A: 

Jetty.

It's quite small. It is quite advanced on the other hand. For example supports comet style web applications.

Thomas Jung
Hudson does not embed jetty but Winstone
Thorbjørn Ravn Andersen
Thanks. Corrected the post and voted yours up.
Thomas Jung
+6  A: 

Tomcat works great, even for "non enterprisey" solutions. I'm on my phone but will provide some excellent reasons when i get to a PC later. its very stable if you configure it correctly and works quite smoothly "out of the box".

UPDATE:

I've been running a Tomcat server with about 25 J2EE web applications of varying complexity for a couple years now. The server is a SPARC Dual Core 2.0GHz, 2GB RAM machine running Solaris. The previous server administrator (who is no longer with our company) did not do anything to re-configure the default tomcat instance. As such, we had some pretty spotty performance with some of our really I/O intensive applications due to memory constraints. Tomcat's default (I believe) allocates only 64MB of memory, which is just asking for OutOfMemory exceptions (and we experienced them for a while). Our department just trudged on though, and accepted restarting the server every day as a "procedure". Ugh.

When he left I was tasked with configuring our tomcat server and spent some time investigating how to properly configure it for our environment. I found that I only needed to add a couple of new arguments to the catalina.sh startup script in order to turn Tomcat into a very stable, very fast environment. The following line exists in catalina.sh (around line 112 on a default install of Tomcat 6.0.18):

CATALINA_OPTS=" $CATALINA_OPTS"

I changed the line to read as follows:

CATALINA_OPTS="-server $CATALINA_OPTS -Xms512m -Xmx2048m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote"

Explanation:

  • -server : This sets the container to act as a dedicated server.
  • -Xms512m: Sets the inital heap size to 512MB (1/4 the amount of memory on the server). You can play around this value, since the operation to change the heap size has a performance penalty, so set it to a value that will be in the range of your normal usage.
  • -Xmx2048: Sets the maximum heap size to 2GB (the amount of memory on the server). This should be maxed out if your machine is a dedicated server to get the most out of your environment, I've found.
  • -XX:MaxPermSize=512m: Maximum permanent generation. I set this equal to the initial heap size.
  • -Dcom.sun.management.jmxremote: I add this to enable this jar file by applications on the server. I use it so I can run the Lambda Probe monitoring application, which I really like for analytics on my server.

With this additional line, our server went from being up and down 1 to 2 times daily during a busy day to now being stably online without a restart for the past 20 days since I implemented this configuration.

KG
+4  A: 

I have embedded the Jetty web server in our web service server components and been very satisfied.

I was surprised by finding that Hudson uses Winstone - http://winstone.sourceforge.net/ - but it works very well. "Winstone is a small, fast and functional java servlet v2.4 container in a single 166kb jar file."

Note: You might quickly find that you want to be able to do redeployment of code without restarting the web container. I will strongly suggest that you find a web container which allows for that - you WILL need it someday.

Thorbjørn Ravn Andersen
+3  A: 

Winstone(mentioned by Thorbjørn) seems to be the fastest, not sure what the basic features are.

The next one would be Jetty followed closely by Tomcat.

mokito