Reputation: 1325
I have 15 web apps deployed in the same tomcat instance.More or less the same application but tailored for different affiliates.I have 2 production tomcat instances in two seperate machines. Anyway, I 'd like to use hazelcast as a clustered memory grid.What is the best way to do it?
I don't want to go peer to peer and start 15 instances of hazelcast per tomcat.In total it will make 30 instances.Worried about memory overhead and hardship to manage.(Or is this the correct thing to do?)
Other option is,to place the hazelcast jar file under tomcat/lin folder and add a contextStartListener event to my webapps which will start hazelcast instance on startup.But this means it will check and if not created,create a hazelcast instance.This check will be done for all 15 web apps.This also doesn't look like an optimal solution to me.It might introduce concurrency issues,what if multiple apps start at the same time?
Hence the question again:What is the optimal way to do it?
Upvotes: 0
Views: 1496
Reputation: 10633
Hazelcast
is in memory data grid (IMDG), that acts as a distributed storage for datastructures. In a way it's a database. You don't need to start one instance per application, one would suffice. That said, to make it fault tolerant you may cluster multiple nodes together.
For example in your two server setup you can utilize bot the servers to start one instance of Hazelcast and use them in a single cluster. A cluster is the list of the member nodes that are defined in hazelcast.xml
as below
<member-list>
<member>127.0.0.1</member>
<member>127.0.0.2</member>
</member-list>
If you're running Hazelcast programatically using Hazelcast.newInstance
this file (hazelcast.xml) would have to be on classpath. Other simpler way is to use start.bat or start.sh
under bin
directory of hazelcast download and modify the xml file there.
If you run Hazelcast.newInstance
or start.sh
more than once on the same machine it will create as many processes for hazelcast acting as different members clustered together. This is only for experiments and not for production.
To create client use Hazelcast.newHazelcastClient
by keeping hazelcast-client.xml
on class path. This xml file will need the member addresses as configured for the servers in the hazelcast.xml
.
<cluster-members>
<address>127.0.0.1</address>
<address>127.0.0.2</address>
</cluster-members>
Here's a full client XML file from Hazelcast https://github.com/hazelcast/hazelcast/blob/master/hazelcast-client/src/main/resources/hazelcast-client-full.xml
To create the client follow steps here
Note: Client would be created per application, just like you would create database Connection
instance per application. Server would be run independently from the applications.
Upvotes: 2
Reputation: 6094
The optimal way would be to have a standalone (separate) Hazelcast cluster for storing and your applications (webapps) use Hazelcast clients to proxy to the cluster.
Upvotes: 2