sub milisec socket server write
rneeraj at yahoo.com
Mon Feb 15 02:25:10 CET 2010
We are trying to write a high performance socket server. multiple threads may
be writing to a queue associated with the socket and single thread writes
out the data on the socket. The same thread also reads data from the socket. We are using non-block IO.
The queue is drained in idle event and written out. If all data cannot be
written out due to channel fill, it spills over to next idle event.
There is a trade off between latency and cpu usage. If we sleep 1ms after each queue drain, cpu usage is almost nil on no activity, but latency is ~1ms.
If sleep is omitted, the cpu usage is 100% crowding out other procs on same box.
Q1. is this the best way to do this ?
Q2. we tried registering for EV_WRITE but had same issue.
Q3. ev_async seems to something that might help - each write to queue can
call ev_async to wake the loop. However, before we knew about ev_async,
we had attempted similar solution (write to pipe and register ev_READ on
the pipe. This sometimes ran into deadlock when pipe was full. I think
pipes are 4K by default and we probably went over it.
Does the ev_async already take care of pipe full ?
Please let me know you thoughts and any better solution .
arguments are a "win win" situations. Each party goes away thinking they won.
More information about the libev