From: Goswin von Brederlow <goswin-v-b@web.de>
To: Romain Beauxis <toots@rastageeks.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Smart ways to implement worker threads
Date: Fri, 16 Jul 2010 05:52:53 +0200 [thread overview]
Message-ID: <87lj9cw0a2.fsf@frosties.localdomain> (raw)
In-Reply-To: <201007151344.12726.toots@rastageeks.org> (Romain Beauxis's message of "Thu, 15 Jul 2010 13:44:12 -0500")
Romain Beauxis <toots@rastageeks.org> writes:
> Le jeudi 15 juillet 2010 12:46:53, Goswin von Brederlow a écrit :
>> I don't see where that helps at all. I don't want to offload the IO into
>> threads and schedule them and Duppy seems to only handle IO tasks.
>
> I don't understand what you mean by IO tasks. Tasks in duppy are scheduled
> according to some events which, since it is select-based, are either an event
> on a socket or a timeout.
But I don't have a socket. The main thread runs and at some point it has
a Buffer.t that it needs to have checksummed. So that leaves timeout.
> Once scheduled, the action that the task does is anything you programmed. Once
> finished, the tasks can return an array of new tasks which are then put in the
> queue.
>
> In your case, you probably only need the timeout event, which would mean that
> as soon as you have a new tasks to perform, you submit it to the scheduler
> with timeout 0 and it will be processed by one of the threads as soon as
> possible..
So the code would be something like this?
let with_checksum buf sum _ =
reply_request ();
[]
let do_checksum buf _ =
let sum = ...
in
{ priority = 0; events = [`Delay 0.]; handler = with_checksum buf sum; }
let main_task events =
let rec loop tasks = function
[] -> tasks
| (`Read fd)::events ->
let buf = parse_request fd in
let task1 = { priority = 1; events = [`Delay 0.]; handler = do_checksum buf; } in
let task2 = { priority = 0; events = [`Read fd]; handler = main_task; }
in
loop (task1::task2::tasks) events
in
loop events
let main () =
let scheduler = Duppy.create ()
in
for i = 1 to num_cores do
Thread.create (Duppy.queue ~priorities=(fun x -> x = 1) scheduler "worker") ();
done;
Duppy.Task.add scheduler
{ priority = 0; events = [`Read server_socket]; handler = main_task; }
Duppy.queue ~priorities=(fun x -> x = 0) scheduler "main") ();
The main task will only process priority 0 events and bounce between
main_task and with_checksum while the worker threads process priority 1
events and do_checksum.
Correct?
>> Except if I pick Solution 1 and then it still doesn't help anything
>> since I can already run select in every thread. The IO should not be
>> scheduled by priorities and isn't the bottleneck anyway. Seems this
>> would just add overhead.
>
> The idea of duppy was to have only one select running among the multiple queue
> threads.
>
>
> Romain
MfG
Goswin
next prev parent reply other threads:[~2010-07-16 3:52 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-14 16:09 Goswin von Brederlow
2010-07-15 15:58 ` [Caml-list] " Rich Neswold
2010-07-15 16:19 ` David McClain
2010-07-15 17:16 ` Ashish Agarwal
2010-07-15 18:24 ` Goswin von Brederlow
2010-07-15 18:37 ` David McClain
2010-07-15 18:40 ` David McClain
2010-07-15 19:56 ` Rich Neswold
2010-07-16 4:02 ` Goswin von Brederlow
2010-07-16 4:23 ` Rich Neswold
2010-07-16 13:02 ` Goswin von Brederlow
2010-07-16 14:40 ` Dawid Toton
2010-07-16 16:18 ` [Caml-list] " Rich Neswold
2010-07-17 17:53 ` Eray Ozkural
2010-07-20 4:54 ` Satoshi Ogasawara
2010-07-17 18:34 ` Eray Ozkural
2010-07-17 19:35 ` Goswin von Brederlow
2010-07-17 22:00 ` Eray Ozkural
2010-07-15 16:32 ` Romain Beauxis
2010-07-15 17:46 ` Goswin von Brederlow
2010-07-15 18:44 ` Romain Beauxis
2010-07-16 3:52 ` Goswin von Brederlow [this message]
2010-07-16 4:19 ` Romain Beauxis
2010-07-16 13:05 ` Goswin von Brederlow
2010-07-16 13:20 ` Romain Beauxis
2010-07-17 9:07 ` Goswin von Brederlow
2010-07-17 13:51 ` Romain Beauxis
2010-07-17 14:08 ` Goswin von Brederlow
2010-07-17 9:52 ` Goswin von Brederlow
2010-07-17 14:20 ` Romain Beauxis
2010-07-17 15:52 ` Goswin von Brederlow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lj9cw0a2.fsf@frosties.localdomain \
--to=goswin-v-b@web.de \
--cc=caml-list@yquem.inria.fr \
--cc=toots@rastageeks.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox