Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Mike Lin <mlin@mlin.net>
Cc: ocamlnet-devel@lists.sourceforge.net,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] AW: Multithreaded https requests in ocamlnet netclient
Date: Tue, 27 Nov 2012 14:03:03 +0100	[thread overview]
Message-ID: <1354021383.3169.2@samsung> (raw)
In-Reply-To: <CADxsieavhmvdJAL+3Wk9Dfyrb-dW49reNFoxcZHwKYvC4RabzA@mail.gmail.com> (from mlin@mlin.net on Tue Nov 27 03:54:16 2012)

Hi Mike,

I can confirm the problem, but I'm not able to track it down.

First of all, I'm quite sure that you cannot share SSL contexts between  
threads. But even if I fix this, I get crashes - usually early during  
SSL_connect.

I'm wondering whether ocaml-ssl initializes openssl correctly for  
multi-threading. In my version of openssl the prototype is

int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID  
*));

but in ocaml-ssl the CRYPTO_THREADID pointer is ignored (it assumes  
void here). So, maybe this is the reason. I currently don't have time  
to follow this idea.

If everything fails, there is a way to use Netclient in threaded  
applications so that only one thread is doing the networking stuff, see  
this example:

https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/examples/netclient/simple/http_mt.ml

As Netclient is event-driven, the requests are processed in parallel  
(with one exception, though: DNS lookups are synchronous, but this can  
be worked around, as the DNS lookup function is settable in Netclient).

Gerd

Am 27.11.2012 03:54:16 schrieb(en) Mike Lin:
> Hello Gerd, all,
> 
> I'm trying to find the right incantations to make parallel https  
> requests
> from multiple threads using Http_client. (I know the library is  
> capable of
> multiple requests from one thread -- I have other strong reasons to  
> use
> multithreading.)
> 
> https://gist.github.com/4152047
> 
> This program generally segfaults for me at some random point during  
> the 10
> requests.  Compiled as in the comment in line 2 (ubuntu quantal,
> libocamlnet-ocaml-dev 3.5.1, ocaml 3.12.1).
> 
> Permutations attempted:
> 
> 1) Change https to http in google URL -- works as expected
> 2) Serialize requests by uncommenting line 35 -- works as expected
> 3) Move invocations of Ssl.init, Ssl.create_context,
> HTTPS.https_transport_channel_type in and out of fresh_pipeline  
> (which runs
> in the worker threads) -- no help
> 
> Any suggestions? Thanks!
> 
> Mike Lin
> 



-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

  reply	other threads:[~2012-11-27 13:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-27  2:54 [Caml-list] " Mike Lin
2012-11-27 13:03 ` Gerd Stolpmann [this message]
2012-11-28  1:43   ` [Caml-list] " Mike Lin
2013-09-26  8:34     ` [Caml-list] " Török Edwin

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=1354021383.3169.2@samsung \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@inria.fr \
    --cc=mlin@mlin.net \
    --cc=ocamlnet-devel@lists.sourceforge.net \
    /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