Waking up a network server: 2 threads + semaphore vs 1 thread + pipe
Waking up a network server: 2 threads + semaphore vs 1 thread + pipe
- Subject: Waking up a network server: 2 threads + semaphore vs 1 thread + pipe
- From: Joel Reymont <email@hidden>
- Date: Sat, 14 Feb 2009 08:16:11 +0000
Suppose I'm trying to create a very efficient network server. I define
efficiency as low latency and low CPU usage. The server is to run on
the iPhone.
The server will use one ring buffer each for sending and receiving
data. I don't think it matters whether it's TCP or UDP for the purpose
of this discussion.
A producer is pumping out packets at high speed and there a main GUI
thread with a run loop.
One design would involve adding a CFSocket per connection to the run
loop and using a separate thread and a semaphore to notify the network
server that there's data to be broadcast to clients.
I'm not sure if each CFSocket creates a separate thread or there's a
thread managing all of them together. Not sure if it matters. There
are at least two threads in this design and separate threads for
network sending and receiving.
Another design could use a pipe to wake up the network server and add
it to the list of native sockets monitored by the server. This design
could use either select or kqueue/kevent and may not need CFSocket.
Sending and receiving here would run in a single thread since the pipe
is just another descriptor to be monitored.
Which is the best design and how efficient?
How efficient is it to put a byte into a pipe in a callback that gets
triggered every few milliseconds? Would there be a significant gain
since an extra thread is not required to wait on a semaphore? Would it
even out since (intuitively) a pipe is slower?
Thanks in advance, Joel
---
http://tinyco.de
--- Mac & iPhone
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden