Re: Waking up a network server: 2 threads + semaphore vs 1 thread + pipe
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com On Feb 14, 2009, at 12:16 AM, Joel Reymont <joelr1@gmail.com> wrote: Which is the best design and how efficient? 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/tlambert%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Please do not crosspost, especially to subscription-required-to-reply lists. You've actually said almost nothing about your problem space, other than implying that the packets are network MTU sized or smaller by discounting UDP vs. TCP and therefore packet reassembly after fragmentation doesn't come into play.. 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. 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? This email sent to tlambert@apple.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Terry Lambert