The Terracotta Server provides powerful distributed in-memory data management capabilities for Terracotta products (such as Ehcache and TCStore) and is the backbone for Terracotta clusters.
A Terracotta Server Array can vary from a basic two-node tandem to a multi-node array (Terracotta Server Array (TSA)) providing configurable scale, high performance, and deep failover coverage.
Add distributed caching capabilities to your Ehcache deployment today!
Terracotta additionally offers various other open source projects and code libraries which may be of interest.
apis/ehcache/lib/ehcache-<version>.jar
– This file contains the Ehcache API.apis/ehcache/lib/slf4j-api-<version>.jar
– This file is the bridge, or logging facade, to the BigMemory Max logging framework.apis/toolkit/lib/terracotta-toolkit-runtime-<version>.jar
– This JAR contains the libraries that enable connecting Ehcache to the Terracotta Server.<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
name="myBigMemoryMaxConfig">
<!-- Tell BigMemory where to write its data to disk. -->
<diskStore path="/path/to/my/disk/store/directory"/>
<!-- Set 'maxBytesLocalOffHeap' to the amount of off-heap in-memory
storage you want to use. This memory is invisible to the Java garbage
collector, providing for gigabytes to terabytes of in-memory data without
garbage collection pauses. -->
<cache name="myBigMemoryMaxStore"
maxBytesLocalHeap="512M"
maxBytesLocalOffHeap="8G">
<!-- Tell BigMemory to use the "localRestartable" persistence
strategy for fast restart (optional). -->
<persistence strategy="localRestartable"/>
<!-- Include the terracotta element so that the data set will be
managed as a client of the Terracotta server array. -->
<terracotta/>
</cache>
<!-- Specify where to find the server array configuration. In this
case, the configuration is retrieved from the local server. -->
<terracottaConfig url="localhost:9510" />
</ehcache>
Ensure that your `ehcache.xml` file is in the top-level of your classpath.
-XX:MaxDirectMemorySize=9G
Set MaxDirectMemorySize to the amount of BigMemory you have.
-Xmx1g
<?xml version="1.0" encoding="UTF-8" ?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-9.xsd">
<servers>
<server host="localhost" name="My Server Name">
<!-- Specify the port clients will connect to the server on. -->
<tsa-port>9510</tsa-port>
<!-- Configure memory (off-heap) space to use on the server. -->
<dataStorage size=ā4gā>
</dataStorage>
</server>
</servers>
<clients>
<logs>logs-%i</logs>
</clients>
</tc:tc-config>
Place your `tc-config.xml` file in the Terracotta `server/` directory.
%> cd /path/to/terracotta-<version>/server %> ./bin/start-tc-server.shFor Windows systems:
> cd \path\to\terracotta-<version>\server > .\bin\start-tc-server.batYou should see confirmation in the terminal that the server started.
apis/ehcache-terracotta-client-all.jar
– This file contains the Ehcache API.
ehcache.xml
configuration file, or modify your own existing Ehcache configuration, or update the one that is provided in the config-samples/
directory of the downloaded Terracotta Server kit. For example:
.....
<cache alias="foo">
<key-type>java.lang.String</key-type>
<resources>
<heap unit="entries">2000</heap>
<offheap unit="MB">500</offheap>
</resources>
</cache>
<cache-template name="myDefaults">
<key-type>java.lang.Long</key-type>
<value-type>java.lang.String</value-type>
<heap unit="entries">200</heap>
</cache-template>
<cache alias="bar" uses-template="myDefaults">
<key-type>java.lang.Number</key-type>
</cache>
<cache alias="simpleCache" uses-template="myDefaults" />
.....
Ensure that your ehcache.xml
file is in the top-level of your classpath.
Cache
is through a CacheManager
:
.....
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured", CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
.build();
cacheManager.init();
Cache<Long, String> preConfigured = cacheManager.getCache("preConfigured", Long.class, String.class);
Cache<Long, String> myCache = cacheManager.createCache("myCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)).build());
myCache.put(1L, "da one!");
String value = myCache.get(1L);
cacheManager.removeCache("preConfigured");
cacheManager.close();
.....
Further, for creating the cache manager with clustering support, you will need to provide the clustering service configuration:
.....
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder
.cluster(URI.create("terracotta://localhost:9510/my-application")).autoCreate());
final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
cacheManager.close();
.....
tc-config.xml
configuration file, or update the one that is provided in the config-samples/
directory of the terracotta kit. For example:
<?xml version="1.0" encoding="UTF-8"?>
<tc-config xmlns="http://www.terracotta.org/config" xmlns:ohr="http://www.terracotta.org/config/offheap-resource">
<services>
<service id="resources">
<ohr:offheap-resources>
<ohr:resource name="primary-server-resource" unit="MB">128</ohr:resource>
<ohr:resource name="secondary-server-resource" unit="MB">96</ohr:resource>
</ohr:offheap-resources>
</service>
</services>
</tc-config>
The above configuration defines two named server off-heap resources:
128 MB
size named primary-server-resource
.
secondary-server-resource
with 96 MB
capacity.
cd <path/to/terracotta/kit>/server/bin
start-tc-server.bat -f <path/to/server/config>/tc-config.xml
On Unix/Mac:
cd <path/to/terracotta/kit>/server/bin
./start-tc-server.sh -f <path/to/server/config>/tc-config.xml
JAVA_HOME
set to JDK8 while starting the Terracotta server.
INFO
log to confirm if the server started successfully, Terracotta Server instance has started up as ACTIVE node on 0:0:0:0:0:0:0:0:9510 successfully, and is now ready for work
.
apis/ehcache-terracotta-client-all.jar
– This file contains the Ehcache API.
ehcache.xml
configuration file, or modify your own existing Ehcache configuration, or update the one that is provided in the config-samples/
directory of the downloaded Terracotta Server kit. For example:
.....
<cache alias="foo">
<key-type>java.lang.String</key-type>
<resources>
<heap unit="entries">2000</heap>
<offheap unit="MB">500</offheap>
</resources>
</cache>
<cache-template name="myDefaults">
<key-type>java.lang.Long</key-type>
<value-type>java.lang.String</value-type>
<heap unit="entries">200</heap>
</cache-template>
<cache alias="bar" uses-template="myDefaults">
<key-type>java.lang.Number</key-type>
</cache>
<cache alias="simpleCache" uses-template="myDefaults" />
.....
Ensure that your ehcache.xml
file is in the top-level of your classpath.
Cache
is through a CacheManager
:
.....
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured", CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
.build();
cacheManager.init();
Cache<Long, String> preConfigured = cacheManager.getCache("preConfigured", Long.class, String.class);
Cache<Long, String> myCache = cacheManager.createCache("myCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)).build());
myCache.put(1L, "da one!");
String value = myCache.get(1L);
cacheManager.removeCache("preConfigured");
cacheManager.close();
.....
Further, for creating the cache manager with clustering support, you will need to provide the clustering service configuration:
.....
final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder
.cluster(URI.create("terracotta://localhost:9510/my-application")).autoCreate());
final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);
cacheManager.close();
.....
tc-config.xml
configuration file, or update the one that is provided in the config-samples/
directory of the terracotta kit. For example:
<?xml version="1.0" encoding="UTF-8"?>
<tc-config xmlns="http://www.terracotta.org/config" xmlns:ohr="http://www.terracotta.org/config/offheap-resource">
<services>
<service id="resources">
<ohr:offheap-resources>
<ohr:resource name="primary-server-resource" unit="MB">128</ohr:resource>
<ohr:resource name="secondary-server-resource" unit="MB">96</ohr:resource>
</ohr:offheap-resources>
</service>
</services>
</tc-config>
The above configuration defines two named server off-heap resources:
128 MB
size named primary-server-resource
.
secondary-server-resource
with 96 MB
capacity.
cd <path/to/terracotta/kit>/server/bin
start-tc-server.bat -f <path/to/server/config>/tc-config.xml
On Unix/Mac:
cd <path/to/terracotta/kit>/server/bin
./start-tc-server.sh -f <path/to/server/config>/tc-config.xml
JAVA_HOME
set to JDK8 while starting the Terracotta server.
INFO
log to confirm if the server started successfully, Terracotta Server instance has started up as ACTIVE node on 0:0:0:0:0:0:0:0:9510 successfully, and is now ready for work
.