Apache Ignite

GridGain Developer Hub - Apache Ignitetm

Welcome to the Apache Ignite developer hub run by GridGain. Here you'll find comprehensive guides and documentation to help you start working with Apache Ignite as quickly as possible, as well as support if you get stuck.

 

GridGain also provides Community Edition which is a distribution of Apache Ignite made available by GridGain. It is the fastest and easiest way to get started with Apache Ignite. The Community Edition is generally more stable than the Apache Ignite release available from the Apache Ignite website and may contain extra bug fixes and features that have not made it yet into the release on the Apache website.

 

Let's jump right in!

 

Documentation     Ask a Question     Download

 

Javadoc     Scaladoc     Examples

Off-Heap Memory

Off-Heap memory allows your cache to overcome lengthy JVM Garbage Collection (GC) pauses when working with large heap sizes by caching data outside of main Java Heap space, but still in RAM.

Off-Heap Indexes

Note that when off-heap memory is configured, Ignite will also store query indexes off-heap as well. This means that indexes will not take any portion of on-heap memory.

Off-Heap Memory vs. Multiple Processes

You can also manage GC pauses by starting multiple processes with smaller heap on the same physical server. However, such approach is wasteful when using REPLICATED caches as we will end up with caching identical replicated data for every started JVM process.

Tiered Off-Heap Storage

Ignite provides tiered storage model, where data can be stored and moved between on-heap, off-heap, and swap space. Going up the tier provides more data storage capacity, with gradual increase in latency.

Ignite provides three types of memory modes, defined in CacheMemoryMode, for storing cache entries, supporting tiered storage model:

Memory Mode
Description

ONHEAP_TIERED

Store entries on-heap and evict to off-heap and optionally to swap.

OFFHEAP_TIERED

Store entries off-heap, bypassing on-heap and optionally evicting to swap.

OFFHEAP_VALUES

Store keys on-heap and values off-heap.

Cache can be configured to use any of the three modes by setting the memoryMode configuration property of CacheConfiguration, as described below.

ONHEAP_TIERED

In Ignite, ONHEAP_TIERED is the default memory mode, where all cache entries are stored on-heap. Entries can be moved from on-heap to off-heap storage and later to swap space, if one is configured.

To configure ONHEAP_TIERED memory mode, you need to:

  1. Set memoryMode property of CacheConfiguration to ONHEAP_TIERED.
  2. Enable off-heap memory (optionally).
  3. Configure eviction policy for on-heap memory.
<bean class="org.apache.ignite.configuration.CacheConfiguration">
  ...
  <!-- Store cache entries on-heap. -->
  <property name="memoryMode" value="ONHEAP_TIERED"/> 

  <!-- Enable Off-Heap memory with max size of 10 Gigabytes (0 for unlimited). -->
  <property name="offHeapMaxMemory" value="#{10 * 1024L * 1024L * 1024L}"/>

  <!-- Configure eviction policy. -->
  <property name="evictionPolicy">
    <bean class="org.apache.ignite.cache.eviction.fifo.CacheFifoEvictionPolicy">
      <!-- Evict to off-heap after cache size reaches maxSize. -->
      <property name="maxSize" value="100000"/>
    </bean>
  </property>
  ...
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);

// Set off-heap memory to 10GB (0 for unlimited)
cacheCfg.setOffHeapMaxMemory(10 * 1024L * 1024L * 1024L);

CacheFifoEvictionPolicy evctPolicy = new CacheFifoEvictionPolicy();

// Store only 100,000 entries on-heap.
evctPolicy.setMaxSize(100000);

cacheCfg.setEvictionPolicy(evctPolicy);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

Eviction Policy

Note that if you do not enable eviction policy in ONHEAP_TIERED mode, data will never be moved from on-heap to off-heap memory.

OFFHEAP_TIERED

This memory mode allows you to configure your cache to store entries directly into off-heap storage, bypassing on-heap memory. Since all entries are stored off-heap, there is no need to explicitly configure an eviction policy. If off-heap storage size is exceeded (0 for unlimited), then LRU eviction policy is used to evict entries from off-heap store and optionally moving them to swap space, if one is configured.

To configure OFFHEAP_TIERED memory mode, you need to:

  1. Set memoryMode property of CacheConfiguration to OFFHEAP_TIERED.
  2. Enable off-heap memory (optionally).
<bean class="org.apache.ignite.configuration.CacheConfiguration">
  ...
  <!-- Always store cache entries in off-heap memory. -->
  <property name="memoryMode" value="OFFHEAP_TIERED"/>

  <!-- Enable Off-Heap memory with max size of 10 Gigabytes (0 for unlimited). -->
  <property name="offHeapMaxMemory" value="#{10 * 1024L * 1024L * 1024L}"/>
  ...
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED);

// Set off-heap memory to 10GB (0 for unlimited)
cacheCfg.setOffHeapMaxMemory(10 * 1024L * 1024L * 1024L);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

OFFHEAP_VALUES

Setting this memory mode allows you to store keys on-heap and values off-heap. This memory mode is useful when keys are small and values are large.

To configure OFFHEAP_VALUES memory mode, you need to:

  1. Set memoryMode property of CacheConfiguration to OFFHEAP_VALUES.
  2. Enable off-heap memory.
  3. Configure eviction policy for on-heap memory (optionally).
<bean class="org.apache.ignite.configuration.CacheConfiguration">
  ...
  <!-- Always store cache entries in off-heap memory. -->
  <property name="memoryMode" value="OFFHEAP_VALUES"/>

  <!-- Enable Off-Heap memory with max size of 10 Gigabytes (0 for unlimited). -->
  <property name="offHeapMaxMemory" value="#{10 * 1024L * 1024L * 1024L}"/>
  ...
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setMemoryMode(CacheMemoryMode.OFFHEAP_VALUES);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

Swap Space

Whenever your data set exceeds the limits of on-heap and off-heap memory, you can configure swap space in which case Ignite will evict entries to the disk instead of discarding them.

Swap Space Performance

Since swap space is on-disk, it is significantly slower than on-heap or off-heap memory.

<bean class="org.apache.ignite.configuration.CacheConfiguration">
  ...
  <!-- Enable swap. -->
  <property name="swapEnabled" value="true"/> 
  ...
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setSwapEnabled(true);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

Off-Heap Memory