melwin_jose
melwin_jose

Reputation: 325

libuv combines mutliple async calls and invokes callback once

Requirement : A UDP server that on receiving an UDP packet and stores the received packet to one of the two queues. A worker thread is associated with each queue, and the associated thread picks up packet from the front of the queue, processes it and writes it into a in-memory cache system.

Constraints : solution has to be based on event-loop(libuv) and written in C

My Solution

The problem The Client sends large number of packets which registers large number of events in the server. Now the problem is that libuv combines multiple calls into one and invokes a single callback(which removes a SINGLE node from queue). This leads to situation where nodes are being added to the queue at a faster rate and removed at a very slow rate. Can these rates be balanced ?

Is there a better way to design the server using event-looping library libuv ?

Upvotes: 0

Views: 784

Answers (1)

saghul
saghul

Reputation: 2010

Since you are queueing the packets in one thread but processing in another, it's possible that they work at slightly different rates. I'd use a thread-safe queue (have a look at concurrencykit.org) and process the entire queue on the async callback, instead of just processing a single packet.

Upvotes: 1

Related Questions