You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Erik Fears <st...@gmail.com> on 2010/07/20 21:18:09 UTC

C++ API and external eventloop

Thrift users,

There seems to be a lack of documentation for the C++ implementation. If I'm
mistaken, please point me in the right direction.

I want to implement a thrift server in a non-blocking fashion in C++, but I
want control over my own eventloop (libevent). My daemon has more
responsibilities than just thrift, so I cannot just call
thriftServer.serve().

What's the best approach for this? Is there a model where I can tell thrift
that there is activity on a socket?

Thanks,
--erik

Re: C++ API and external eventloop

Posted by Rush Manbert <ru...@manbert.com>.
IIRC, from my tests using the stress test app, TNonBlockingServer seems to be faster than any of the others in Windows.

But be sure to do your own tests, because it's been a while since I was doing thisd.

- Rush

On Jul 22, 2010, at 7:31 AM, Bryan Duxbury wrote:

> If the C++ NonblockingServer is like the Java one, which I think it is, then
> it uses nonblocking IO to communicate with clients in a single thread, and
> then performs the method invocations either in that same thread or in a
> limited threadpool. The purpose is to avoid having to have a thread per
> connection.
> 
> ThreadPoolServer uses a thread per client connection (up to a certain limit)
> and performs the IO and invocation in that thread. You run the risk of
> having slow connections take up a thread for a long time and blocking other
> invocations from occurring. At least in the Java ThreadPoolServer, you also
> have the issue that it's not a "fair" server - that is, once a socket is
> assigned to a thread from the pool, that thread will remain busy until the
> socket is *closed*, meaning that you need to have as many threads as you
> want to have concurrent connections, not just concurrent method executions.
> 
> -Bryan
> 
> On Thu, Jul 22, 2010 at 7:15 AM, 萧超杰 <ch...@gmail.com> wrote:
> 
>> so what is the differences between TNonBlockingServer and
>> TThreadPoolServer?
>> 
>> 2010/7/22 Łukasz Michalik <lm...@ift.uni.wroc.pl>
>> 
>>> On 16:34 2010-07-22 +0800, 萧超杰 wrote:
>>>> if i use TThreadPoolServer is this server a nonblocking server?
>>>> 
>>> 
>>> It is nonblocking in the sense, that it doesn't block, but keep in
>>> mind that it spawns a thread (or uses one from pool) each time a
>>> client connects.
>>> 
>>> --
>>> A: Because it messes up the order in which people normally read text.
>>> Q: Why is top-posting such a bad thing?
>>> A: Top-posting.
>>> Q: What is the most annoying thing on usenet and in e-mail?
>>> 
>>> Pozdrawiam,
>>> Łukasz P. Michalik
>>> 
>> 


Re: C++ API and external eventloop

Posted by Bryan Duxbury <br...@rapleaf.com>.
If the C++ NonblockingServer is like the Java one, which I think it is, then
it uses nonblocking IO to communicate with clients in a single thread, and
then performs the method invocations either in that same thread or in a
limited threadpool. The purpose is to avoid having to have a thread per
connection.

ThreadPoolServer uses a thread per client connection (up to a certain limit)
and performs the IO and invocation in that thread. You run the risk of
having slow connections take up a thread for a long time and blocking other
invocations from occurring. At least in the Java ThreadPoolServer, you also
have the issue that it's not a "fair" server - that is, once a socket is
assigned to a thread from the pool, that thread will remain busy until the
socket is *closed*, meaning that you need to have as many threads as you
want to have concurrent connections, not just concurrent method executions.

-Bryan

On Thu, Jul 22, 2010 at 7:15 AM, 萧超杰 <ch...@gmail.com> wrote:

> so what is the differences between TNonBlockingServer and
> TThreadPoolServer?
>
> 2010/7/22 Łukasz Michalik <lm...@ift.uni.wroc.pl>
>
> > On 16:34 2010-07-22 +0800, 萧超杰 wrote:
> > > if i use TThreadPoolServer is this server a nonblocking server?
> > >
> >
> > It is nonblocking in the sense, that it doesn't block, but keep in
> > mind that it spawns a thread (or uses one from pool) each time a
> > client connects.
> >
> > --
> > A: Because it messes up the order in which people normally read text.
> > Q: Why is top-posting such a bad thing?
> > A: Top-posting.
> > Q: What is the most annoying thing on usenet and in e-mail?
> >
> > Pozdrawiam,
> > Łukasz P. Michalik
> >
>

Re: C++ API and external eventloop

