Today, I will be talking about getting started with the Java Edition of NCache. Please note there's a separate video on getting started with the .NET Edition of NCache, if you're interested in that. There are six steps to getting started with the NCache Java Edition.
Since this video is on the Java Edition of NCache, I will be focusing mainly on Java apps. But, please note that you can use NCache from Node.js, Python, and .NET applications as well.
The first step is the software setup. NCache gives you multiple deployment options, number one is the on-premises option. This is your own data center where you have to install NCache. Number two is the Cloud option.
On the on-premises option you can either download NCache software from our website, I will show you that here. If you come to our website and go to the download page you can see that there are different download options. Since this video is on the Java Edition I would suggest that you download the Java Edition of NCache. Either .tar.gz for Linux, or .msi for Windows. Or you could do a docker pull command which is what I will be using in this video anyway. So, that's the first way to obtain software for an on-premises situation.
The second deployment option is the Cloud. In the Cloud, NCache gives you two ways to use NCache. One is to purchase NCache Cloud SaaS offering from Azure and AWS Marketplace. Let me take you there. So, if you come to the Azure Marketplace you'll see that NCache Enterprise Cloud is available there that you can purchase from. And, the same is true for the AWS Marketplace. Please note that if you purchase the NCache Cloud either from AWS or Azure Marketplace, you're actually purchasing it from Azure or AWS and not from Alachisoft.
The other way to use NCache in the Cloud is the NCache software option in BYOL model. This is where you purchase NCache from Alachisoft but you deploy it in the Cloud. This is available on all clouds including Azure and AWS. I would strongly recommend that even if it makes sense for you to purchase the SaaS offering of NCache, which is NCache Cloud, is to First do your evaluation and your proof of concept with the NCache software option where you just install it in the Cloud, and then when it's time to purchase you can go ahead with the NCache Cloud offering.
I've already talked about Docker is being fully supported by NCache and I'm going to demonstrate that in this video. NCache also fully supports Kubernetes. You can use NCache in AWS EKS, Google GKE, Azure AKS, Red Hat OpenShift, or any other Kubernetes flavors that you like. The client portion of NCache in your case is going to be Java. So, I've already shown you the Java Maven, actually, I did not. So, let me bring you back here. So, if you come to the download page after the NCache Java Edition you have the NCache Client. So, you can download the NCache Java client which is a maven package, or you can actually go to the Maven tab here and look at all the different Java Maven packages. There's an NCache Client, there's NCache Sessions, there's the NCache Maven package for Spring and Hibernate. You can also come to the Maven repository and type a word ‘NCache’ and you'll see all of them available here as well. So, that's for the Java part again the same goes for Node.js, Python, and .NET Clients.
The second thing to understand about deploying NCache is the systems requirement. What type of an NCache Server profile do you need? On the hardware side, it's pretty straightforward. NCache gives you eight different server plans. There's an SO-4, SO-8, SO-16, SO-32, SO-64, and SO-128. Those numbers signify RAM but they also have their vCPU combinations. You can come to the NCache pricing page, and you'll see all those details mentioned here.
I strongly recommend that if you're going to deploy NCache in production that you should not deploy anything less than SO-16 because, you know, to get the optimum performance, and you know, even for higher transaction load you should go with SO-32, or SO-64, SO-128. For non-prod you can go with SO-8 if you don't have enough of stress in this. But, even for prod, for DR (disaster recovery), and for staging, usually which is all production like environments SO-16 or higher is what we recommend. For Dev, QA, and test, you can go with SO-8 if you want and, SO-4 being the really low end.
The operating system for an NCache Server is either Linux or Windows. Linux is the more preferred operating system for the Java Edition. Here we support Ubuntu, Debian, and Red Hat Enterprise Linux. You have to make sure the Java 17 is installed on your NCache Server box whether it is Linux or Windows. On the Windows side we support Windows Server 2016 or later.
The NCache Clients are actually your application servers, or your web server boxes. So, the hardware is very similar to the NCache Server box. And, the operating system again for Java applications is mostly Linux where we support Ubuntu, Debian, and Red Hat Enterprise Linux. And, the Java version should be 11 or higher for the Client, even though it's 17 for the Server. On windows, again same thing, Windows Server 2016 or later is the operating system, and the Java 11 or later.
NCache is typically deployed either as a distributed cache in mission-critical applications which are really high transaction applications, which are Web Applications, Microservices, Web APIs, or Server Applications that are trying to improve their performance and scalability by reducing those expensive database trips to the database. NCache is deployed as two or more cache servers in a cluster. Or NCache is used as a messaging and streams platform. And, even there NCache is deployed as two or more servers as a messaging and streams platform. So, either way, NCache has two or more server cluster.
Okay, let's go ahead and create an NCache Cluster. By the way, in distributed caching, we strongly recommend that you have a 5:1 between your cache servers and the application tier. You can go slightly higher than 5:1 if needed based on your use case, but 5:1 is the most optimum that we've seen over the years. And, since you're trying to optimize your application performance and scalability with NCache, it's really important that you pay attention to this configuration detail to get the best out of NCache. Okay, let's go ahead and create an NCache Cluster. So, I have three servers that I'm going to use as NCache Servers. They're all Linux boxes DEMO8, DEMO9, and DEMO10, actually, 114, 115, 116. Then, I have two client boxes which are again both server type of boxes with their NCache Clients. And, one is a Windows server box which is what I'm logged into right now, and one is a Linux box. So, 112 is the box I'm logged into right now and the way to confirm that is if I go and type ip config as you can see it is 112.
So, let's go ahead and create an NCache Cluster. I will start NCache Management Center, but since I'm on 112 box it's show showing me the 112 box whereas I want to manage 114. I could have gotten any of those. I could have connected any of these two and then manage the entire cluster. So, I'm going to say 'New' clustered cache. I will name my cache as 'democache'. I will use JSON serialization which is good for language portability between different types of languages, Java, .NET, and others. You can read about them in the docs.
I'm going to pick 'Partition Replica' as a caching topology with an 'Asynchronous' replication. There's a detailed video on NCache architecture that talks about all the caching topologies and all these details, please do watch it. It's very very informative.
I'm going to create a 1 gigabyte cache only, although yours is probably going to be much bigger than that, because as I said, a typical production box is 16 Gig of RAM. So, I'm going to give 114, and 115 as my two boxes here. I will hit 'Next'.
I'm going to just take the defaults. Although, I'm not enabling compression but it's a very useful feature. If you turn on compression anything that is larger than whatever threshold you specify NCache compresses it on the client end, and that compression really improves your overall throughput, overall bandwidth consumption, and performance, and scalability. It's a really very powerful feature.
I'm going to say 'Start this cache on the finish'. You should probably also check this box 'Auto start this cache on service startup', I'm not going to. I am going to keep the Eviction enabled. If you turn eviction off then NCache stops accepting new data when the cache is full. And, the cache is full when it reaches that size which I have specified in the previous few pages. Once the cache is full, and if the eviction is turned on, NCache actually will use an LRU policy, or algorithm to evict 5% of the cache, I could change that. I'm going to keep the 'Clean Interval' to be 15 seconds. Clean Interval is essentially a time when NCache does its expirations, evictions, and a bunch of other cleanups that it needs in the cache.
Now, I've started the cache. So, the next step is to go ahead and configure the clients. So, I had said I have two clients, so I'm going to add my Linux Client first. So, my Linux Client is 113. I'm going to come here and I'm going to quickly minimize my video. I hope to remember to un-minimize it. So, if I come into the details of this, I can come here and say client and 113 is the box that I want.
So, I've just added 113 as my client. The next thing I'm going to do is hit 'Monitor', and hit 'Statistics'. Those are the two that I need. Monitor gives me a really nice to use dashboard that gives me all sorts of different performance metrics on NCache and the system. Both NCache’s own, and also the CPU, and others. I'm going to come here and do a stress test. Currently, notice there are no clients connected to this cluster but the cluster itself is formed.
I'm going to just run a stress test for 30 seconds. This is only to test to see that the cluster is working. So, this NCache monitor part of the management center just ran a stress test program on box 114 which is also one of the servers. And, it is doing now about 3,800 requests per server. So, there are two of these boxes. So about, you know, close to 8,000 requests per second to the entire cluster but it's going to do it only for 30 seconds and then stop. But at least it'll validate that the cluster is working.
I'm going to test the cluster in a more thorough fashion. So, I'm going to go ahead and go to the sign box which is a Linux box, just confirm that this is 113 box which is the one I had added right here, and that's one of my Linux boxes. I'm going to actually run a stress test program that comes with NCache, just to make your life easier. I'm going to first, just to kind of give you an idea, what the activity is. I'm going to now bring myself back in. So, you know I'm still here, and I'm going to come here, and the stress test tool and I will just run it. You'll see that this is going to suddenly increase the request per second quite a bit, suddenly it jumped up. Both the NCache Servers are doing about the 7,000 requests per second, that's about 14,000/15,000 requests per second for the cluster from this one client. And, you know, it got a combination of additions, fetches and updates. So, it's a bunch of things. The NCache CPU also, you know, is not that high it's low.
So, I have now started an application against a two-node NCache Cluster. So, let's assume that I've somehow maxed out the capacity of these two servers, although obviously I haven't here, no nowhere near. But, let's say, I have and I wanted to add a third server at runtime. So, I'm going to demonstrate the high availability portion of NCache. So, I have a third server which is a Linux box, but I don't have NCache installed in that box. I'm going to just quickly do it through Docker in front of you. So, I'm going to come here and I'm going to just do a Docker pull. Actually, I do have this Docker image pulled already but I just want to do the pull command again just to kind of tell you that this is what you would be doing.
So, once you've done a Docker pull which doesn't take very long, the next thing I'm going to do is, I'm going to create an NCache container by the name ‘ncache’. I'm going to use a host network, and that's it. The network adapter of host mode. Now that I've done this, now I know that NCache is running. How do I know? I'm going to say "docker ps –a". I can see that this is running. But, this Docker instance, this NCache needs to be activated. If I do not activate this it's going to actually not work. So, there are two ways to activate it. One is to just do through the GUI, and I'm going to skip that I'm going to just do a command line activation. This is the same. It got your first name, last name, company name, your email, and the activation key, the trial key that you get in your email. So, just specify that, and suddenly this box is been activated. I'm going to show you a more graphical view when we do the Dev workstation.
Now that I've gotten that box activated I can go ahead and come here and try to add that as a third server. So, what was that box? The box was 116. So, I'm going to say 116. And oh, it says the cache is already registered, that means there's a cache by the name 'demoCache' already existing on that box. So, I'm going to go ahead and delete that cache first. I will quickly use this command in Docker to first verify. This is the "docker exec –it" command which basically means execute this command, this command, inside this Docker container. So, it's just a standard Docker command that anybody who uses Docker understands it very well. So, I'm on this box. So, I can see that there's already a 'demoCache' which I need to delete. So, I'm going to execute another command, which is in the same fashion "docker exec -it ncache" and then I'm going to now execute "remove-cache -name democache" as the command. I’ll copy that and verify that again and it's not there anymore. Now I can come here and add it here, oh let me just minimize this again, so you can see that now it's going to, right here, it's going to show you that cache got added, but that server is not running because I have to run it explicitly.
So, now that I'm going to do that there's something that you should see there's a third box that got added. So, I still have the same transaction load because I haven't added more transaction load, but I have now distributed that load from two servers to three. By distributing to three the load per server has just dropped to about half. So, now that shows you the capacity has just increased. So, if this was maxed out capacity which is isn't you would have just gotten almost a 50% drop in this case.
Now that you have a drop you have the ability to add more clients to this. So, I'm going to go ahead and add another client. I'm going to now add a Windows Client actually. So, now I'm going to show you that while the application is running you, I've already shown you that you can add a cache server at run time without stopping NCache or stopping your application or affecting your existing running application, now you can add another client which is your application server and now I'm going to actually add one of those Windows Server boxes, 112 which is my current box right here which is I just showed you that I was 112. This is a more likely scenario anyway because you're going to add more clients and there's a 5:1 or 6:1 ratio. So, you have to add five clients to then add one server, so the adding of the client is going to occur more frequently.
Now that I have done this you can see it's still showing one client because although I've added that in the configuration I haven't run any application on it yet. On Windows NCache provides you a PowerShell CLI. On Linux it has a native Linux based command line, but on Windows it is PowerShell. So, I'm going to come here and I'm going to now run a PowerShell thing, and now you'll see that suddenly this has become two clients. And, the traffic has started to go up again, because the load per server has increased because there's one more client. Now I have two clients talking to these three servers. So, I I've been able to add a cache server at runtime.
I've been able to add a cache client and NCache Client at runtime. Now, let me add more, let’s say, I'm going to add a second process onto the existing client. So, let's say, on the same client itself I'm going to add another process. So, I'm logged into DEMO7 again here. So, I'm going to just run another instance of the stress test tool on this Linux box. Once I do that you'll see that the load is going to increase even further. So, all of that kind of demonstrates that everything is dynamic in NCache. You can add servers at runtime, you can add NCache Clients at runtime. Of course, you can do the same, you can also stop servers, and remove servers, and stop clients, all of that. I'm not going to go through that because of the shortage of time but you should know that you can add or remove servers and the clients at runtime.
I've now tested the NCache Cluster. The next step is to setup a Dev workstation, and a Dev workstation I'm going to do a unique thing. Although, you know, most likely you either have a Windows or a macOS as your Dev workstation if you are a Java developer. Some people may even have a Linux based desktop, but most are Windows or macOS. So, you could come here and download a Windows .msi if you want, but for macOS you can either download a .tar.gz. Which is usually may or may not be your favorite way, but the best way to do this is to just do Docker. So, I'm going to actually treat this box which is not the 112 box, it's another box, it's .60, as you can see here. So, I'm going to do the same thing, I'm going to pull a Docker image of the same Java Edition. I'm going to pull a Docker image. I've already pulled it I just want to show you that you can also pull it, and it is going to only verify that it's been pulled already. Okay, it has been pulled. I'm going to then say, "docker ps -a". There's no Docker instance running.
So, I'm going to go ahead and now this time I'm going to run a different type of a Docker container. I'm not going to run a host mode container which is for the NCache Server. On the NCache Dev workstation I'm going to run just a standard container with standard networking with just port mapping. I'm going to actually just copy this here, and I'm going to forward 8251, 9800, 8300, and 8301 is the four ports and that's it.
Now that I have that the next thing I need to do is I'm going to try to access this. Now I can show you that again what happens because the this Docker container is not registered, so you can press the start a 30-Day trial, and here's the data that you can either enter through that command line that I did or enter it manually. This is the information that gets emailed to you. I'm going to again do this from the command line is because just to save some time. I'm going to just do it here. So, I'm going to say ‘docker exec’ which means in this container execute this command which is the NCache.
Actually, it's the same command, let just say, it says ‘register NCache evaluation, first name, last name, company name, email, and the key. And, the key is the one that gets sent to you. Okay. So, I'm going to hit Enter, once I do that you'll see that it says it is activated. So, now that it's activated, if I come here it will no longer say not activated. So, now I'm just going to come here and say start this.
Again do the same thing I did. I'm going to hit Monitor, I will come here and quickly do a stress test. A 30 second stress test to see if everything works and that's it. I'm done with my setting up.
Now, this is a standalone NCache that I can access locally from my application. My application being Java. Let's say, I've got a Java IDE in which I'm doing my development I want to connect to my cache locally, I can do that. And, by the way, this local cache is free. There is no licensing cost to it.
So, now that I've done all of that, I'm going to actually go to the next stage which is here. ‘Use NCache in Your Application’. Since, it's this is a video on the Java Edition I'm going to focus mainly on the Java applications. I've already mentioned, there are two ways that NCache is primarily used. One is as a distributed cache, and the second is as a messaging and streams platform. Let me go back onto that again here. So, as a distributed cache, NCache sits between the application tier and the database. And, the goal is to cache as much of the data as possible, so, you don't have to go to the database to improve your performance and scalability. Very simple, traditional caching use case.
The second big where NCache is use as a Messaging and Streams platform, where NCache becomes a messaging platform of two or more servers. You have multiple applications. These could be Web Apps, Microservices, Web APIs, or any other server applications that can communicate with each other in a totally decoupled manner in a Pub/Sub Messaging, or Continuous Query, or other Events through NCache. So, I'm going to show you that. So, if you were to come to on GitHub, there's an NCache samples repository which has samples on .NET, .NET Core, Java, Node.js, Pythons. So, I'm going to go into Java, and there are bunch of samples here, you know, to kind of really help you get started quickly with NCache. So, I'm going to show you two of these samples, the basic operations and the Pub/Sub. So, the basic operations sample is right here. It's very straightforward. There's a method called initialize cache which is to basically connect to the cache, CacheManager.getCache, and this is a cache name, that same cache name is the demo cache that you just did. Once you have a cache handle then you just do a cache.add right here, cache.get right here. cache.insert, essentially it's an add if there's no data or an update if there's data already, and then cache.remove is in there too.
There also other variations to this. But, this is to kind of give you a gist of this. And again, you know, you can very easily use NCache with Maven, with the leading IDEs. I'm using IntelliJ but you can use anything that you prefer. The other sample that I'm going to show you quickly is PubSub. In this you have a publisher that is publishing messages. They're on two different topics. One is the electronics orders, one is the garments orders. If I were to run, go into runPublisher, it just says publish message. And, publish messages essentially gets a topic based on topic name and then it uses that topic handle to start publishing messages in a decoupled fashion. So, this is the publisher. It's a separate application. Then you have subscribers. There are different types. There are durable subscriber, non-durable. You can go into the details in the docs. But again, a subscriber runs through this in the same fashion. It actually again uses the same topic name, gets a topic handle, and then it says create a durable subscription, and it provides it its message received listener. So, when messages are received on this topic, on this subscription the subscriber actually receives them. And, they could be on two different computers. They could be even between .NET and Java applications communicating to each other through this, you know, especially they can use JSON as the thing. So, that's one, and then I said there are also a bunch of others. So, for example there's Jakarta sessions, I've got it opened here. So, if you go to the Jakarta sessions sample, and you just go to this WEB-INF > web.xml you have to just enter that, and obviously specify your path here, and that's it. And, that's the only thing you have to do to an existing Java web application to start storing sessions in NCache. Very straightforward.
The next then is you've got hibernate. Hibernate is very popular in the Java ecosystem. NCache plugs in as a second level cache to hibernate. Again, you have the sample here. I'm not going to go into the detail I'm just showing you the sample.
Then you can go into the spring. So, spring again is the spring framework and the spring boot are very popular. You can go into this, NCache is available. I'm not going to go into the detail of this but all of those samples are there.
So, NCache gives you full support of Java. I hope I've demonstrated that. You can use NCache not only on Windows but also on Linux, and in Docker. Basically, in your favorite environment that you want. Well now that you've taken a look at all of this I would strongly recommend that you go ahead and try NCache yourself. There's a free 30-Day trial, fully working, that can be extended for up to six months, total of six months. That's a long time that you can play with NCache obviously.
The other thing that you can do is come to our website and just go Try Playground. Playground is something where it's a really good way to immediately get started with NCache. You don't have to install anything. Just go ahead and start playing with NCache samples. I am not going to go into this. There's a separate video on this, but you know, you can see these samples. Although these are .NET samples but there is Java samples and the other option that I didn't do because that requires another login. So, you can go ahead and you can run these samples. You can make changes and compile & run. You have hibernate samples. You have spring. You have, you know, all sorts of stuff in there. That's all for today. I hope you will go ahead and take a look at NCache and realize how powerful of caching solution it is, as an in-memory distributed store for your web applications. Thank you very much. Goodbye.