You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by David chen <c7...@163.com> on 2015/01/13 10:31:23 UTC

Whether or not multi-thread share the single PhoenixConnection object?

My application will base on Phoenix, and response the multi-user query. I plan to create a thread pool that its per thread will correspond to a user query. But i don't sure whether or not multi-thread in the pool should share the single PhoenixConnection object?
I remember that HBase community advice that the multi-thread should share the single HConnection object as much as possible.
Any ideas can be appreciated!

Re:Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by David chen <c7...@163.com>.
Hi guys,
Your discussion and clarification make sense for me, thank you!

Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by Naga Vijayapuram <Na...@gap.com>.
>From the discussions it is clear there is no point in using C3P0 connection pool due to the sole HConnection behind the scenes.

Thanks
Naga

On Jan 13, 2015, at 11:39 AM, Naga Vijayapuram <Na...@gap.com>> wrote:

We are using MyBatis.  Would it be worthwhile or meaningful to use C3P0 connection pool in our case?

Naga

On Jan 13, 2015, at 11:28 AM, Samarth Jain <sa...@gmail.com>> wrote:

There is only one HConnection per cluster. Every phoenix connection to a cluster shares the same underlying HConnection. See ConnectionQueryServicesImpl#init() where we make sure that there is only one HConnection to the cluster. The HConnection is established when it's the first time that the phoenix driver tries to connect to the cluster.

On Tuesday, January 13, 2015, Nick Dimiduk <nd...@gmail.com>> wrote:
At least on Master, it appears the default HConnectionFactoryImpl is calling HConnectionManager.createConnection(Configuration), which creates an unmanaged connection. This means that each PhoenixConnection will be making and managing its own HBase Connection.

On Tue, Jan 13, 2015 at 1:50 AM, Gabriel Reid <gabriel.reid@gmail.com<javascript:_e(%7B%7D,'cvml','gabriel.reid@gmail.com');>> wrote:
Hi David,

The PhoenixConnection class is not thread-safe, and shouldn't be
shared over multiple threads. I think that this is probably the case
with quite a few other JDBC drivers as well, so it's generally safer
to use a JDBC connection pool if you want to use connections in
multiple threads.

If I remember correctly, a single HConnection is used (and shared) by
multiple PhoenixConnection objects that have been instantiated from
the same Driver instance, so there shouldn't be any performance
overhead to using a single Phoenix connection per thread.

- Gabriel


On Tue, Jan 13, 2015 at 10:31 AM, David chen <c77_cn@163.com<javascript:_e(%7B%7D,'cvml','c77_cn@163.com');>> wrote:
> My application will base on Phoenix, and response the multi-user query. I
> plan to create a thread pool that its per thread will correspond to a user
> query. But i don't sure whether or not multi-thread in the pool should share
> the single PhoenixConnection object?
> I remember that HBase community advice that the multi-thread should share
> the single HConnection object as much as possible.
> Any ideas can be appreciated!




Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by Naga Vijayapuram <Na...@gap.com>.
We are using MyBatis.  Would it be worthwhile or meaningful to use C3P0 connection pool in our case?

Naga

On Jan 13, 2015, at 11:28 AM, Samarth Jain <sa...@gmail.com>> wrote:

There is only one HConnection per cluster. Every phoenix connection to a cluster shares the same underlying HConnection. See ConnectionQueryServicesImpl#init() where we make sure that there is only one HConnection to the cluster. The HConnection is established when it's the first time that the phoenix driver tries to connect to the cluster.

On Tuesday, January 13, 2015, Nick Dimiduk <nd...@gmail.com>> wrote:
At least on Master, it appears the default HConnectionFactoryImpl is calling HConnectionManager.createConnection(Configuration), which creates an unmanaged connection. This means that each PhoenixConnection will be making and managing its own HBase Connection.

On Tue, Jan 13, 2015 at 1:50 AM, Gabriel Reid <gabriel.reid@gmail.com<javascript:_e(%7B%7D,'cvml','gabriel.reid@gmail.com');>> wrote:
Hi David,

