Maximus
Maximus

Reputation: 559

Clustered Jboss servers - Maintaining a unique count

We have a web service receiving requests at a very high frequency. The application is deployed on two jboss servers in a cluster (for load balancing)

We process the requests and determine some requests as "good requests". Now we want to treat certain percentage of the "good requests" specially(send downstream to another system).This percentage value is configurable. For example if the percentage is 75%, for every 4 "good requests" we receive, 3 of them has to treated specially(sent downstream) and the 4th one must be ignored.

I do not want to add the process of determining if the "good request" has to be sent downstream as part of the existing system. Since that will slow down the processing time.


Here is the solution I thought for this problem.

Count - is the count of requests received by the downstream module


There are couple of problems that I foresee with the above approach, since the application is deployed in two servers.

  1. The count is not going to be unique for the two servers, each "downstream module" will have its own count.
  2. Since count is not unique, it is possible that we are not sending the configured percentage. For example if the percentage is 75% and if we receive 6 requests. It is possible 3 went to server1 and 3 went to server2. The count in each "downstream module" will be 3. So we would not have effectively sent even 1 "good request" to the downstream system, which is not desirable.

I thought I would maintain a table in the database that will insert "good requests" and generate a unique number(Good_request_count) for that, and use the Good_request_count in each "downstream module" make a decision of whether it has to be treated specially or not.


But I am afraid my solution is very inefficient, since it would involve the following

  1. Having two JMS queues in (one for each jboss)
  2. Have two "Downstream module" in each server to determine if the good request has to be sent downstream.
  3. Each downstream module has to insert some key value in "good request" and read a unique count value from the database.

The underlying problem is, I have two servers and I want a unique count across both.

Can anyone please suggest me a better solution or point me inefficiencies in the system that can be improved.

Please let me know if I am not clear in any part, I can explain that.

Thanks a ton for reading !

Upvotes: 1

Views: 428

Answers (1)

Asynkronos
Asynkronos

Reputation: 195

Here are two other strategies to consider:

  1. Create a MBean containing the code that keeps count and deploy it in your deploy-hasingleton directory on each server in your cluster. You can refer to the MBean via JNDI lookup, and are guaranteed only a single instance of it will be accesible across the cluster.

  2. If you are using a more recent version of JBoss, you have the option of using a singleton session EJB to keep track of the count.

Upvotes: 2

Related Questions