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


Groups > comp.programming > #2149 > unrolled thread

server

Started bybob <bob@coolfone.comze.com>
First post2012-09-04 14:04 -0700
Last post2012-09-04 23:25 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.programming


Contents

  server bob <bob@coolfone.comze.com> - 2012-09-04 14:04 -0700
    Re: server "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-09-04 23:48 +0200
    Re: server Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-04 15:39 -0700
    Re: server Willem <willem@turtle.stack.nl> - 2012-09-04 23:25 +0000

#2149 — server

Frombob <bob@coolfone.comze.com>
Date2012-09-04 14:04 -0700
Subjectserver
Message-ID<ded7ddda-f73a-4277-a20a-524923f145f8@googlegroups.com>
There are two main ways I can see to make a server that serves multiple users simultaneously.

One is to use threads.

The other is to use non-blocking sockets.  

Has anyone actually used the latter approach in practice or do they pretty much always use multiple threads?

[toc] | [next] | [standalone]


#2150

From"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Date2012-09-04 23:48 +0200
Message-ID<1on221yplcz1l$.19rq3vngv2jqs.dlg@40tude.net>
In reply to#2149
On Tue, 4 Sep 2012 14:04:28 -0700 (PDT), bob wrote:

> There are two main ways I can see to make a server that serves multiple
> users simultaneously.
> 
> One is to use threads.
> 
> The other is to use non-blocking sockets.  
> 
> Has anyone actually used the latter approach in practice or do they pretty
> much always use multiple threads?

Yep. If you have many thousands connections to handle, you would not use
threads for that because switching threads will eat all performance and
because the OS limit on the number of threads is much lower (hundreds or so
under Windows) than the limit put on sockets.

We are using this approach (socket select) for a metering system server.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

[toc] | [prev] | [next] | [standalone]


#2151

FromDaniel Pitts <newsgroup.nospam@virtualinfinity.net>
Date2012-09-04 15:39 -0700
Message-ID<Zqv1s.6975$EJ7.1884@newsfe10.iad>
In reply to#2149
On 9/4/12 2:04 PM, bob wrote:
> There are two main ways I can see to make a server that serves multiple users simultaneously.
>
> One is to use threads.
>
> The other is to use non-blocking sockets.
>
> Has anyone actually used the latter approach in practice or do they pretty much always use multiple threads?
>
I believe Varnish and Node.js are both examples of software implemented 
using the latter approach, but that's only what I've heard.

[toc] | [prev] | [next] | [standalone]


#2152

FromWillem <willem@turtle.stack.nl>
Date2012-09-04 23:25 +0000
Message-ID<slrnk4d3fa.2hg5.willem@turtle.stack.nl>
In reply to#2149
bob wrote:
) There are two main ways I can see to make a server that serves multiple users simultaneously.
)
) One is to use threads.
)
) The other is to use non-blocking sockets.  
)
) Has anyone actually used the latter approach in practice or do they pretty much always use multiple threads?

Not using threads avoids a lot of concurrency issues, race conditions and
whatnot, making programming a lot simpler.  All one has to worry about is
to handle any single request in a short amount of time, to keep the latency
acceptable.

Most MUDs that I know of are single-threaded, and use 'select' calls and
non-blocking sockets to service multiple users.  There are usually tens to
hundreds of connections to a MUD, back when they were quite popular.

Basically, as long as you avoid blocking calls, you don't need threads.
A hybrid approach is to use a single thread that services all the
non-blocking sockets, which hands off long-running or blocking tasks
to worker threads.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web