The PhoenixConnection class is not thread-safe, and shouldn't be
shared over multiple threads. I think that this is probably the case
with quite a few other JDBC drivers as well, so it's generally safer
to use a JDBC connection pool if you want to use connections in
multiple threads.

If I remember correctly, a single HConnection is used (and shared) by
multiple PhoenixConnection objects that have been instantiated from
the same Driver instance, so there shouldn't be any performance
overhead to using a single Phoenix connection per thread.

- Gabriel


On Tue, Jan 13, 2015 at 10:31 AM, David chen <c77_cn@163.com<javascript:_e(%7B%7D,'cvml','c77_cn@163.com');>> wrote:
> My application will base on Phoenix, and response the multi-user query. I
> plan to create a thread pool that its per thread will correspond to a user
> query. But i don't sure whether or not multi-thread in the pool should share
> the single PhoenixConnection object?
> I remember that HBase community advice that the multi-thread should share
> the single HConnection object as much as possible.
> Any ideas can be appreciated!



Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by Nick Dimiduk <nd...@gmail.com>.
On Tue, Jan 13, 2015 at 11:28 AM, Samarth Jain <sa...@gmail.com>
wrote:

> There is only one HConnection per cluster. Every phoenix connection to a
> cluster shares the same underlying HConnection. See
> ConnectionQueryServicesImpl#init() where we make sure that there is only
> one HConnection to the cluster. The HConnection is established when it's
> the first time that the phoenix driver tries to connect to the cluster.


I see now. Thank you for clarifying.

On Tuesday, January 13, 2015, Nick Dimiduk <nd...@gmail.com> wrote:
>
>> At least on Master, it appears the default HConnectionFactoryImpl is
>> calling HConnectionManager.createConnection(Configuration), which creates
>> an unmanaged connection. This means that each PhoenixConnection will be
>> making and managing its own HBase Connection.
>>
>> On Tue, Jan 13, 2015 at 1:50 AM, Gabriel Reid <ga...@gmail.com>
>> wrote:
>>
>>> Hi David,
>>>
>>> The PhoenixConnection class is not thread-safe, and shouldn't be
>>> shared over multiple threads. I think that this is probably the case
>>> with quite a few other JDBC drivers as well, so it's generally safer
>>> to use a JDBC connection pool if you want to use connections in
>>> multiple threads.
>>>
>>> If I remember correctly, a single HConnection is used (and shared) by
>>> multiple PhoenixConnection objects that have been instantiated from
>>> the same Driver instance, so there shouldn't be any performance
>>> overhead to using a single Phoenix connection per thread.
>>>
>>> - Gabriel
>>>
>>>
>>> On Tue, Jan 13, 2015 at 10:31 AM, David chen <c7...@163.com> wrote:
>>> > My application will base on Phoenix, and response the multi-user
>>> query. I
>>> > plan to create a thread pool that its per thread will correspond to a
>>> user
>>> > query. But i don't sure whether or not multi-thread in the pool should
>>> share
>>> > the single PhoenixConnection object?
>>> > I remember that HBase community advice that the multi-thread should
>>> share
>>> > the single HConnection object as much as possible.
>>> > Any ideas can be appreciated!
>>>
>>
>>

Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by Samarth Jain <sa...@gmail.com>.
There is only one HConnection per cluster. Every phoenix connection to a
cluster shares the same underlying HConnection. See
ConnectionQueryServicesImpl#init() where we make sure that there is only
one HConnection to the cluster. The HConnection is established when it's
the first time that the phoenix driver tries to connect to the cluster.

On Tuesday, January 13, 2015, Nick Dimiduk <nd...@gmail.com> wrote:

