The easiest / fastest way to implement a counter across multiple JVM nodes

Consider the problem:

I have n Tomcat nodes with a web application serving some content without attack. For example, 1000 applications of the first request must answer “a”, for the next 10000 with “b”, and for the rest with “c”.

First, I looked at messaging: the application receives the total number of samples from some storage → if it is less than n, then serve the content “a” → after the content is served, the application sends a message → the message receives consumption → the total number of serviced ones increases by some memory → ... However, in this case, there is a rather high chance of overshoot due to a small (or a huge delay in peeping time) delay between the service message and the counter increase ilische.

Then I decided to configure memcached-session-manager to store the counters as a shared session. But it looks pretty hard for my simple case.

Can someone please ask if there is an easy way how multiple JVM instances can communicate with each other (which is applicable for my case)?

+4
source share
3 answers

If this is absolutely true and you do not want a delay, I think your best options are Redis or Hazlecast . In particular, Redis, since it has a number of atoms, like an operation . Although it is theoretically possible to do the same with memcache, Redis is kind of designed for this particular use case (statistics counters).

db, H2, Postgres unlogged -, , - . , upsert aka MERGE .

+1

tomcat. tomcat, , tomcat.

, - , , , , . , .

, , 1000 , , IP- DNS- .

. , . " " node.

, , . , , Paxos, , "" .

. , , . , , , ; , - , , . , , , , . .

--- ---

, , N , N .

  • 1 N, , count % N == 0
  • 2 N, , count % N == 1
  • ...
  • N-1 N, , count % N = N-2
  • N N, , count % N = N-1

, - , , , , :

  • ,

+1

, , :

0

All Articles