apache > cocoon

- Home

# StoreJanitor in Apache Cocoon

## Goal

This document describes the usage of the StoreJanitor under Apache Cocoon.

## Description

The implementation is quite simple! Every implementation of a Store can register in the StoreJanitor. It checks at a configurable interval if memory is running low. If low, it greps via Round Robin a victim (Store) and frees xx% of all elements in this Store. After that the StoreJanitor sleeps and waits for the next iteration.

## Configuration

    <store-janitor logger="root.store">
      <parameter name="freememory" value="1000000"/>
      <parameter name="heapsize" value="60000000"/>
      <parameter name="cleanupthreadinterval" value="10"/>
      <parameter name="threadpriority" value="5"/>
      <parameter name="percent_to_free" value="10"/>
    </store-janitor>

The right configuration is very important, because wrong settings can cause a high system load.

### Example configuration

- Tomcat settings in tomcat.sh or tomcat.bat:

    %_RUNJAVA% %TOMCAT_OPTS% -Dtomcat.home="%TOMCAT_HOME%" \
      -Xmx200000000 org.apache.tomcat.startup.Tomcat %2 %3 %4 %5 %6 %7 %8 %9

- StoreJanitor settings:

The freememory and heapsize parameters always depend on the Xmx parameter.

    <store-janitor logger="root.store">
      <parameter name="freememory" value="50000000"/>
      <parameter name="heapsize" value="150000000"/>
      <parameter name="cleanupthreadinterval" value="10"/>
      <parameter name="threadpriority" value="5"/>
      <parameter name="percent_to_free" value="10"/>
    </store-janitor>

It is recommended to have `heapsize` equal to -Xmx, especially on Sun's JVM which is unable to shrink its heap once it grows above the minimum. The `freememory` parameter should be greater than the amount of memory necessary for normal application operation.

The `cleanupthreadinterval` defines the interval (in seconds)of the background thread which checks memory. Also this parameter should configured wisely. A too short interval can also cause a high system load. The `threadpriority` defines the priority of the background thread (1 is the lowest level and 10 the highest).

The `percent_to_free` parameter describes what percentage of the elements of each registered Store shall be removed when low on memory.

Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).