Driving a thread pool from libev

echo fatmck at 163.com
Sat Feb 14 12:05:31 CET 2015


read/write a pipe is slow, but read/write circle-buffer is fast because 
its pure user space code and lockless.
memcpy() can be avoid by write the pointer into circle-buffer instead of 
write the data itself.
if you care about malloc() cost, you can use pre-allocated memory which 
are allocated during initialization.
But in my opinion, the work in thread usually cost much more cpu time 
than read/write/malloc. It's not worth paying time on read/write/malloc 
when you using multi-threading. In another word, if the work in thread 
is not heavy or blocking, I prefer do the work in main thread. Because 
"multi-threading" means more complicated development and more bug which 
is diffcult to debug, I hate this...

在 2015年02月14日 17:47, Rick van Rein 写道:
> Hi Echo,
>
>> 3) When main thread got a new request, it find an idle worker and write the request data to the worker's circle-buffer and notify the worker's ev_async.
> This is what I’m hoping to avoid — slowing down the master with the read() of the available data, and causing a need for an extra memcpy() in the worker threads.  This may only work with a modification of libev, and I thought it would be useful to drive that discussion.
>
>> My English is not very good, hope this helpful.
> To me, you make a lot of sense :)
>
> Thanks for your response!
>
>   -Rick





More information about the libev mailing list