PWS headless - Lack of Responsiveless and Double Submits

Stephen Pair spair at advantive.com
Thu Aug 26 01:43:38 UTC 1999


> Can someone please explain what is happening in this PWS
> loopOnPort:loggingTo: method and how it interacts with the Squeak
> "simulated" processes...

The loop method is looping indefinitely, calling
ConnectionQueue>>getConnectionOrNil, which, if there are no connections
pending, will return immediately with a nil.  Hence, taking out a delay in
that loop will chew up the CPU.  Unfortunately, having the delay can
introduce an unnecessary lag time in picking up connections.

A better solution would probably be to use a SharedQueue for stacking up
connections and use #next to retrieve connections (I could have sworn that
this was what ConnectionQueue was doing, but apparently not).  The #next
would pause the PWS loop until a connection is placed into the queue.

Underneath all of this is the socket implementation which many have
indicated also has a polling scheme.  I looked into that a little further
and discovered that's not completely true.  Events such as socket-connect,
data-send-complete, data-available, and disconnect can be waited on via a
set of #waitXXX methods in Socket.  At a glance, these look to poll on
primitives that tell whether or not these events have occurred.  However,
they actually do wait on a semaphore associated with the socket, which is
signaled when any of these events has occurred.  Also, the primitives are
simply looking at state data in memory (at least on the Win32 platform) and
not making an OS call (so they're pretty fast).  One solution would be to
use a separate Semaphore for each event, but perhaps there would be some
issue with having a large number of externally registered Semaphores.

The more serious issue (at least on Win32) is that two OS threads are
created for each socket.  It doesn't take a lot of simultaneous hits before
you start running into thread allocation problems (not to mention that
creating those threads is likely not the speediest things in the world to
do).

- Stephen





More information about the Squeak-dev mailing list