Posted by 萧超杰 <ch...@gmail.com>.
so what is the differences between TNonBlockingServer and TThreadPoolServer?

2010/7/22 Łukasz Michalik <lm...@ift.uni.wroc.pl>

> On 16:34 2010-07-22 +0800, 萧超杰 wrote:
> > if i use TThreadPoolServer is this server a nonblocking server?
> >
>
> It is nonblocking in the sense, that it doesn't block, but keep in
> mind that it spawns a thread (or uses one from pool) each time a
> client connects.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?
>
> Pozdrawiam,
> Łukasz P. Michalik
>

Re: C++ API and external eventloop

Posted by Łukasz Michalik <lm...@ift.uni.wroc.pl>.
On 16:34 2010-07-22 +0800, 萧超杰 wrote:
> if i use TThreadPoolServer is this server a nonblocking server?
> 

It is nonblocking in the sense, that it doesn't block, but keep in
mind that it spawns a thread (or uses one from pool) each time a
client connects.

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Pozdrawiam,
Łukasz P. Michalik

Re: C++ API and external eventloop

Posted by 萧超杰 <ch...@gmail.com>.
if i use TThreadPoolServer is this server a nonblocking server?

thank you!

2010/7/22 Erik Fears <st...@gmail.com>

> Yep. I ended up deriving from TNonblockingServer and overriding the ::serve
> function to not call the libevent loop.
>
> Thanks,
> --erik
>
> On Wed, Jul 21, 2010 at 11:32 AM, Roger Meier <roger@bufferoverflow.ch
> >wrote:
>
> > Hi erik
> >
> > just have a look on the TNonblockingServer::serve() function
> > it uses libevent and might be a starting point for your work:
> >
> >
> >
> https://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
> >
> >
> > regards
> >
> > roger
> >
> >
> > Am 20.07.2010 21:18, schrieb Erik Fears:
> >
> >  Thrift users,
> >>
> >> There seems to be a lack of documentation for the C++ implementation. If
> >> I'm
> >> mistaken, please point me in the right direction.
> >>
> >> I want to implement a thrift server in a non-blocking fashion in C++,
> but
> >> I
> >> want control over my own eventloop (libevent). My daemon has more
> >> responsibilities than just thrift, so I cannot just call
> >> thriftServer.serve().
> >>
> >> What's the best approach for this? Is there a model where I can tell
> >> thrift
> >> that there is activity on a socket?
> >>
> >> Thanks,
> >> --erik
> >>
> >>
> >
>

Re: C++ API and external eventloop

Posted by Erik Fears <st...@gmail.com>.
Yep. I ended up deriving from TNonblockingServer and overriding the ::serve
function to not call the libevent loop.

Thanks,
--erik

On Wed, Jul 21, 2010 at 11:32 AM, Roger Meier <ro...@bufferoverflow.ch>wrote:

> Hi erik
>
> just have a look on the TNonblockingServer::serve() function
> it uses libevent and might be a starting point for your work:
>
>
> https://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp
>
>
> regards
>
> roger
>
>
> Am 20.07.2010 21:18, schrieb Erik Fears:
>
>  Thrift users,
>>
>> There seems to be a lack of documentation for the C++ implementation. If
>> I'm
>> mistaken, please point me in the right direction.
>>
>> I want to implement a thrift server in a non-blocking fashion in C++, but
>> I
>> want control over my own eventloop (libevent). My daemon has more
>> responsibilities than just thrift, so I cannot just call
>> thriftServer.serve().
>>
>> What's the best approach for this? Is there a model where I can tell
>> thrift
>> that there is activity on a socket?
>>
>> Thanks,
>> --erik
>>
>>
>

Re: C++ API and external eventloop

Posted by Roger Meier <ro...@bufferoverflow.ch>.
Hi erik

just have a look on the TNonblockingServer::serve() function
it uses libevent and might be a starting point for your work:

https://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/cpp/src/server/TNonblockingServer.cpp


regards

roger


Am 20.07.2010 21:18, schrieb Erik Fears:
> Thrift users,
>
> There seems to be a lack of documentation for the C++ implementation. If I'm
> mistaken, please point me in the right direction.
>
> I want to implement a thrift server in a non-blocking fashion in C++, but I
> want control over my own eventloop (libevent). My daemon has more
> responsibilities than just thrift, so I cannot just call
> thriftServer.serve().
>
> What's the best approach for this? Is there a model where I can tell thrift
> that there is activity on a socket?
>
> Thanks,
> --erik
>