Program guide > Performance considerations
Plug-in evictor performance best practices
If you use plug-in evictors, they are not active until you create them and associate them with a backing map. The following best practices will increase performance for least frequently used (LFU) and least recently used (LRU) evictors.
Least frequently used (LFU) evictor
The concept of a LFU evictor is to remove entries from the map that are used infrequently. The entries of the map are spread over a set amount of binary heaps. As the usage of a particular cache entry grows, it becomes ordered higher in the heap. When the evictor attempts a set of evictions it removes only the cache entries that are located lower than a specific point on the binary heap. As a result, the least frequently used entries are evicted.
Least recently used (LRU) evictor
The LRU Evictor follows the same concepts of the LFU Evictor with a few differences. The main difference is that the LRU uses a first in, first out queue (FIFO) instead of a set of binary heaps. Every time a cache entry is accessed, it moves to the head of the queue. Consequently, the front of the queue contains the most recently used map entries and the end becomes the least recently used map entries. For example, the A cache entry is used 50 times, and the B cache entry is used only once right after the A cache entry. In this situation, the B cache entry is at the front of the queue because it was used most recently, and the A cache entry is at the end of the queue. The LRU evictor evicts the cache entries that are at the tail of the queue, which are the least recently used map entries.
LFU and LRU properties and best practices to improve performance
Number of heaps
When using the LFU evictor, all of the cache entries for a particular map are ordered over the number of heaps that you specify, improving performance drastically and preventing all of the evictions from synchronizing on one binary heap that contains all of the ordering for the map. More heaps also speeds up the time that is required for reordering the heaps because each heap has fewer entries. Set the number of heaps to 10% of the number of entries in the BaseMap.
Number of queues
When using the LRU evictor, all of the cache entries for a particular map are ordered over the number of LRU queues that you specify, improving performance drastically and preventing all of the evictions from synchronizing on one queue that contains all of the ordering for the map. Set the number of queues to 10% of the number of entries in the BaseMap.
When an LFU or LRU evictor begins evicting entries, it uses the MaxSize evictor property to determine how many binary heaps or LRU queue elements to evict. For example, assume that you set the number of heaps or queues to have about 10 map entries in each map queue. If the MaxSize property is set to 7, the evictor evicts 3 entries from each heap or queue object to bring the size of each heap or queue back down to 7. The evictor only evicts map entries from a heap or queue when that heap or queue has more than the MaxSize property value of elements in it. Set the MaxSize to 70% of the heap or queue size. For this example, the value is set to 7. You can get an approximate size of each heap or queue by dividing the number of BaseMap entries by the number of heaps or queues that are used.
An evictor does not constantly remove entries from the map. Instead it is idle for a set amount of time, only checking the map every n number of seconds, where n refers to the SleepTime property. This property also positively affects performance: running an eviction sweep too often lowers performance because of the resources that are needed for processing them. However, not using the evictor often can result in a map that has entries that are not needed. A map full of entries that are not needed can negatively affect both the memory requirements and processing resources that are required for the map. Setting the eviction sweep interval to fifteen seconds is a good practice for most maps. If the map is written to frequently and is used at a high transaction rate, consider setting the value to a lower time. If the map is accessed infrequently, you can set the time to a higher value.
The following example defines a map, creates a new LFU evictor, sets the evictor properties, and sets the map to use the evictor:
//Use ObjectGridManager to create/get the ObjectGrid. Refer to // the ObjectGridManger section ObjectGrid objGrid = ObjectGridManager.create............ BackingMap bMap = objGrid.defineMap("SomeMap"); //Set properties assuming 50,000 map entries LFUEvictor someEvictor = new LFUEvictor(); someEvictor.setNumberOfHeaps(5000); someEvictor.setMaxSize(7); someEvictor.setSleepTime(15); bMap.setEvictor(someEvictor);
Use the LRU evictor is very similar to using an LFU evictor. An example follows:
ObjectGrid objGrid = new ObjectGrid; BackingMap bMap = objGrid.defineMap("SomeMap"); //Set properties assuming 50,000 map entries LRUEvictor someEvictor = new LRUEvictor(); someEvictor.setNumberOfLRUQueues(5000); someEvictor.setMaxSize(7); someEvictor.setSleepTime(15); bMap.setEvictor(someEvictor);
Notice that only two lines are different from the LFUEvictor example.
Parent topic:Plug-ins for evicting cache objects
Parent topic:Performance considerations for application developers
TimeToLive (TTL) evictor
Plug in a pluggable evictor
Write a custom evictor
CopyMode best practices
Byte array maps
Locking performance best practices
ObjectTransformer interface best practices
Query performance tuning