Tuning tinyPM

Contents

Tuning tinyPM

tinyPM is a Java web application that runs in Tomcat by simply unpacking the WAR. However Tomcat is not solely responsible for tinyPM's performance. Underneath you will find some hints on how to get more out of your configuration.

JVM options

tinyPM required at least 256MB of memory to run properly. However the more users you want to let in the more memory will be useful. Also remember to run tinyPM using the -sever version of JVM. Put the following options in the $JAVA_OPTS environment variable:

JAVA_OPTS
 
-server -Xms256m -Xmx768m -XX:MaxPermSize=96m -XX:+UseParallelGC

Adapt the amount specified in -Xmx option to your server capacity.

Ubuntu

To do that on Ubuntu you will find the configuration in /etc/default/tomcat6
Edit this file. By default it contains the section "Default Java options" and the following settings:

JAVA_OPTS="-Djava.awt.headless=true -Xmx128M"

You will need to change it at least to:

JAVA_OPTS="-Djava.awt.headless=true -Xms256m -Xmx768m -XX:MaxPermSize=96m"

Tomcat Connector

There are a few parameters that you can setup for your Tomcat Connector to first make tinyPM work properly with UTF-8 characters and to save some bandwidth when serving some text content by Tomcat (read also the next chapter on how to serve most of that content by Apache HTTPD server instead).

server.xml
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
           useIPVHosts="true"
           URIEncoding="utf-8"
           enableLookups="false"
           compression="30000"
           compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/x-javascript" />

Running Tomcat behind Apache 2.x

mod_jk

The best way to let Tomcat do the Java stuff is to run it behind Apache HTTP server using mod_jk module and leave handling all the static content to the Apache. Here is some basic configuration that you can use with your vhost configuration to make static tinyPM content served by Apache:

Apache vhost configuration
<VirtualHost *:80 *:443>
        DocumentRoot "/var/www/localhost/webapps/tinypm"
        ServerName www.example.com

        # Contents GZIPing
        AddOutputFilterByType DEFLATE text/plain text/html text/css text/javascript application/x-javascript

        # Allow Apache serve static files
        <FilesMatch "\.(gif|jpe?g|png|css|js|ico)$">
                Order allow,deny
                Allow from all

                ExpiresActive On
                ExpiresDefault "now plus 1 week"
                Header unset ETag
                FileETag None
                Header unset Last-Modified
        </FilesMatch>

        # Static files in all Tomcat webapp context directories
        # are served by apache
        JkAutoAlias /var/www/localhost/webapps
        JkStripSession On

        # All requests go to Tomcat by default
        JkMount /* ajp13

        # Serve some static files through Apache
        JkUnMount /*/img/*      ajp13
        JkUnMount /*/js/*       ajp13
        JkUnMount /*/css/*      ajp13
        JkUnMount /*/*.ico      ajp13

        # Use the following if you are running tinyPM using it's own subdomain
        JkUnMount /img/*        ajp13
        JkUnMount /js/*         ajp13
        JkUnMount /css/*        ajp13
        JkUnMount /*.ico        ajp13
</VirtualHost>

To check if your vhost settings work you may point your browser to

http://www.example.com/tinypm/css/tinypm.css

and check the HTTP headers (for example using FireBug extension for Firefox). They should look similar to these:

Date:	                Tue, 18 May 2010 08:08:07 GMT
Server:	                Apache
Accept-Ranges:	        bytes
Cache-Control:	        max-age=604800
Expires:	        Tue, 25 May 2010 08:08:07 GMT
Vary:	                Accept-Encoding
Content-Encoding:	gzip
Content-Length:	        7263
Keep-Alive:	        timeout=15, max=100
Connection:	        Keep-Alive
Content-Type:	        text/css

The important ones are Expires and Content-Encoding which should be set to gzip

mod_proxy_ajp

It's also possible to use Apache HTTP server using mod_proxy along with its additional module mod_proxy_ajp. Here is some basic configuration that you can use with your vhost configuration to make static tinyPM content served by Apache:

<VirtualHost *:80 *:443>
        DocumentRoot "/var/www/localhost/webapps/tinypm"
        ServerName www.example.com

        # Contents GZIPing
        AddOutputFilterByType DEFLATE text/plain text/html text/css text/javascript application/x-javascript

        # Allow Apache serve static files
        <FilesMatch "\.(gif|jpe?g|png|css|js|ico)$">
                Order allow,deny
                Allow from all

                ExpiresActive On
                ExpiresDefault "now plus 1 week"
                Header unset ETag
                FileETag None
                Header unset Last-Modified
        </FilesMatch>

        <Proxy *>
                AddDefaultCharset Off
                Order deny,allow
                Allow from all
        </Proxy>
        
        ProxyPass /tinypm/img/ !
        ProxyPass /tinypm/js/  !
        ProxyPass /tinypm/css/ !
        ProxyPass /tinypm/favicon.ico !
        ProxyPass /tinypm ajp://localhost:8009/tinypm
        ProxyPassReverse /tinypm ajp://localhost:8009/tinypm
</VirtualHost>

Giving MySQL a breath

If you can spare around 200MB for MySQL on your box, then these are the settings you may use:

These settings are valid for MySQL 5.x
my.cnf
# The following options will be passed to all MySQL clients
[client]
port                            = 3306
socket                          = /var/run/mysqld/mysqld.sock

[mysql]
# Let tinyPM use national characters without problems
default-character-set           = utf8

[mysqld_safe]
err-log                         = /var/log/mysql/mysql.err

[mysqld]
# Let tinyPM use national characters without problems
character-set-server            = utf8
default-character-set           = utf8

user                            = mysql
port                            = 3306
bind-address                    = 127.0.0.1
log-bin
server-id                       = 1
socket                          = /var/run/mysqld/mysqld.sock
pid-file                        = /var/run/mysqld/mysqld.pid
log-error                       = /var/log/mysql/mysqld.err
basedir                         = /usr
datadir                         = /var/lib/mysql
tmpdir                          = /tmp/
skip-locking
key_buffer                      = 64M
table_cache                     = 128
sort_buffer_size                = 8M
net_buffer_length               = 8K
read_buffer_size                = 1M
read_rnd_buffer_size            = 2M
myisam_sort_buffer_size         = 8M
language                        = /usr/share/mysql/english

# Increase max allowed packet to accept bigger file attachments in tinyPM
max_allowed_packet              = 16M

# tinyPM uses innoDB tables in MySQL
innodb_buffer_pool_size         = 128M
innodb_additional_mem_pool_size = 8M
innodb_data_file_path           = ibdata1:10M:autoextend:max:1024M
innodb_log_file_size            = 16M
innodb_log_buffer_size          = 8M
set-variable                    = innodb_log_files_in_group=2
innodb_flush_log_at_trx_commit  = 1
innodb_lock_wait_timeout        = 50

[mysqldump]
# Use UTF-8 in your tinyPM backups
default-character-set           = utf8
quick

# Keep that in sync with [mysqld] section to be able to backup tinyPM's file 
# attachments properly
max_allowed_packet              = 16M
? If this documentation doesn't solve your problem or has left you with any questions, please don't hesitate to contact us at support@tinypm.com
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.