You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Francis Liu <to...@apache.org> on 2012/07/31 00:17:17 UTC

is the thrift client thread safe?

Hi,

Thrift noob here. I looked through the documentation was searching the net
for an answer but couldn't find up to date information on this. I'm looking
to cache the thrift client and was wondering if it could be shared across
multiple threads.

-Francis




Re: is the thrift client thread safe?

Posted by Francis Liu <to...@apache.org>.
I'm using Java. 

Thanks for the quick response guys! We'll be going with the
client-per-thread model then.

-Francis

On 7/30/12 3:23 PM, "Mark Slee" <ms...@fb.com> wrote:

>Which language are you referring to?
>
>The general answer is no. I don't believe any of the off-the-shelf client
>libraries synchronize access to the underlying socket or buffers in any
>way.
>
>You *may* be able to share the client across threads, if you take
>explicit care to lock access to it, ensuring that any thread using the
>client holds a lock around the full life-cycle of sending a request,
>flushing it, receiving any expected response.
>
>Wouldn't generally recommend this, though. Think you're better off going
>with a client-per-thread model, and keeping your number of threads low
>(typically close to the order of your number of cores). Or using a
>networker thread model, where worker threads put in requests for the
>networker thread to do some work, and just the networker owns the client.
>
>The simplest way to think about this is that clients are like sockets.
>Sharing sockets across threads is generally going to be painful.
>________________________________________
>From: Francis Liu [toffer@apache.org]
>Sent: Monday, July 30, 2012 3:17 PM
>To: user@thrift.apache.org
>Subject: is the thrift client thread safe?
>
>Hi,
>
>Thrift noob here. I looked through the documentation was searching the net
>for an answer but couldn't find up to date information on this. I'm
>looking
>to cache the thrift client and was wondering if it could be shared across
>multiple threads.
>
>-Francis
>
>
>



RE: is the thrift client thread safe?

Posted by Mark Slee <ms...@fb.com>.
Which language are you referring to?

The general answer is no. I don't believe any of the off-the-shelf client libraries synchronize access to the underlying socket or buffers in any way.

You *may* be able to share the client across threads, if you take explicit care to lock access to it, ensuring that any thread using the client holds a lock around the full life-cycle of sending a request, flushing it, receiving any expected response.

Wouldn't generally recommend this, though. Think you're better off going with a client-per-thread model, and keeping your number of threads low (typically close to the order of your number of cores). Or using a networker thread model, where worker threads put in requests for the networker thread to do some work, and just the networker owns the client.

The simplest way to think about this is that clients are like sockets. Sharing sockets across threads is generally going to be painful.
________________________________________
From: Francis Liu [toffer@apache.org]
Sent: Monday, July 30, 2012 3:17 PM
To: user@thrift.apache.org
Subject: is the thrift client thread safe?

Hi,

Thrift noob here. I looked through the documentation was searching the net
for an answer but couldn't find up to date information on this. I'm looking
to cache the thrift client and was wondering if it could be shared across
multiple threads.

-Francis




Re: is the thrift client thread safe?

Posted by Jonathan Ellis <jb...@gmail.com>.
No.

On Mon, Jul 30, 2012 at 5:17 PM, Francis Liu <to...@apache.org> wrote:
> Hi,
>
> Thrift noob here. I looked through the documentation was searching the net
> for an answer but couldn't find up to date information on this. I'm looking
> to cache the thrift client and was wondering if it could be shared across
> multiple threads.
>
> -Francis
>
>
>



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of DataStax, the source for professional Cassandra support
http://www.datastax.com