Grokbase Groups Thrift user July 2012
FAQ
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

Search Discussions

  • Jonathan Ellis at Jul 30, 2012 at 10:19 pm
    No.
    On Mon, Jul 30, 2012 at 5:17 PM, Francis Liu 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
  • Mark Slee at Jul 30, 2012 at 10:23 pm
    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
  • Francis Liu at Jul 31, 2012 at 12:41 am
    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" 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesthrift
postedJul 30, '12 at 10:17p
activeJul 31, '12 at 12:41a
posts4
users3
websitethrift.apache.org
irc#thrift

People

Translate

site design / logo © 2022 Grokbase