Re: NetHTTPd/Netplex subtasking
Gerd Stolpmann <[email protected]> Thu, 10 Jan 2013 15:56:25 +0100
| Newsgroups | gmane.comp.lang.ocaml.lib.net.devel |
|---|---|
| Message-ID | <1357829785.3150.145.camel@thinkpad> |
Am Donnerstag, den 10.01.2013, 15:17 +0100 schrieb Pierre-Alexandre
Voye:
>
>
> I followed one of the simpler example (don't remember which one), in
> fact, my app starts with this code :
>
> let start handlers =
> let (option_list, cmdline_infos) = Netplex_main.args() in
>
> (* .... cut ... *)
> let nethttpd_factory = Nethttpd_plex.nethttpd_factory
> ~handlers:handlers () in
> Netplex_main.startup ( Netplex_mp.mp ~keep_fd_open:true () )
> Netplex_log.logger_factories
> Netplex_workload.workload_manager_factories
> [ nethttpd_factory ]
> cmdline_infos
>
>
> Normally, only the threads will use the object.
That's fine then.
> Because of my inability to user shared memory, I don't have any byte
> of global memory in this software (I use Memcache for that)
>
>
> So, if i start a thread and return the string result, is there a risk
> that the processes is killed by the master process before the thread
> finish his job (In theory not) ?
In theory and practice, this risk exists in deed. But you can do
something about it. The process is not killed with a signal, but there
is an orderly shutdown procedure going through several steps until
terminating the process, and it is possible to run some user code for
process cleanup. Nethttpd_plex.nethttpd_factory takes a ~hooks argument:
let hooks =
object
inherit Netplex_kit.empty_processor_hooks()
method shutdown() = wait_for_the_termination_of_the_threads()
end
I think a simple counter for the number of threads would be sufficient
(remember that "incr counter" and "decr counter" are atomic), and you
could just busy-wait (while !counter > 0 do sleep 1 done).
Note that there is also a second hook, pre_finish_hook, which is even
called later, but this hook is time-bound. If the maximum time is
exceeded, the process is finally killed (the timeout is set by
~terminate_tmo of Netplex_mp.mp).
Gerd
>
>
> 2013/1/10 Gerd Stolpmann <[email protected]>
> Am Donnerstag, den 10.01.2013, 13:19 +0100 schrieb
> Pierre-Alexandre
> Voye:
>
> >
> > Can I use a thread without risk ?
>
>
> Normally, yes, if you ensure that library functions do not
> "see" that
> there are several threads, i.e. any object is only used by one
> thread at
> a time. There are normally no mutexes controlling parallel
> access
> built-in (except where described). There are also no global
> variables
> making multi-threading impossible (and if so, there are
> mutexes around
> them).
>
> I must admit that I do not exactly understand your
> architectural
> problem. What I've got is that
>
> - You get a request via Nethttpd
> - You call your service routine via the CGI-style interface
> - that routine computes the result to return via CGI
> - but that routine also needs to do some side work that is
> not needed for the CGI return value, and could be run
> outside the strict HTTP request/response cycle
>
> The answer to the question how you can run such side work
> depends very
> much on how you deploy Nethttpd. Do you use the Netplex
> containers, or
> did you follow one of the simpler examples?
>
> Gerd
>
>
>
>
> --
> ------------------------------------------------------------
> Gerd Stolpmann, Darmstadt, Germany [email protected]
> Creator of GODI and camlcity.org.
> Contact details: http://www.camlcity.org/contact.html
> Company homepage: http://www.gerd-stolpmann.de
> *** Searching for new projects! Need consulting for system
> *** programming in Ocaml? Gerd Stolpmann can help you.
> ------------------------------------------------------------
>
>
>
>
> --
> ---------------------
> https://twitter.com/#!/ontologiae/
> http://linuxfr.org/users/montaigne
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122712
> _______________________________________________ Ocamlnet-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ocamlnet-devel
--
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany [email protected]
Creator of GODI and camlcity.org.
Contact details: http://www.camlcity.org/contact.html
Company homepage: http://www.gerd-stolpmann.de
*** Searching for new projects! Need consulting for system
*** programming in Ocaml? Gerd Stolpmann can help you.
------------------------------------------------------------
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712