Pandurang Waghulde
Pandurang Waghulde

Reputation: 1035

Delay in processing more requests/sec

I have a JRuby application using celluloid. It receives requests through Zeromq socket and responds with JSON string.

So, There are 2 actors in my application one for processing requests and another for sending a response(Push socket in Zeromq). Application receives requests at a rate of around 30 requests/second, It would be more in future say 1000/sec. But on increasing number of requests per second, it takes more time to process. It starts to use more CPU.

For each received request, I am processing that inside defer block.

defer {
  response = ResponseHandler.new(socket,message).start
  send_response(response)
}

For 20 requests/sec, it works fine without any delay. The server has a configuration with 15Gb RAM and 4 cores. It makes a connection to Postgres DB and Redis DB as well. But that doesn't seem to be an issue here.

Here is basic structure I have, there is main actor Service,

supervisor = Service.supervise

this internally creates instances of PushSock Actor with 10 pool.

@pushsocket_actor = PushSock.pool(size: 10)

send_response method in defer block above calls pushsocket actor. In defer block ResponseHandler is not an Actor.

So with Service Actor, I am not using a pool.

Upvotes: 3

Views: 79

Answers (1)

digitalextremist
digitalextremist

Reputation: 5993

Use a pool.

Right now you are using the internal thread pool... which keeps spawning new threads. Instead, create a pool of actors, then invoke using async ... which will actually decrease the number of tasks run at once. That'll speed up response time, since it'll be doing processing at full speed and not just taking requests.

You need to be realistic about your resource requirements though! Do you know how much you need per request? You need to plan out your actor strategy based on that.

Don't use too many or too few actors. Right now, you're using too many threads I suspect, because using defer {} doesn't place limits like async would, if used with a realistically sized pool.

Upvotes: 2

Related Questions