Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #10902

Re: FastCGI-like stuff and Forth

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.forth
Subject Re: FastCGI-like stuff and Forth
References (2 earlier) <jlfk2d$160$1@online.de> <7x398ky33l.fsf@ruckus.brouhaha.com> <jlfmv1$3gp$1@online.de> <7xvclfdfag.fsf@ruckus.brouhaha.com> <jZWdnZSDNON6uuHSnZ2dnUVZ_oydnZ2d@supernews.com>
Date 2012-04-05 00:03 -0700
Message-ID <7x4nsywth7.fsf@ruckus.brouhaha.com> (permalink)
Organization Nightsong/Fort GNOX

Show all headers | View raw


Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>> TCP connections, you have a separate socket for each one, and listen
>> to them all simultaneously with something like epoll.
> That is absolutely the opposite of the Forth way of doing it!  Have
> lots of simple tasks, one per I/O device.

Are we talking about the same thing?  There's only one physical I/O
device in this picture, the ethernet card, which is carrying a lot of
multiplexed TCP connections to various remote endpoints.  The Unix TCP
stack splits the connections out into logical "devices" i.e. sockets.

The notion here is to have a separate task per socket, but how to do
that?  One way is multiple Unix processes or pthreads, but these are
quite expensive and pthreads introduce the usual locking hazards.
Another way is use Forth's cooperative multitasking and very
lightweight tasks running in a single Unix thread, with some mechanism
dealing out the different incoming connections to the different Forth
tasks.  For example, have one task listening to all the sockets with
epoll as above.  Whenever there's activity on any socket, the
listening task wakes up the task dedicated to handling that particular
socket, which handles the packet and then goes back to sleep (the
client interface looks like a blocking read, but is actually a library
call doing an async read and a PAUSE if there's no data).  This is how
Erlang and GHC work and they outperform pthreads by orders of
magnitude.  It's certainly how I'd hope for any seriously concurrent
Forth web server to work.

Yet another way is with callbacks or state machines in a single logical
thread with asynchronous i/o, favored by some.  You get high performance
but IMHO cumbersome, control-inverted code.  For a more flamey take you
can google "node.js is cancer" ;-).

See also the old but still relevant "C10k problem" article:
http://www.kegel.com/c10k.html

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

FastCGI-like stuff and Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-03 13:28 +0000
  Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-03 11:44 -0700
    Re: FastCGI-like stuff and Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-04-03 21:46 +0200
      Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-03 13:25 -0700
        Re: FastCGI-like stuff and Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-04-03 22:35 +0200
          Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-04 02:20 -0700
            Re: FastCGI-like stuff and Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-04-04 05:52 -0500
              Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-05 00:03 -0700
                Re: FastCGI-like stuff and Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-04-05 03:03 -0500
                Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-05 10:42 -0700
                Re: FastCGI-like stuff and Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-04-06 06:30 -0500
                Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-07 01:44 -0700
                Re: FastCGI-like stuff and Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-04-07 19:04 -0500
                Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-07 17:40 -0700
        Re: FastCGI-like stuff and Forth quiet_lad <gavcomedy@gmail.com> - 2012-04-05 13:37 -0700
    Re: FastCGI-like stuff and Forth Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-04-04 13:20 +0000
      Re: FastCGI-like stuff and Forth Paul Rubin <no.email@nospam.invalid> - 2012-04-04 11:20 -0700
    Re: FastCGI-like stuff and Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-04 13:42 +0000
  Re: FastCGI-like stuff and Forth Spam@ControlQ.com - 2012-04-04 17:00 -0400
  Re: FastCGI-like stuff and Forth quiet_lad <gavcomedy@gmail.com> - 2012-04-05 13:36 -0700
  Re: FastCGI-like stuff and Forth quiet_lad <gavcomedy@gmail.com> - 2012-04-13 23:10 -0700

csiph-web