Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1470 (reopened enhancement)

Opened 15 years ago

Last modified 14 years ago

a special Conduit providing cooperatively blocking read and write methods using just one thread, fibers and select

Reported by: elite01 Assigned to: kris
Priority: normal Milestone: 2.0
Component: IO Version: 0.99.7 Dominik
Keywords: conduit Cc: elite01

Description

There are two ways of implementing a socket server serving multiple connections at once: One is creating a thread for each connection while the other is having one thread serving all connections.

Both methods have their advantages and disadvantages: The multithreaded approach usually performs worse but is easier to program since the program flow is linear and not event based.

Combining both approaches, one could use select in a loop and Fiber.call depending on the event - read would be implemented with a Fiber.yield then. This allows a single threaded server with a linear program flow (you can still use blocking methods). This should perform better than the multi threaded approach and be just as easy to use if not easier, since there's no need to synchronize anything.

I've attached a test case demonstrating a simple implementation and the use of it. The strace output looks like the singlethreaded approach while the server uses simple methods like readln (as opposed to events) to process input. Of course, there are lots of ways to optimize this, for example by eliminating some of the context switches.

As this is a suitable building block for most socket servers and other blocking io tasks, I propose including something similar in Tango.

Attachments

main.d (3.4 kB) - added by elite01 on 02/03/09 11:09:50.
sample implementation and usage (actually a trivial httpd)

Change History

02/03/09 11:09:50 changed by elite01

  • attachment main.d added.

sample implementation and usage (actually a trivial httpd)

03/29/09 15:05:14 changed by larsivi

  • milestone changed from 0.99.8 to 0.99.9.

11/09/09 08:52:23 changed by kris

  • status changed from new to assigned.

we're looking at providing an asynchronous layer atop the I/O, and this would be included in such a package

11/13/09 23:29:09 changed by kris

  • milestone changed from 0.99.9 to 1.0.

though, we deliberately exclude servers from Tango (cluster was recently removed too) ... so not sure what to do with this one, to be honest

11/17/09 06:21:57 changed by kris

elite01: the idea here is nice, though just won't work for Windows with its flimsy select() implementation. Also a bit tricky to support read/write timeout to any reasonable scale.

Please reopen if there are some straightforward ways to resolve these two issues (a scheduler with a timeout would be one approach, though it would likely require windows CompletionPorts? in order to scale)

11/17/09 06:22:13 changed by kris

  • status changed from assigned to closed.
  • resolution set to wontfix.

11/17/09 18:34:07 changed by kris

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 1.0 to 2.0.

01/12/10 09:54:08 changed by kris

  • cc set to elite01.