thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tuan Le Dinh <ldtua...@gmail.com>
Subject Re: How to make a Thrift client for multiple threads?
Date Tue, 07 Jun 2016 14:45:14 GMT
I tried to use HttpClient instance with PoolingHttpClientConnectionManager
 and passed it to THttpClient(String url, HttpClient client) but it doesn't
help.
THttpClient is Thrift transport layer.
Do I need to handle multiple thread in Protocol layer (TProtocol,
TMultiplexedProtocol) ?

TProtocol protocol = new
TBinaryProtocol(transport);TMultiplexedProtocol mp = new
TMultiplexedProtocol(protocol, "UserService");UserService.Client
userServiceClient = new UserService.Client(mp);

Dear Matt Chambers, by mentioning "to use ThreadLocal connections", did you
mean use it for TTransport or TProtocol or both?

On Tue, Jun 7, 2016 at 10:29 PM, BCG <bgould@hushmail.com> wrote:

>
> On 06/07/2016 07:54 AM, Matt Chambers wrote:
>
>> Another way to do it would be to use ThreadLocal connections.
>> https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html <
>> https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html>
>>
>> On Jun 7, 2016, at 6:14 AM, Daniel Wu <qiang.wu@dianrong.com> wrote:
>>>
>>> Thrift client/connection is not thread safe. Use a lock or object pool.
>>>
>>> On 7/6/2016, 5:51 PM, "Tuan Le Dinh" <ldtuanbk@gmail.com> wrote:
>>>
>>>
>>> You might not see too much gain in simply pooling/locking/reusing
> clients, as the real overhead that you are trying to avoid (I presume) is
> the overhead of establishing connections.  Simply reusing THttpClient might
> not avoid this overhead.
>
> In addition to (or perhaps instead of) reusing client instances you might
> want to investigate the connection pooling functionality built into Commons
> HTTP Components:
>
> https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
>
> You could, for example, manually configure an HttpClient instance to use
> connection pooling and then just pass that instance to the
> THttpClient(String url, HttpClient client) constructor.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message