|
Search XAP 6.6
Offline Documentation
Download latest offline documentation in HTML format:
|
Summary: Setting cache policy, memory usage and rules for exceeding physical memory capacity.
Overview | Cache Policy | Monitoring the Memory Manager | Defining Cache Size | How the LRU Eviction Works? | Memory Usage | GC Behavior and Space Response Time Tango | Memory Manager Activity when initializing the space | Memory Manager and Transient Entries | How can I Get Deterministic Behavior During Eviction? | 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 from consuming memory beyond the defined threshold.
Memory management can be achieved in three main ways:
Cache PolicyThe space supports two cache management 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 entries and identifying memory shortage event. In general, Eviction can be done using:
Evicting an entry from the space requires the space engine to lock the LRU chain during the entry 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 entries within the space. Monitoring the Memory ManagerYou can monitor the memory manager activity by moving the com.gigaspaces.core.memorymanager logging entry to ALL. Defining Cache SizeWhen a persistent space (using the JDBC SA or an indexed file) is using LRU cache policy and the space has been restarted, it loads data from the underlying durable data source (RDBMS, indexed file) 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 Entries inside the space 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. How the LRU Eviction Works?The LRU eviction has 2 eviction strategies: This activity checks the amount of entries within the space and evicts relevant entry. One entry is evicted when reaching max amount of entries. This is called when:
2. Based on the amount of available memory the JVM hosting the space has - need some tuning to provide deterministic behavior. This is turned on when the space-config.engine.memory_usage.enabled value is true. Very complex to use when having multiple spaces running within the same JVM (GSC). The LRU eviction based on amount of available memory performs the following: Start loop
End loop The Wait to GC to reclaim memory step has been added recently to avoid the problem of evicting too many entries. The problem manifest itself when the Check used memory phase is called where the memory of evicted objects has not been reclaimed causing the JVM to return wrong result for the used memory. The used memory rate calculated via: Used_memory_rate = (Runtime.totalMemory() - Runtime.freeMemory() * 100.0) / Runtime.maxMemory() Memory UsageThe space-config.engine.memory_usage properties provides options for controlling the space memory utilization and allows you to evict Entries from the space. Entries are evicted when the number of cached Entries reaches its maximum size or the memory use reaches its limit.
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
MemoryShortageExceptionThe com.j_spaces.core.MemoryShortageException is thrown when:
The com.j_spaces.core.MemoryShortageException includes information about:
Here is an example for the MemoryShortageException message: Memory shortage at: host: pc-lab38, container: mySpace_container1_1, space mySpace, total memory: 1820 mb, used memory: 1283 mb explicit-gcThe memory manger has very delicate feature - <explicit-gc>. When enabled, this 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 small value for the retry_yield_time or when the explicit-gc is turned off (false as a value), the space might evict most of its data once the write_only_block_percentage or the high_watermark_percentage is breached. Since the space does perform garbage collection between each batch eviction cycle, the evicted object data is not reclaimed immediately by the garbage collection, and the space continuous to evict Entries. When using the explicit-gc option:
GC Behavior and Space Response Time TangoIn general, when the 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 entries 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 entries are written into the space:
When the LRU eviction is based on maximum amount of entries the memory utilization graph would look like this - very small amplitude.
This behavior achieved since the memory manager evicts entries 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 EntriesWhen using transient entries:
How can I Get Deterministic Behavior During Eviction?In order to have deterministic behavior of of the memory manager when evicting entries based on amount of free memory in such a way that it will:
You should:
Here are good settings for a JVM with 2G with 5 K 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_OPTIONS (using incremental GC) to use for the JVM running the Space/GSC: -Xmx2g -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=10 -XX:CMSIncrementalDutyCycle=50 -XX:ParallelGCThreads=8 -XX:+UseParNewGC -Xmn5m -XX:MaxGCPauseMillis=1000 -XX:GCTimeRatio=4 -XX:+DisableExplicitGC " 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: Exceeding Physical Memory CapacityThe overall space capacity is not necessarily limited to the capacity of its physical memory.
|
Memory Management Facility
IMPORTANT: This is an old version of GigaSpaces XAP. Click here for the latest version.
(None)




