ptntialunrlsd
ptntialunrlsd

Reputation: 794

Shared queues VS Actor Model

In my J2EE web app, I have to send a count for every Web API call to an isolated thread for counting the number of calls. Possibilities include:

a) Use an atomic long. I think that would cause contention in case I have millions of calls in a minute. As, all the threads will try to update a single variable.

b) Use a shared queue. Every request processing thread will insert into the queue, and the dedicated counter thread will dequeue from that queue and increment the count.

c) Use actor model, say using Akka library. Send an asynchronous message to the actor, and that will add it up to the count.

My question is how does method (b) compare to (c). What are the pros and cons, and how they are different at low level?

Upvotes: 1

Views: 811

Answers (1)

Radioguy
Radioguy

Reputation: 23

In your case I believe Actor model should be a better option. Pros with Akka-

  • Actor Model with Akka will take care of the thread management and it is easy to implement
  • Further, in future if you want to implement counter for different kind of request, you can simply add a new actor for that.

There is a similar question at- When to use actors instead of messaging solutions such as WebSphere MQ or Tibco Rendezvous?

Upvotes: 1

Related Questions