haskell httpd

Paul Graunke ptg at acm.org
Tue Nov 4 19:37:07 EST 2003


Brian Demsky's master's thesis compares servers written in direct style
(using a thread per connection) to event driven servers (which are 
supposedly
oh so much faster.)  He shows how you can CPS the thread
per connection server and end up with the event driven server.
That way you don't need to manually mangle your code in an ad hoc way.
Of course, as Peter points out, you can build cooperative multitasking 
in
Haskell using monads rather that face the pain of using Java like 
Demsky.

If I recall correctly, the main performance advantages came from 
avoiding
   - thread creation overhead
   - excessive context switching
   - synchronization due to potential interruptions at inconvenient 
moments
I suspect Haskell threads are much lighter than Java threads, so
there may not be as large of a payoff.

I'm curious about the difficulties with the monadic cooperative threads.
(I assume Peter meant cooperative threads where a scheduler chooses the 
next
  bit-o-code to run rather than coroutines where the yielder explicitly 
calls
  some other coroutine.)  Were the asynchronous IO primitives too ugly to
deal with cleanly, or was the performance gain too small to be worth 
while?

Regards,

Paul

On Tuesday, November 4, 2003, at 02:58 PM, Peter Simons wrote:

> S Alexander Jacobson writes:
>
>> Is there a reasonably efficient Haskell httpd
>> implementation around that uses poll/select?
>
> There is a web server written in Haskell: HWS-WP
> -- or "Haskell Web Server with Plug-ins". You'll
> find it at:
>
>     http://sourceforge.net/forum/forum.php?forum_id=253134
>     http://cvs.sourceforge.net/viewcvs.py/haskell-libs/libs/hws-wp/
>
> The following paper from Simon Marlow provides a
> detailed description of the server's architecture:
>
>     Writing High-Performance Server Applications
>     in Haskell, Case Study: A Haskell Web Server
>
>     http://www.haskell.org/~simonmar/bib.html
>
> Note that HWS-WP does not use poll(2) directly.
> Instead, it relies an Haskell's forkIO function to
> spawn concurrent threads of execution. These are
> _not_ necessarily system threads, though. GHC, for
> instance, does implement IO threads with poll()
> internally. Other compilers or run-time systems
> may use other techniques.
>
> I have experimented with direct poll()-based
> scheduling in Haskell (using a CSP monad to
> implement co-routines) and honestly didn't find it
> to be worth the extra effort. Eventually, I threw
> all the code away and just used forkIO, like
> everybody else does.
>
> Peter
>
>
> P. S.: If you're interested in a poll()-based web
> server written in C++, though, let me know. I have
> some code I'm more than willing to share. The
> server speaks HTTP/1.1 and can deliver static
> pages. No dynamic content, though. But it _is_
> fast. :-)
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell



More information about the Haskell mailing list