GridGain Developers Hub

Configuring Data Regions

Overview

GridGain uses the concept of data regions to control the amount of RAM available to a cache or a group of caches. A data region is a logical extendable area in RAM in which cached data resides. You can control the initial size of the region and the maximum size it can occupy. In addition to the size, data regions control persistence settings for caches.

By default, there is one data region that can take up to 20% of RAM available to the node, and all caches you create are placed in that region; but you can add as many regions as you want. There are a couple of reasons why you may want to have multiple regions:

  • Regions allow you to configure the amount of RAM available to a cache or number of caches.

  • Persistence parameters are configured per region. If you want to have both in-memory only caches and the caches that store their content to disk, you need to configure two (or more) data regions with different persistence settings: one for in-memory caches and one for persistent caches.

  • Some memory parameters, such as eviction policies, are configured per data region.

See the following section to learn how to change the parameters of the default data region or configure multiple data regions.

Configuring Default Data Region

By default, a new cache is added to the default data region. If you want to change the properties of the default data region, you can do so in the data storage configuration.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="         http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/util         http://www.springframework.org/schema/util/spring-util.xsd">
    <bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
        <property name="dataStorageConfiguration">
            <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                <!--
                Default memory region that grows endlessly. Any cache will be bound to this memory region
                unless another region is set in the cache's configuration.
                -->
                <property name="defaultDataRegionConfiguration">
                    <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                        <property name="name" value="Default_Region"/>
                        <!-- 100 MB memory region with disabled eviction. -->
                        <property name="initialSize" value="#{100 * 1024 * 1024}"/>
                    </bean>
                </property>
            </bean>
        </property>
        <!-- other properties -->
    </bean>
</beans>
package com.gridgain.snippets;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.DataPageEvictionMode;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;

public class DataRegionConfigurationExample {

    public static void main(String[] args) {

        DataStorageConfiguration storageCfg = new DataStorageConfiguration();

        DataRegionConfiguration defaultRegion = new DataRegionConfiguration();
        defaultRegion.setName("Default_Region");
        defaultRegion.setInitialSize(100 * 1024 * 1024);

        storageCfg.setDefaultDataRegionConfiguration(defaultRegion);

        IgniteConfiguration cfg = new IgniteConfiguration();

        cfg.setDataStorageConfiguration(storageCfg);

        // Start the node.
        Ignite ignite = Ignition.start(cfg);

        ignite.close();
    }
}
var cfg = new IgniteConfiguration
{
    DataStorageConfiguration = new DataStorageConfiguration
    {
        DefaultDataRegionConfiguration = new DataRegionConfiguration
        {
            Name = "Default_Region",
            InitialSize = 100 * 1024 * 1024
        }
    }
};

// Start the node.
var ignite = Ignition.Start(cfg);
This API is not presently available for C++. You can use XML configuration.

Adding Custom Data Regions

In addition to the default data region, you can add more data regions with custom settings. In the following example, we configure a data region that can take up to 40 MB and uses the Random-2-LRU eviction policy. Note that further below in the configuration, we create a cache that resides in the new data region.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="         http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/util         http://www.springframework.org/schema/util/spring-util.xsd">
    <bean class="org.apache.ignite.configuration.IgniteConfiguration" id="ignite.cfg">
        <property name="dataStorageConfiguration">
            <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                <!--
                Default memory region that grows endlessly. Any cache will be bound to this memory region
                unless another region is set in the cache's configuration.
                -->
                <property name="defaultDataRegionConfiguration">
                    <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                        <property name="name" value="Default_Region"/>
                        <!-- 100 MB memory region with disabled eviction. -->
                        <property name="initialSize" value="#{100 * 1024 * 1024}"/>
                    </bean>
                </property>
                <property name="dataRegionConfigurations">
                    <list>
                        <!--
                        40MB memory region with eviction enabled.
                        -->
                        <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                            <property name="name" value="40MB_Region_Eviction"/>
                            <!-- Memory region of 20 MB initial size. -->
                            <property name="initialSize" value="#{20 * 1024 * 1024}"/>
                            <!-- Maximum size is 40 MB. -->
                            <property name="maxSize" value="#{40 * 1024 * 1024}"/>
                            <!-- Enabling eviction for this memory region. -->
                            <property name="pageEvictionMode" value="RANDOM_2_LRU"/>
                        </bean>
                    </list>
                </property>
            </bean>
        </property>
        <property name="cacheConfiguration">
            <list>
                <!-- Cache that is mapped to a specific data region. -->
                <bean class="org.apache.ignite.configuration.CacheConfiguration">

                    <property name="name" value="SampleCache"/>
                    <!--
                    Assigning the cache to the `40MB_Region_Eviction` region.
                    -->
                    <property name="dataRegionName" value="40MB_Region_Eviction"/>
                </bean>
            </list>
        </property>
        <!-- other properties -->
    </bean>
