[Seaside] Serving files

David T. Lewis lewis at mail.msen.com
Thu Oct 12 02:29:27 UTC 2006


On Wed, Oct 11, 2006 at 01:15:37PM -0400, David Shaffer wrote:
> tim Rowledge wrote:
> >
> >On 11-Oct-06, at 5:10 AM, David Shaffer wrote:
> >
> >Assuming I understand 'tread safe' in same way that you mean it, that 
> >isn't strictly correct. The problem is that the squeak model use 
> >separate positioning and read/writing calls. Thus is is quite possible 
> >(been there....) to have two processes referring to the same file and get
> >procA -> position: a
> >procB -> position: b
> >procA -> read from position (which I thought was a!)
> >boom.
> >
> I thought my meaning was the obvious one but now that I hear yours I'd 
> agree that I was wrong.  So...(let's hope the second try is a charm)
> 
>    Just a point of clarification: file I/O on a single Stream is not
>    thread safe but Kom uses separate streams for each request so this
>    has nothing to do with why Squeak makes a poor web server for
>    serving static files.  The problem with it is that the Squeak VM
>    uses blocking I/O calls for file I/O (not for socket I/O!).  So is
>    quite possible that the OS will block all processes in the Squeak
>    image while reading or writing a file.  This can be a problem when
>    serving large files.  If you're serious about serving files from
>    Squeak you could use a modified ModFile which uses Async-I/O under
>    platforms that support it.  I posted a first attempt at a version of
>    this to the Squeak Wiki but it required a modified VM.  I think that
>    it could be done without modifying the VM though.  Anyway the
>    correct solution is, of course, making Squeak's underlying file I/O
>    asychronous just as the socket I/O already is.

I don't think that blocking IO has anything to do with why Squeak
does or does not make a good web server, and it's only incidentally
related to the process/thread model in Squeak. But for what it's
worth:

To set a file stream for non-blocking reads, the required
primitives are in OSProcessPlugin (distributed with Unix VMs, or
roll your own for Windows), and used in OSProcess (Squeak Map).
See e.g. OSProcessAccessor>>setNonBlocking:. This is applicable
to OS pipes and other file-like external resources, as well as
to conventional files.

For "file event callbacks" (to borrow the tcl/tk terminology), you
can use AIO plugin on unix systems, which provides hooks into the
event-driven aio functions in the Unix VM. See AioEventHandler in
OSProcess. This uses aio callbacks along with file streams set in
non-blocking mode (the standard Squeak sockets and async files
work similarly). As long as you use non-blocking input, the Squeak
VM will not hang on input IO operations, and the aio callbacks will
signal Squeak semaphores to provide the asynchronous callbacks.

None of this has anything to do with the process or threading model
of Squeak, other than the fact that if you don't set non-blocking
behavior on files (and sockets), you will lock up the VM on certain
read operations.

Dave



More information about the Seaside mailing list