Getting Started With NCache Java Edition (Using Docker)
NCache Java Edition with distributed cache technique is a powerful tool that helps Java applications run faster, handle more users, and be more reliable. In today's world, where people expect apps to work quickly and without any problems, knowing how to use NCache Java Edition is very important. It's a key piece of technology for both developers and businesses who want to make sure their apps can give users fast access to data and a smooth experience. This makes NCache Java Edition an important part of making great apps.
This article is made especially for beginners to make the ideas and steps of adding NCache to your Java applications clear and easy to understand. It doesn't matter if you've been developing for years or if you're new to caching, this article will help you get a good start with NCache Java Edition. Let’s start with a step-by-step process to set up a development workstation for NCache with the Java setup.
NCache Server Installation: Java Edition
NCache has different deployment options. The classification is listed below:
- On-premises
- Cloud
- Using Docker/Kubernetes
You can check all the deployment options and the package available for the deployment here.
NCache recommends at least SO-16 (16GB RAM, 8v CPU) to get optimum performance in a production environment, for a higher transaction load we should go with SO-32, SO-64, or SO-128.
NCache Server Deployment With Docker Image
NCache provides different images (alachisoft/ncache - Docker Image | Docker Hub) for Windows and Linux platform Java edition.
Let’s see how to deploy the NCache server using the latest Linux Docker image.
Use the below Docker command to pull the latest image:
docker pull alachisoft/ncache:latest-java
Now we successfully pulled the Docker image.
Run the Docker image using the Docker command below:
- For a development workstation:
docker run --name ncache -itd -p 8251:8251 -p 9800:9800 -p 8300:8300 -p 8301:8301 alachisoft/ncache:latest-java
Use the actual host configuration for the production NCache server:
docker run –name ncache -itd –network host alachisoft/ncache:latest-java
The above command will run the NCache server and listen to port 8251.
Now, launch NCache Management Center using the browser (localhost:8251). You will get a modal popup to register your license key as shown below:
Click on Start Free Trial to activate the free trial with the license key, using the form below.
You can register your license key using this registration page form or the Docker command to register the license key as given below:
docker exec -it ncache /opt/ncache/bin/tools/register-ncacheevaluation -firstname [registered first name] -lastname [registered last name] -company [registered company name] -email [registered e-mail id] -key [key]
Now, open the NCache Management Center from the browser http://localhost:8251/.
NCache Cache Cluster
Let’s install one more image in a different instance, with proper network configuration. Use the document below for the network configuration with NCache docker image deployment:
- Create NCache Containers for Windows Server
I deployed one image in the 10.0.0.4 instance and another in the 10.0.0.5 instance. I just hopped into 10.0.0.4 NCache Management Center and removed the default cluster cache created during the installation.
Let’s create a new clustered cache using the NCache Management Center Wizard.
Click on New from the Clustered Cache page as shown in the figure below:
It’s a 7-step process to create a clustered cache with the NCache Management Center interface, which we will go through one by one.
Step 1: In-Memory Store
In this step, you can define the in-memory store type, the name of the clustered cache, and the serialization type. In my case, I named the clustered cache as demoCache and the serialization as JSON.
Step 2: Caching Topology
Define the caching topology in the screen; in my case, I just went with default options.
Step 3: Cache Partitions and Size
In this screen, we can define the cache partition size. In my case, I just went with the default value. With this option, it will skip step 4.
Also, I added two server nodes: 10.0.0.4 and 10.0.0.5.
Step 5: Cluster TCP Parameters
Define the Cluster Port, Port Range, and Batch Interval values. In my case, I went with the default values.
Step 6: Encryption and Compression Settings
You can enable the encryption and compression settings in this step. I just went with default values.
Step 7: Advanced Options
You can enable eviction and also check other advanced options. In my case, I checked to start the cache on the finish. Finally, click on Finish. Once the process is complete, it will create and start the clustered cache with two nodes. (10.0.0.4 and 10.0.0.5).
Now the cluster is formed.
Start the Cache
You can use the start option from the NCache Management Center to start the clustered cache, as shown in the below figure.
You can also use the command below to start the server:
start-cache –name demoCache
Run a Stress Test
Click Test-Stress and select the duration to run the stress test. This is one of my favorite features in NCache Management Center where you can initiate a stress test with ease just by a button click.
You can also use the commands below to start the server. For example, to initiate a Test-Stress for the demoCache
cluster with default settings:
test-stress –cachename demoCache
Click on Monitor to check the metrics.
You can monitor the number of requests processed by each node.
Click on Statistics to get the complete statistics of the clustered caches.
SNMP Counter to Monitor NCache
Simple Network Management Protocol (SNMP) is a key system used for keeping an eye on and managing different network devices and their activities. It's a part of the Internet Protocol Suite and helps in sharing important information about the network's health and operations between devices like routers, switches, servers, and printers. This allows network managers to change settings, track how well the network is doing, and get alerts on any issues. SNMP is widely used and important for keeping networks running smoothly and safely. It's a vital part of managing and fixing networks.
NCache has made SNMP monitoring easier by now allowing the publication of counters through a single port. Before, a separate port was needed for each cache.
Make sure the NCache service and cache(s) to monitor are up and running.
Configure NCache Service
The Alachisoft.NCache.Service.dll.config file, located in the %NCHOME%\bin\service folder, provides the ability to activate or deactivate the monitoring of cache counters via SNMP by modifying particular options. These options are marked by specific tags.
Update the value for the tags below:
<add key="NCacheServer.EnableSnmpMonitoring" value="true"/>
<add key="NCacheServer.SnmpListenersInfoPort" value="8256"/>
<add key="NCacheServer.EnableMetricsPublishing" value="true"/>
- Change the
NCacheServer.EnableSnmpMonitoring
tag totrue
to turn on or off the SNMP monitoring of NCache cache counters. Initially, this tag is off (false
). - Change the
NCacheServer.SnmpListenersInfoPort
tag totrue
to set the port for SNMP to listen on. The default port is 8256, but you can adjust it according to your needs. - Change the
NCacheServer.EnableMetricsPublishing
tag to true if you want to start or stop sending metrics to the NCache Service.
Remember to reboot the NCache Service once you've made the necessary adjustments to the service configuration files.
SNMP Monitoring
NCache has made available a single MIB file called alachisoft.mib that keeps track of various counters which can be checked using SNMP. This file tells you about the ports used for different types of caches and client activities. You can find this file at %NCHOME%\bin\resources. To look at these counters, you can use a program called MIB Browser Free Tool to go through the MIB file.
Use port 8256 to connect with NCache, and open the SNMP Table from View to check all the attributes of the NCache as shown in the figure below:
To check specific attribute details in the SNMP Table, first pick the attributes you want to see. For a sample, I have selected cacheName
, cacheSize
, cacheCount
, fetchesPerSec
, requestsPerSec
, additionPerSec
. Then, click on View from the menu at the top before you choose the SNMP Table. You'll then see the values of the counter in the table as shown in the figure below.
Summary
This article provides a beginner-friendly guide on how to get started with NCache Java Edition, covering essential steps such as installing the NCache server, deploying it using a Docker image, starting the cache, conducting a stress test to evaluate its performance, and monitoring its operation through JMX counters. It helps you get started with enhancing your Java application's speed and reliability by implementing distributed caching with NCache.