</beans>

For the full list of properties, refer to the DataStorageConfiguration javadoc.

DataStorageConfiguration storageCfg = new DataStorageConfiguration();

DataRegionConfiguration defaultRegion = new DataRegionConfiguration();
defaultRegion.setName("Default_Region");
defaultRegion.setInitialSize(100 * 1024 * 1024);

storageCfg.setDefaultDataRegionConfiguration(defaultRegion);
// 40MB memory region with eviction enabled.
DataRegionConfiguration regionWithEviction = new DataRegionConfiguration();
regionWithEviction.setName("40MB_Region_Eviction");
regionWithEviction.setInitialSize(20 * 1024 * 1024);
regionWithEviction.setMaxSize(40 * 1024 * 1024);
regionWithEviction.setPageEvictionMode(DataPageEvictionMode.RANDOM_2_LRU);

storageCfg.setDataRegionConfigurations(regionWithEviction);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setDataStorageConfiguration(storageCfg);

CacheConfiguration cache1 = new CacheConfiguration("SampleCache");
//this cache will be hosted in the "40MB_Region_Eviction" data region
cache1.setDataRegionName("40MB_Region_Eviction");

cfg.setCacheConfiguration(cache1);

// Start the node.
Ignite ignite = Ignition.start(cfg);
var cfg = new IgniteConfiguration
{
    DataStorageConfiguration = new DataStorageConfiguration
    {
        DefaultDataRegionConfiguration = new DataRegionConfiguration
        {
            Name = "Default_Region",
            InitialSize = 100 * 1024 * 1024
        },
        DataRegionConfigurations = new[]
        {
            new DataRegionConfiguration
            {
                Name = "40MB_Region_Eviction",
                InitialSize = 20 * 1024 * 1024,
                MaxSize = 40 * 1024 * 1024,
                PageEvictionMode = DataPageEvictionMode.Random2Lru
            },
            new DataRegionConfiguration
            {
                Name = "30MB_Region_Swapping",
                InitialSize = 15 * 1024 * 1024,
                MaxSize = 30 * 1024 * 1024,
                SwapPath = "/path/to/swap/file"
            }
        }
    }
};
Ignition.Start(cfg);
This API is not presently available for C++. You can use XML configuration.

Cache Warm-Up Strategy

The cache warm-up strategy provides an ability to load data from the disk to the node before it is joined to the cluster. This prevents performance loss when the node is restarted.

Presently, GridGain warm-up strategy implies loading data into the region, starting with indexes, until it runs out of free space.

Java Configuration

To warm up all data regions, pass the configuration parameter LoadAllWarmUpStrategy to the DataStorageConfiguration#setDefaultWarmUpConfiguration as follows:

setDefaultWarmUpConfiguration(loadAllWarmUpStrategy)

To warm up a specific data region, pass the configuration parameter LoadAllWarmUpStrategy to the DataStorageConfiguration#setWarmUpConfiguration as follows:

setWarmUpConfiguration(loadAllWarmUpStrategy)

To stop warming up all data regions, pass the configuration parameter NoOpWarmUpStrategy to the DataStorageConfiguration#setDefaultWarmUpConfiguration as follows:

setDefaultWarmUpConfiguration(noOpWarmUpStrategy)

To stop warming up a specific data region, pass the configuration parameter NoOpWarmUpStrategy to the DataStorageConfiguration#setWarmUpConfiguration as follows:

setWarmUpConfiguration(noOpWarmUpStrategy)

XML Configuration

You can use the XML cofiguration to set up your warm-up strategy:

<property name="dataStorageConfiguration">
    <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
        <!-- Default policy for all regions -->
        <property name="defaultWarmUpConfiguration">
            <bean class="org.apache.ignite.configuration.LoadAllWarmUpConfiguration"/>
        </property>
        <property name="defaultDataRegionConfiguration">
            <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                <!-- Default policy for all regions -->
                <property name="warmUpConfiguration">
                    <bean class="org.apache.ignite.configuration.LoadAllWarmUpConfiguration"/>
                </property>
            </bean>
        </property>
    </bean>
</property>

Control Script Management

You can also stop the cache warming up process by using control.sh and JMX.

To stop the warming up using control.sh:

control.sh --warm-up --stop --yes
control.bat --warm-up --stop --yes

To stop the warming up using JMX, use the method below:

org.apache.ignite.mxbean.WarmUpMXBean#stopWarmUp