> At least on Master, it appears the default HConnectionFactoryImpl is
> calling HConnectionManager.createConnection(Configuration), which creates
> an unmanaged connection. This means that each PhoenixConnection will be
> making and managing its own HBase Connection.
>
> On Tue, Jan 13, 2015 at 1:50 AM, Gabriel Reid <gabriel.reid@gmail.com
> <javascript:_e(%7B%7D,'cvml','gabriel.reid@gmail.com');>> wrote:
>
>> Hi David,
>>
>> The PhoenixConnection class is not thread-safe, and shouldn't be
>> shared over multiple threads. I think that this is probably the case
>> with quite a few other JDBC drivers as well, so it's generally safer
>> to use a JDBC connection pool if you want to use connections in
>> multiple threads.
>>
>> If I remember correctly, a single HConnection is used (and shared) by
>> multiple PhoenixConnection objects that have been instantiated from
>> the same Driver instance, so there shouldn't be any performance
>> overhead to using a single Phoenix connection per thread.
>>
>> - Gabriel
>>
>>
>> On Tue, Jan 13, 2015 at 10:31 AM, David chen <c77_cn@163.com
>> <javascript:_e(%7B%7D,'cvml','c77_cn@163.com');>> wrote:
>> > My application will base on Phoenix, and response the multi-user query.
>> I
>> > plan to create a thread pool that its per thread will correspond to a
>> user
>> > query. But i don't sure whether or not multi-thread in the pool should
>> share
>> > the single PhoenixConnection object?
>> > I remember that HBase community advice that the multi-thread should
>> share
>> > the single HConnection object as much as possible.
>> > Any ideas can be appreciated!
>>
>
>

Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by Nick Dimiduk <nd...@gmail.com>.
At least on Master, it appears the default HConnectionFactoryImpl is
calling HConnectionManager.createConnection(Configuration), which creates
an unmanaged connection. This means that each PhoenixConnection will be
making and managing its own HBase Connection.

On Tue, Jan 13, 2015 at 1:50 AM, Gabriel Reid <ga...@gmail.com>
wrote:

> Hi David,
>
> The PhoenixConnection class is not thread-safe, and shouldn't be
> shared over multiple threads. I think that this is probably the case
> with quite a few other JDBC drivers as well, so it's generally safer
> to use a JDBC connection pool if you want to use connections in
> multiple threads.
>
> If I remember correctly, a single HConnection is used (and shared) by
> multiple PhoenixConnection objects that have been instantiated from
> the same Driver instance, so there shouldn't be any performance
> overhead to using a single Phoenix connection per thread.
>
> - Gabriel
>
>
> On Tue, Jan 13, 2015 at 10:31 AM, David chen <c7...@163.com> wrote:
> > My application will base on Phoenix, and response the multi-user query. I
> > plan to create a thread pool that its per thread will correspond to a
> user
> > query. But i don't sure whether or not multi-thread in the pool should
> share
> > the single PhoenixConnection object?
> > I remember that HBase community advice that the multi-thread should share
> > the single HConnection object as much as possible.
> > Any ideas can be appreciated!
>

Re: Whether or not multi-thread share the single PhoenixConnection object?

Posted by Gabriel Reid <ga...@gmail.com>.
Hi David,

The PhoenixConnection class is not thread-safe, and shouldn't be
shared over multiple threads. I think that this is probably the case
with quite a few other JDBC drivers as well, so it's generally safer
to use a JDBC connection pool if you want to use connections in
multiple threads.

If I remember correctly, a single HConnection is used (and shared) by
multiple PhoenixConnection objects that have been instantiated from
the same Driver instance, so there shouldn't be any performance
overhead to using a single Phoenix connection per thread.

- Gabriel


On Tue, Jan 13, 2015 at 10:31 AM, David chen <c7...@163.com> wrote:
> My application will base on Phoenix, and response the multi-user query. I
> plan to create a thread pool that its per thread will correspond to a user
> query. But i don't sure whether or not multi-thread in the pool should share
> the single PhoenixConnection object?
> I remember that HBase community advice that the multi-thread should share
> the single HConnection object as much as possible.
> Any ideas can be appreciated!