|
Search XAP 7.0
Offline Documentation
Download latest offline documentation in HTML format:
|
Summary: Setting Space cache policy, memory usage and rules for exceeding physical memory capacity.
Overview | Cache Eviction Policies | Defining the Cache Size | Monitoring the Memory Manager's Activity | How the LRU Eviction Works? | The Memory Manager | Garbage Collection Behavior and Space Response Time Tango | Memory Manager Activity when initializing the space | Memory Manager and Transient Objects | How can I Get Deterministic Behavior During Eviction Objects? | Memory Manager Parameters | Exceeding Physical Memory Capacity
OverviewThe Memory Management facility is used to assist the client avoiding situation where a space server will not get into an Out Of Memory failure scenario. Based on the configured cache policy the memory manager protect the space (and the application in case running in collocated mode) from consuming memory beyond the defined threshold.
The space's memory can be managed with the following facilities:
Cache Eviction PoliciesThe space supports two cache eviction policies (0 - LRU POLICY, 1 - ALL IN CACHE ) defined via the following property: space-config.engine.cache_policy
The space memory manager using a dedicated thread called Evictor - this thread handles the eviction of objects and identifying memory shortage event. In general, Eviction can be done using:
Evicting an object from the space requires the space engine to lock the LRU chain during the object removal and to update the relevant indexes. This means the eviction based on Available memory that is done in batches, might impact the space responsiveness to client requests. Still, you might need to use this in case you can't estimate the amount of objects within the space. Defining the Cache SizeWhen a persistent space (having External Data Source or JDBC Storage Adapter used) running in LRU cache policy mode and the space has been started/deployed, it loads data from the underlying durable data source before being available for clients to access. The default behavior is to load data up to 50% of the space-config.engine.cache_size value. When the space-config.engine.memory_usage is true (evicting data from the space based on free heap size), is it recommended to have a large value for the space-config.engine.cache_size property. This instructs the space engine to ignore the amount of space objects when launching the eviction mechanism. This ensures that the eviction is based only on heap size free memory. The combination of the above (large space-config.engine.cache_size and space restart) may lead to out of memory problems. To avoid this, configure the space-config.engine.initial_load to have a low value (5 below means 5% of the space-config.engine.cache_size - default is 50%): space-config.engine.initial_load=5 The space-config.engine.initial_load_class property can be used to specify which class(s) to load its data. Monitoring the Memory Manager's ActivityYou can monitor the memory manager activity by moving the com.gigaspaces.core.memorymanager logging entry to ALL. How the LRU Eviction Works?The LRU eviction has 2 eviction strategies: This strategy checks the amount of space objects and evicts the relevant object. One object is evicted when reaching max amount of objects. This eviction routine is called when:
2. Based on the amount of available memory the JVM hosting the space has - When using this strategy, you should perform some tuning to provide deterministic behavior. This strategy is turned on when the space-config.engine.memory_usage.enabled value is true. This strategy is very complex to use when having multiple spaces running within the same JVM. The Eviction FlowThe LRU eviction based on amount of available memory performs the following:
The used memory rate calculated via: Used_memory_rate = (Runtime.totalMemory() - Runtime.freeMemory() * 100.0) / Runtime.maxMemory() The Memory ManagerThe space-config.engine.memory_usage properties provides options for controlling the space memory utilization and allows you to evict objects from the space. Objects are evicted when the number of cached objects reaches its maximum size or the memory usage reaches its limit. high_watermark_percentage >= write_only_block_percentage >= write_only_check_percentage >= low_watermark_percentage
space-config.engine.cache_policy=0 space-config.engine.cache_size=5000000 space-config.engine.memory_usage.enabled=true space-config.engine.memory_usage.high_watermark_percentage=95 space-config.engine.memory_usage.write_only_block_percentage=85 space-config.engine.memory_usage.write_only_check_percentage=76 space-config.engine.memory_usage.low_watermark_percentage=75 space-config.engine.memory_usage.eviction_batch_size=500 space-config.engine.memory_usage.retry_count=5 space-config.engine.memory_usage.explicit-gc=false space-config.engine.memory_usage.retry_yield_time=2000
SpaceMemoryShortageExceptionThe org.openspaces.core.SpaceMemoryShortageException (it wraps com.j_spaces.core.MemoryShortageException) is thrown when:
The org.openspaces.core.SpaceMemoryShortageException or com.j_spaces.core.MemoryShortageException includes information about:
Here is an example for the org.openspaces.core.SpaceMemoryShortageException message: org.openspaces.core.SpaceMemoryShortageException at: host: MachineHostName, container: mySpace_container1_1, space mySpace, total memory: 1820 mb, used memory: 1283 mb If a client running a local cache and the local cache can't evict its data fast enough or somehow there is no available memory for the local cache to function the following will be thrown: org.openspaces.core.SpaceMemoryShortageException: Memory shortage at: host: MachineHostName, container: mySpace_container_container1, space mySpace_container_DCache, total memory: 1527 mb, used memory: 1497 mb
space-config.engine.memory_usage.explicit-gcThe memory manger has very delicate feature calld the explicit-gc. When enabled, the space performs an explicit GC call before checking how much memory is used. When turned on - this will block clients from accessing the space during the GC activity. This can cause a domino affect, resulting unneeded failover or client total hang. The problem would be sever with clustered environment where both primary and backup space JVM calling GC explicitly in the same time, holding back the primary from both serving the client and sending operations to the backup. With a small value for the space-config.engine.memory_usage.retry_yield_time or when the space-config.engine.memory_usage.explicit-gc is turned off (false as a value), the space might evict most of its data once the space-config.engine.memory_usage.write_only_block_percentage or the space-config.engine.memory_usage.high_watermark_percentage is breached. This happens since the JVM hosting the space might not perform garbage collection immediately between each eviction cycle, resulting the memory usage to remain intact, causing another evict cycle to be called. When using the space-config.engine.memory_usage.explicit-gc option:
Calculating available memory is performed when the following operations are called:
Garbage Collection Behavior and Space Response Time TangoIn general, when the JVM Garbage Collection (GC) is called, there is a chance clients accessing the space will be affected. See below regular GC behavior when eviction is going on (based on available memory) and new objects are written into the space:
The Incremental GC behavior will have more moderate activity with on going garbage collection without the risk missing a garbage collection and getting OOME - see below behavior when eviction is going on (based on available memory) and new objects are written into the space:
When the LRU eviction is based on maximum amount of objects the memory utilization graph would look like this - very small amplitude.
This behavior achieved since the memory manager evicts objects one by one from the space and not in batches. So the amount of work the JVM garbage collector needs to perform is relatively small. This also does not affect the clients communicating with the space and provide very deterministic response time - i.e. very small chance for client hiccup.
Memory Manager Activity when initializing the spaceIn this phase of the space life cycle, the space checks for the amount of available memory. This is relevant when the space perform warm start such as ExternalDataSource.initialLoad() or persistent space using SA with RDBMS or embedded H2 database. Memory Manager and Transient ObjectsTransient Objects are specified using the @SpaceClass (persist=false) decoration. You may specify transient decoration at the class or object level (field method level decoration).
How can I Get Deterministic Behavior During Eviction Objects?In order to have a deterministic behavior of the memory manager when evicting objects based on amount of free memory in such a way that it will:
You should:
Here are good settings for a JVM with 2G heap size with 5K object size. With the following settings eviction will happen once the JVM will consume more than 1.4 G: space-config.engine.cache_policy=0 space-config.engine.cache_size=200000 space-config.engine.memory_usage.enabled=true space-config.engine.memory_usage.high_watermark_percentage=70 space-config.engine.memory_usage.write_only_block_percentage=68 space-config.engine.memory_usage.write_only_check_percentage=65 space-config.engine.memory_usage.low_watermark_percentage=60 space-config.engine.memory_usage.eviction_batch_size=2000 space-config.engine.memory_usage.retry_count=100 space-config.engine.memory_usage.explicit-gc=false space-config.engine.memory_usage.retry_yield_time=4000 Here are the Java arguments (using incremental GC) to use for the JVM running the Space/GSC: -Xmx2g -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:ParallelGCThreads=8 -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:MaxGCPauseMillis=1000 When having small amount of objects within the space (less than 50,000) with relatively large size (100K and above) and you are running with LRU cache policy you should:
Memory Manager Parameters
When space-config.engine.memory_usage.enabled=true (evicting data from the space is based also on free heap size), you might want to have large value for the space-config.engine.cache_size property. This essentially instructs the space engine to ignore the amount of space objects when trigering the eviction mechanism. This ensures that the eviction is based only on JVM heap size free memory. The combination of the above (large space-config.engine.cache_size and space restart) might lead to out-of-memory problems when the space starts. To avoid this problem, configure space-config.engine.initial_load to a low value:space-config.engine.initial_load=5 Exceeding Physical Memory CapacityThe overall space capacity is not necessarily limited to the capacity of its physical memory. Currently there are two options for exceeding this limit:
|
Memory Management Facilities
IMPORTANT: This is an old version of GigaSpaces XAP. Click here for the latest version.
(None)




