Optimal multithread model

Marc Lehmann schmorp at schmorp.de
Wed Mar 17 13:37:07 CET 2010


On Wed, Mar 17, 2010 at 12:19:23PM +0100, Gabriel Kerneis <kerneis at pps.jussieu.fr> wrote:
> You can find the results here:
> http://hal.archives-ouvertes.fr/hal-00434374/fr/

That's quite fascinating - I have yet to understand what an additional
userspace accept queue (thttpd) has as an effect (i.e. how to decide when
to not dequeue).

The fact that CPC is actually working (i.e. providing working wbe servers
as output) is also quite cool.

But I am also shocked: "a cursory examination of ST's sources indicates
that it uses some rather clever data structures (e.g. heaps for storing
timeouts)".

I am looking for alternatives and improvements (and will implement some
in one of the next releases) to (binary) heaps in libev, and it is a bit
shokcing ot read that this is a clever data structure - I always thought
of it as being the lower acceptable minimum...

(Of course, as outlines in the libev manual, for any important special
cases, simpler and faster data structures exist).

As a side note, however:

   Thus, event-driven program- ming avoids the localised cost associated
   to thread contexts, but pays a price that is spread throughout the
   program and hence dicult to quantify.

That is true for threads, too - C doesn't have registers, so it has to
store verything "in memory" as well (modulo compiler optimisations).  In
fact, you will not find a threaded webserver that doesn't have a "struct
connection" type data structure with metadata, simply because local
variables and registers don't get passed to functions.

So as soon as you use functions, you have the same issue with threads.

Of course, the relative costs are likely smaller with threads, but it is
strictly wrong to claim that it only exists for event-based programs (in
fact, the costs might even be negative).

> (Disclaimer: if I had to redo this study, I would probably do it
> differently.  But I moved to something else and do not have time anymore
> to spend on this.)

It's still giving me great input, and made me plan to look at those clever
optimisations inside ST - there is almost always something to learn in
good software.

Thanks for making the effort and sharing it!

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the libev mailing list