Tomcat Doesn't Suck

image

I was just reading this review of a new book called How Tomcat Works and I think I'm going to grab a copy of it because the subject really interests me now. This was one of those things that I haven't mentioned, so I figured I'd write about it here.

Believe it or not, I've really warmed up to server side development with Tomcat 5. Now that I can find most of the knobs and buttons that I need, have run it at work and on my personal server for six months or so, and have found a really comfortable way of developing with different web app configurations that was never available to me with other platforms, I can honestly say that I prefer it over many of the other app servers I've used. I'm actually quite surprised at how nice it is to develop with, even on a modest dev computer, the server will restart within just a few seconds. In terms of production, with the proper settings it doesn't suck resources on the server, and has held up quite fine serving up static content as well without me bothering to put Apache in front of it.

Development is actually where I've become most happy with Tomcat. I wrote this in a comment on Raible's blog the other day, but I'm going to repeat and elaborate on it here. I never really understood the CATALINA_BASE environment variable until I worked at this job. Being a Linux shop, we share all our libraries on a central NSF mount which is available on any server in the office. This means by simply setting the CATALINA_BASE you can re-use the Tomcat installation files, yet have a completely unique server instance on a different box. It works incredibly well. Once I grokked this, my whole development world changed overnight. Now own my own computer, I have cleanly divided projects - personal and various professional projects, all with their own base directories and settings. No more messing with server.xml files every time I want to mess with a completely different server setup! It's great!

Here's how it works in case you don't know already (I'm not sure if I'm the last person to discover this functionality or what). First, go grab the latest version of Tomcat, unpack it into a directory and *don't touch it*. If you need to have some jar files accessible by the container itself - for example you're using DBCP and Tomcat needs to manage the MySQL connections - you need to either add those jars to your common/lib directory or to your CLASSPATH environment variable. But if you don't need that stuff, don't touch that directory. It makes upgrading a lot easier.

Now you create a catalina_base directory somewhere where you normally work (outside the Tomcat dir). In this directory, create conf, logs, tmp, webapps and work directories. Now set up the catalin_base directory as per normal: Copy the conf stuff out of the Tomcat conf dir into your catalina_base/conf dir and pop your war files into the webapps, modify the server.xml and web.xml files. Then before you start the server, set the CATALINA_BASE environment variable to the directory you just created (or some other one). Here's another tip, while developing you can type "catalina run" in the bin directory instead of using the start script and the process runs in that same window. This makes it *very* fast to just hammer the process with a quick Ctl-C and restart, instead of trying to mess with the app-runner tools or the shutdown scripts and having to tail catalina.out.

Like I said, I'm not sure if I'm the last Tomcat developer on Earth to know this stuff, but it definitely makes life so much nicer. I can isolate web apps now, have different versions of the same app and generally just organize my code and process a lot more. Between this and Eclipse having multiple workspaces, I'm like 100 times more organized.

That's on the development side, but I can say in production Tomcat is holding up quite well. I guess my memories of random crashes and memory leaks from 3.0 code tainted my opinions, but Tomcat 5 seems just as solid as any of the other app servers I've used. I've been banging the hell out of my dev box with JMeter and Microsoft's Load Testing tool and it holds up quite well. It's serving up pages right now on this server and I haven't had any problems with it here either. This all makes me very happy. Developers like that "secure" feeling they get when you feel that you're not basing your dev code on top of quicksand, am I right?

So now that I trust the code a bit more, I'm definitely going to have to get that How Tomcat Works book and really grok what's going on behind the scenes. I'd really like to know what's going on a lot more.

-Russ

< Previous         Next >