Monday, March 14, 2011

Tomcat Tidbit

Recently I inherited some Tomcat administration duties. Despite my dislike for Java (not the coffee, the application platform) I've been fairly impressed by the stability and performance it has to offer.

The default file directory layout for Tomcat is pretty basic and takes little getting used to. As you could imagine, all the configuration files are stored neatly in the /install/path/conf directory. User permissions are defined by the 'tomcat-users.xml' file:

user name="tomcat" password="tomcat" roles="tomcat,manager"

It comes with a bolt-on manager package which is not bad and can be accessed by:

http://ip.add.of.srv:port/manager

There's also a decent session manager (looks pretty bad, but runs very quickly and has all the session information you need, arrange by webapp) located at:

http://ip.add.of.srv:port/manager/html/sessions?path=/webappname

By default, this particular version that I'm running only allocates 256MB of RAM for Tomcat. In order to change this, we need to update:

/install/path/bin/setenv.sh

#!/bin/sh
# Set these variables for use during Tomcat startup / shutdown

# setenv.sh created by dt2install scripts Tue Mar 8 11:54:24 2011
# Note: You may want to manually merge any setting saved in setenv.sh_3-8-2011_11-54

JAVA_HOME=/usr/java;export JAVA_HOME
CATALINA_OPTS="-Djava.awt.headless=true -server -Xms512m -Xmx512m -Dfile.encoding=utf-8";export CATALINA_OPTS

Friday, March 11, 2011

Shared Memory and Semaphore Limits in Red Hat ES

I ran into a few issues recently, where I ran out of semaphore arrays when implementing a new web application. The application is a single-tier setup with all 34 databases on the same server which can get pretty busy at times and needs to have the kernel tweaked a little bit to allow for a large amount of concurrent processes.

To check the shared memory and semaphore limits in RHEL:

ipcs -al

------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 32768
max total shared memory (kbytes) = 8388608
min seg size (bytes) = 1

------ Semaphore Limits --------
max number of arrays = 256 *** <- What I needed to update
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

------ Messages: Limits --------
max queues system wide = 32
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384

Apparently the maximum number of arrays was too low (default on RHEL was 128 I believe).

To change THIS specific value, we need to update the running kernel parameters like so:

echo "250 32000 32 256" > /proc/sys/kernel/sem

**Note this will NOT MAKE THE KERNEL CHANGES PERMANENT

Obviously the format is:

[per array] [system wide] [per semop] [max arrays]

To make the changes permanent, we need to update /etc/sysctl.conf with the following:

kernel.sem = 250 32000 32 256

Another good change would be to update the max queues at the same time:

kernel.msgmni = 128

We could run 'sysctl -p' to update the running kernel with the permanent settings.

Double check with 'sysctl -a'!