I got a question recently, and I thought it would be nice to share the
response with the list:
What special tricks do you use to run Geoserver at MASSGIS? There are
some things like load balancing, fail over, and log analysis that come
up in production but rarely get discussed on the development lists.
Here's what I wrote back:
We use a couple of tricks, and a lot of things are simply not finished
yet (crises seem to take priority).
1) We use a simple, free TCP-level load balancer called "balance"
http://freshmeat.net/projects/balance/ It's really simple, and does
what we expect. I'm also interested in
http://freshmeat.net/projects/haproxy/ but haven't gotten around to any
testing with it yet.
The load balancer runs on a re-purposed desktop machine (p3-733 with
512MB ram). This machine is probably overpowered for what it's doing.
High TCP/IP load could cause this machine to get swamped, but a couple
of good network cards (with ASICs) would probably mitigate any cpu load
and leave the machine to idle in peace.
2) On each individual load-balanced geoserver box we run squid on port
80, http-accelerating geoserver on port 8080. This leads to all kinds
of proxy issues inside of geoserver, and I'm often the developer who
spends time fixing PROXY_URL based geoserver issues. But it works
pretty well these days, and hasn't given us trouble in a while.
3) Our geoserver data_dir is stored on a shared samba share that each
geoserver machine mounts and reads its config from. Actually, we cheat
and use the load-balancer as the samba server, but that's just an
implementation artifact...nothing structural there.
4) Failover: Occasionally a JVM will crash (usually due to geoserver's
use of JAI's native components to do rendering of rasters...I'm using a
rather bleeding-edge copy of the JAI libs from dev.java.net and the libs
are a bit flakey). This is bad, as squid isn't smart enough to close
its port 80 when port 8080 closes up and we get these bad "hangs" where
balance is still sending requests to squid which is then failing them.
To rectify this I wrote a little polling script which keeps an eye on
the running java process and on the response time of tomcat (is tomcat
taking more than 5 seconds to respond to a directory-index request?) and
if anything's outside of normal it shuts down squid.
Squid shutting down means port 80 closes and then balance won't send any
more requests to that node...effectively failing that node and having
the other two boxes pick up the load. When java comes back (either the
load works itself out or we manually restart java after the crash) then
the script re-starts squid when tomcat is behaving normally again.
5) Log analysis: We don't do as good a job of this as we should.
Geoserver 1.6.x doesn't have access-logging in it, but geoserver-trunk
(1.7.x) has it now. My hope is to get a geoserver_access_log logger
that's apache commonlog compatible and separate from the usual logging
stream. Once that's up we'll just aggregate (perl? bash with xargs?
manual?) the logs on the three machines and run awstats or something on
it.
6) We played a lot with the tomcat thread/request pooling mechanisms.
This resulted in many less resources being consumed, and failures
manifesting themselves more quickly. Its all stuff covered in the
tomcat server.xml documentation.
7) Current issues:
a. If you use a tiled map then roughly one of every three tile requests
goes to each server. But the SAME requests don't go to each server
(gah!) so the caching is sub-optimally balanced out. Supposedly you can
configure squid to ask peer caches if the content is cached elsewhere,
but I've not had much luck configuring this (probably because I'm
dense!) It might be much smarter to run one BIG squid cache in front of
the entire cluster.
b. log analysis is currently sub-optimally tracked. We really need to
get on fixing this.
c. failures could be better scripted to fix themselves. A java crash
could be easily fixed by having the script restart java if it's off.
I'm wary of "feedback loops" or self-DOSing due to a structural/hardware
failure causing this to spin out of control. But it would sure save us
the effort/annoyance of having to restart stuff at weird times.
--saul