[Opensymphony-oscache] Setting the amount of memory?

Chris Rusanowski <[email protected]> Thu, 30 Jun 2005 10:23:21 CDT
Newsgroups gmane.comp.java.open-symphony.os-cache
Message-ID <32580289.1120145087182.JavaMail.os-j2ee@opensymphony01.contegix.com>
[b]Is there a better way to control the amount of memory OSCache uses?[/b]

I am using the OSCache filter in front of a servlet that produces binary map images.  I had it set for caching 5000 objects and had the disk persistence turned on with overflow only set to true.  (OSCache.properties is below...)  Oh, and I am currently testing this on the version of OSCache compiled 2.2 development CVS checkout of the HEAD branch.

My Tomcat configuration is set to start with a 512MB initial memory pool and 1024 maximum.  In my initial load testing, I was putting about 10,000 map requests through this configuration in about 30-40 minutes and never had a memory increase.

Now, our production servers are sometimes getting up to 20,000 requests in an hour continuously for 2-3 hours.  When this happens our Tomcat.exe process (we are on Windows 2003) goes up to the maximum amount of memory.  Things work fine for a little while, but then we get errors like:

Jun 30, 2005 9:51:50 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet esri threw exception
java.lang.OutOfMemoryError: Java heap space

Once this happens we have to restart the Tomcat process.  

I suspect that OSCache is caching the map images to the maximum setting in the cache capacity, but when it takes out the LRU image and replaces it with the a new image that is bigger than the one removed, but we are already at the maximum Tomcat memory, then it causes this error.  If the new cache image is smaller, or the load decreases before this happens, then everything works fine.  (This is just a theory. I do not have a working test case yet.)

[b]What I would like is some way of limiting the memory in use by the amount of MB, but having the disk be unlimited.  Is there a way I can do this?

Or even a way I can ensure that it always caches objects larger than X KB to disk, and smaller ones to memory.  Then I can ensure that my memory in use is never more than X KB multiplied by the cache capacity.[/b]

I would be happy to submit either or both of the ideas above as new issues, if anyone thinks that is worthwhile.

The average map image size is only 30KB, but can increase up to about 1MB or more in certain situations.

[b]Here is my cache.properties:[/b]
# CACHE IN MEMORY
#
# If you want to disable memory caching, just uncomment this line.
#
# cache.memory=false


# CACHE KEY
#
# This is the key that will be used to store the cache in the application
# and session scope.
#
# If you want to set the cache key to anything other than the default
# uncomment this line and change the cache.key
#
# cache.key=__oscache_cache


# USE HOST DOMAIN NAME IN KEY
#
# Servers for multiple host domains may wish to add host name info to
# the generation of the key.  If this is true, then uncomment the
# following line.
#
# cache.use.host.domain.in.key=true


# CACHE LISTENERS
#
# These hook OSCache events and perform various actions such as logging
# cache hits and misses, or broadcasting to other cache instances across a cluster.
# See the documentation for further information.
#
# cache.event.listeners=com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener,  \
#                       com.opensymphony.oscache.extra.CacheEntryEventListenerImpl,               \
#                       com.opensymphony.oscache.extra.CacheMapAccessEventListenerImpl,           \
#                       com.opensymphony.oscache.extra.ScopeEventListenerImpl


# CACHE PERSISTENCE CLASS
#
# Specify the class to use for persistence. If you use the supplied DiskPersistenceListener,
# don't forget to supply the cache.path property to specify the location of the cache
# directory.
# 
# If a persistence class is not specified, OSCache will use memory caching only.
#
#cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
cache.persistence.overflow.only=true
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener

# CACHE DIRECTORY
#
# This is the directory on disk where caches will be stored by the DiskPersistenceListener.
# it will be created if it doesn't already exist. Remember that OSCache must have
# write permission to this directory.
#
# Note: for Windows machines, this needs \ to be escaped
# ie Windows:
# cache.path=c:\\myapp\\cache
# or *ix:
# cache.path=/opt/myapp/cache
#
cache.path=D:\\Tomcat\\OSCache_Temp


# CACHE ALGORITHM
#
# Default cache algorithm to use. Note that in order to use an algorithm
# the cache size must also be specified. If the cache size is not specified,
# the cache algorithm will be Unlimited cache.
#
# cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
# cache.algorithm=com.opensymphony.oscache.base.algorithm.FIFOCache
# cache.algorithm=com.opensymphony.oscache.base.algorithm.UnlimitedCache


# CACHE SIZE
#
# Default cache size in number of items. If a size is specified but not
# an algorithm, the cache algorithm used will be LRUCache.
#
cache.capacity=5000


# CACHE UNLIMITED DISK
# Use unlimited disk cache or not. The default value is false, which means
# the disk cache will be limited in size to the value specified by cache.capacity.
#
# cache.unlimited.disk=false


# JMS CLUSTER PROPERTIES
#
# Configuration properties for JMS clustering. See the clustering documentation
# for more information on these settings.
#
#cache.cluster.jms.topic.factory=java:comp/env/jms/TopicConnectionFactory
#cache.cluster.jms.topic.name=java:comp/env/jms/OSCacheTopic
#cache.cluster.jms.node.name=node1


# JAVAGROUPS CLUSTER PROPERTIES
#
# Configuration properites for the JavaGroups clustering. Only one of these
# should be specified. Default values (as shown below) will be used if niether
# property is set. See the clustering documentation and the JavaGroups project
# (www.javagroups.com) for more information on these settings.
#
#cache.cluster.properties=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;mcast_send_buf_size=150000;mcast_recv_buf_size=80000):PING(timeout=2000;num_initial_members=3):MERGE2(min_interval=5000;max_interval=10000):FD_SOCK:VERIFY_SUSPECT(timeout=1500):pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800):pbcast.STABLE(desired_avg_gossip=20000):UNICAST(timeout=5000):FRAG(frag_size=8096;down_thread=false;up_thread=false):pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)
#cache.cluster.multicast.ip=231.12.21.132

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=3793&messageID=9576#9576