caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <gerd@gerd-stolpmann.de>
To: Serge Sivkov <ssp.mryau@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] netplex multi-thread asynchronous processor for passive clients
Date: Fri, 03 Apr 2009 17:51:37 +0200	[thread overview]
Message-ID: <1238773897.9723.6.camel@flake.lan.gerd-stolpmann.de> (raw)
In-Reply-To: <c6c39ebb0904030419x1de72ccnf58dbb59bb610bf6@mail.gmail.com>


Am Freitag, den 03.04.2009, 17:19 +0600 schrieb Serge Sivkov:
> Hello,
> I want to convert my synchronious multi process netplex service to
> asynchronous multi thread one.
> I don't understood how can i send data from #receive_message
> to #process for asynchronous worker (ideally more than one per thread).
> 
> Here is my current code :
> class my_hooks =
>   ...
>   method receive_admin_message container name args =
>     let s = "admin message to contaner: " ^ name in
>     container#log `Info s;
>     let aux (proto,fds) =
>       Array.iter
>         (fun fd ->
>         container#socket_service#processor#process (fun () -> ())
> container fd proto)
>         fds in
>     List.iter aux container#socket_service#sockets
> 
> end
> 
> class ts_alfa_processor hooks : Netplex_types.processor =
>   ...
>   method process ~when_done container fd proto_name =
>     let s =
>       sprintf "process called with %d and %s" (int_of_file_descr fd)
>         proto_name in
>     container#log `Info s;
>     let ch = Unix.out_channel_of_descr fd in
>     let rec aux () =
>       let s = (Sexp.to_string (sexp_of_msg dfl_msg)) ^ "\n" in
>       output_string ch s;
>       flush ch in (*+aux() for synchronious version *)
>     aux ()
> 
> method supported_ptypes = [ `Multi_processing; `Multi_threading ]
> end
> 
> That code doesn't work because method process called from
> receive_admin_message got wrong fd as argument (i assume, that's
> parent fd used to accept right one).

No, that does not work. process must be called from the right
environment.

> What is the right way to write porcessor which must:
>  - work asyncroniously with multithread workload manager
>    (ideally, many jobs per thread)
>  - work with clients whom don't send any packets
> - get data to send from messages sent by other service

e.g. open a Unix domain socket, and send data over that socket. Right
now, there is no faster way that is officially supported. For
convenience, you can define RPC procedures that do all the serialization
details.

What could work if sender and receiver are on the same event system: The
sender puts a special event with the message onto the event queue, and
the receiver installs an event handler listening for such events. I
don't have demo code for something like this, however.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------



  reply	other threads:[~2009-04-03 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-03 11:19 Serge Sivkov
2009-04-03 15:51 ` Gerd Stolpmann [this message]
2009-04-03 17:55   ` [Caml-list] " Serge Sivkov
2009-04-03 18:13     ` Jake Donham
2009-04-04 14:24     ` Serge Sivkov
2009-04-05 16:27       ` Serge Sivkov

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=1238773897.9723.6.camel@flake.lan.gerd-stolpmann.de \
    --to=gerd@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=ssp.mryau@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).