From: John Gardiner Myers <jgmyers@netscape.com>
To: linux-kernel@vger.kernel.org
Subject: Re: Linux's implementation of poll() not scalable?
Date: Fri, 27 Oct 2000 17:46:25 -0700 [thread overview]
Message-ID: <39FA21E1.A9229CAE@netscape.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2735 bytes --]
Linus Torvolds wrote:
> So sticky arrays of events are good, while queues are bad. Let's take that
> as one of the fundamentals.
Please let's not. There is nothing fundamentally different between an
event queue of size N and an interest set of size N.
Your proposed interface suffers from most of the same problems as the
other Unix event interfaces I've seen. Key among the problems are
inherent race conditions when the interface is used by multithreaded
applications.
The "stickiness" of the event binding can cause race conditions where
two threads simultaneously attempt to handle the same event. For
example, consider a socket becomes writeable, delivering a writable
event to one of the multiple threads calling get_events(). While the
callback for that event is running, it writes to the socket, causing the
socket to become non-writable and then writeable again. That in turn
can cause another writable event to be delivered to some other thread.
In the async I/O library I work with, this problem is addressed by
having delivery of the event atomically remove the binding. If the
event needs to be bound after the callback is finished, then it is the
responsibility for the callback to rebind the event. Typically, a
server implements a command/response protocol, where the read callback
reads a command, writes the response, and repeats. It is quite likely
that after the read callback completes, the connection is interested in
a write event, not another read event.
Cancellation of event bindings is another area prone to race
conditions. A thread canceling an event binding frequently needs to
know whether or not that event has been delivered to some other thread.
If it has, the canceling thread has to synchronize with the other thread
before destroying any resources associated with the event.
Multiple event queues are needed by libraries as different libraries can
have different thread pools. The threads in those different pools can
have different characteristics, such as stack size, priority, CPU
affinity, signal state, etc.
There are three performance issues that need to be addressed by the
implementation of get_events(). One is that events preferably be given
to threads that are the same CPU as bound the event. That allows the
event's context to remain in the CPU's cache.
Two is that of threads on a given CPU, events should wake threads in
LIFO order. This allows excess worker threads to be paged out.
Three is that the event queue should limit the number of worker threads
contending with each other for CPU. If an event is triggered while
there are enough worker threads in runnable state, it is better to wait
for one of those threads to block before delivering the event.
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 2147 bytes --]
next reply other threads:[~2000-10-28 0:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-10-28 0:46 John Gardiner Myers [this message]
[not found] <39F529CC.2538300@alumni.caltech.edu>
2000-10-30 22:22 ` Linux's implementation of poll() not scalable? Mike Jagdis
2000-11-01 16:09 ` Dan Kegel
[not found] <local.mail.linux-kernel/39F8D09B.F55AD0FD@alumni.caltech.edu>
[not found] ` <local.mail.linux-kernel/Pine.LNX.4.10.10010260936330.2460-100000@penguin.transmeta.com>
2000-10-27 1:35 ` Jonathan Lemon
[not found] <Pine.LNX.4.10.10010241121340.1704-100000@penguin.transmeta.com>
[not found] ` <39F61766.FC5D2D81@alumni.caltech.edu>
[not found] ` <39F6A412.DE378865@idb.hist.no>
[not found] ` <39F7054C.72FB3EA8@alumni.caltech.edu>
[not found] ` <m1aebs9i74.fsf@frodo.biederman.org>
2000-10-26 16:20 ` Dan Kegel
2000-10-26 16:44 ` Linus Torvalds
2000-10-26 19:51 ` Jim Gettys
2000-10-26 21:48 ` Dan Kegel
2000-10-27 13:56 ` Chris Swiedler
2000-10-27 0:47 ` Dan Kegel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39FA21E1.A9229CAE@netscape.com \
--to=jgmyers@netscape.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox