You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by Chris Goffinet <go...@yahoo-inc.com> on 2008/07/18 07:31:12 UTC

PHP example of buffering

Hi

I was wondering if anyone has an example of using Thrift to buffer a  
set of functions that send data? So right now if I declared a function  
with an argument and needed to send 100 of these functions in an  
async, non-blocking manner, is it this possible? Best example might be  
like multi-set from memcached client.

-- 
Chris Goffinet
MyBlogLog Senior Performance Engineer

Yahoo!
San Francisco, CA
United States


Re: PHP example of buffering

Posted by David Reiss <dr...@facebook.com>.
Actually, another Facebook engineer developed something like this
that uses nonblocking I/O to connect to the servers in parallel,
send all the requests, and receive them in the proper order as
the responses come it.  He's gotten it into a working state,
but he has to make a small architectural change.  I'll be sure
to submit it for inclusion in the open-source repository as soon
as it's done.

--David

Mark Slee wrote:
> It really just depends upon the nature of your application, latency
> requirements, and the variance in your backend server performance.
> 
> We've used this technique in instances where the
> serialization/communication cost is a negligible portion of the total
> operation cost and therefore doesn't contribute significantly to
> latency. In those cases, it's fine.
> 
> Generally, you might as well try this because the cost of development is
> so low. Evaluate the performance, and if it's not up to snuff then start
> thinking about the more complicated stuff.
> 
> -----Original Message-----
> From: Chris Goffinet [mailto:goffinet@yahoo-inc.com]
> Sent: Thursday, July 17, 2008 10:47 PM
> To: thrift-dev@incubator.apache.org
> Subject: Re: PHP example of buffering
> 
> Mark,
> 
> Great! Thanks for the excellent info. In most cases, does Facebook see
> any issues with the existing implementation on the front-end? I'm
> wondering if it really merits the C extension at this time.
> 
> --
> Chris Goffinet
> MyBlogLog Senior Performance Engineer
> 
> Yahoo!
> San Francisco, CA
> United States
> 
> On Jul 17, 2008, at 10:41 PM, Mark Slee wrote:
> 
>> If your client code is in PHP, there's not really a super-elegant 
>> way to
>> do this, since the native PHP client code is by nature single-
>> threaded.
>>
>> What you can do is take advantage of the split send_ recv_ methods 
>> that
>> the Thrift interface exports to do basic round robin.
>>
>> $clients = array(); // assume it contains 100 clients
>> foreach ($clients as $c) {
>>  $c->send_method($args);
>> }
>> $results = array();
>> foreach ($clients as $c) {
>>  $results []= $c->recv_method();
>> }
>>
>> Note that this is *not* a particularly good solution. The performance
>> will depend heavily upon the distribution of your response times. In 
>> the
>> worst case, the first client has a very slow response time and you can
>> spend a long time blocked on receiving data.
>>
>> A good solution to this problem in PHP would basically require writing
>> an extension to do the I/O work in C.
>>
>> -----Original Message-----
>> From: Chris Goffinet [mailto:goffinet@yahoo-inc.com]
>> Sent: Thursday, July 17, 2008 10:31 PM
>> To: thrift-dev@incubator.apache.org
>> Subject: PHP example of buffering
>>
>> Hi
>>
>> I was wondering if anyone has an example of using Thrift to buffer a 
>> set
>> of functions that send data? So right now if I declared a function 
>> with
>> an argument and needed to send 100 of these functions in an async,
>> non-blocking manner, is it this possible? Best example might be like
>> multi-set from memcached client.
>>
>> --
>> Chris Goffinet
>> MyBlogLog Senior Performance Engineer
>>
>> Yahoo!
>> San Francisco, CA
>> United States
>>
> 

RE: PHP example of buffering

Posted by Mark Slee <ms...@facebook.com>.
It really just depends upon the nature of your application, latency
requirements, and the variance in your backend server performance.

We've used this technique in instances where the
serialization/communication cost is a negligible portion of the total
operation cost and therefore doesn't contribute significantly to
latency. In those cases, it's fine.

Generally, you might as well try this because the cost of development is
so low. Evaluate the performance, and if it's not up to snuff then start
thinking about the more complicated stuff.

-----Original Message-----
From: Chris Goffinet [mailto:goffinet@yahoo-inc.com] 
Sent: Thursday, July 17, 2008 10:47 PM
To: thrift-dev@incubator.apache.org
Subject: Re: PHP example of buffering

Mark,

Great! Thanks for the excellent info. In most cases, does Facebook see
any issues with the existing implementation on the front-end? I'm
wondering if it really merits the C extension at this time.

-- 
Chris Goffinet
MyBlogLog Senior Performance Engineer

Yahoo!
San Francisco, CA
United States

On Jul 17, 2008, at 10:41 PM, Mark Slee wrote:

> If your client code is in PHP, there's not really a super-elegant  
> way to
> do this, since the native PHP client code is by nature single- 
> threaded.
>
> What you can do is take advantage of the split send_ recv_ methods  
> that
> the Thrift interface exports to do basic round robin.
>
> $clients = array(); // assume it contains 100 clients
> foreach ($clients as $c) {
>  $c->send_method($args);
> }
> $results = array();
> foreach ($clients as $c) {
>  $results []= $c->recv_method();
> }
>
> Note that this is *not* a particularly good solution. The performance
> will depend heavily upon the distribution of your response times. In  
> the
> worst case, the first client has a very slow response time and you can
> spend a long time blocked on receiving data.
>
> A good solution to this problem in PHP would basically require writing
> an extension to do the I/O work in C.
>
> -----Original Message-----
> From: Chris Goffinet [mailto:goffinet@yahoo-inc.com]
> Sent: Thursday, July 17, 2008 10:31 PM
> To: thrift-dev@incubator.apache.org
> Subject: PHP example of buffering
>
> Hi
>
> I was wondering if anyone has an example of using Thrift to buffer a  
> set
> of functions that send data? So right now if I declared a function  
> with
> an argument and needed to send 100 of these functions in an async,
> non-blocking manner, is it this possible? Best example might be like
> multi-set from memcached client.
>
> --
> Chris Goffinet
> MyBlogLog Senior Performance Engineer
>
> Yahoo!
> San Francisco, CA
> United States
>


Re: PHP example of buffering

Posted by Chris Goffinet <go...@yahoo-inc.com>.
Mark,

Great! Thanks for the excellent info. In most cases, does Facebook see  
any issues with the existing implementation on the front-end? I'm  
wondering if it really merits the C extension at this time.

-- 
Chris Goffinet
MyBlogLog Senior Performance Engineer

Yahoo!
San Francisco, CA
United States

On Jul 17, 2008, at 10:41 PM, Mark Slee wrote:

> If your client code is in PHP, there's not really a super-elegant  
> way to
> do this, since the native PHP client code is by nature single- 
> threaded.
>
> What you can do is take advantage of the split send_ recv_ methods  
> that
> the Thrift interface exports to do basic round robin.
>
> $clients = array(); // assume it contains 100 clients
> foreach ($clients as $c) {
>  $c->send_method($args);
> }
> $results = array();
> foreach ($clients as $c) {
>  $results []= $c->recv_method();
> }
>
> Note that this is *not* a particularly good solution. The performance
> will depend heavily upon the distribution of your response times. In  
> the
> worst case, the first client has a very slow response time and you can
> spend a long time blocked on receiving data.
>
> A good solution to this problem in PHP would basically require writing
> an extension to do the I/O work in C.
>
> -----Original Message-----
> From: Chris Goffinet [mailto:goffinet@yahoo-inc.com]
> Sent: Thursday, July 17, 2008 10:31 PM
> To: thrift-dev@incubator.apache.org
> Subject: PHP example of buffering
>
> Hi
>
> I was wondering if anyone has an example of using Thrift to buffer a  
> set
> of functions that send data? So right now if I declared a function  
> with
> an argument and needed to send 100 of these functions in an async,
> non-blocking manner, is it this possible? Best example might be like
> multi-set from memcached client.
>
> --
> Chris Goffinet
> MyBlogLog Senior Performance Engineer
>
> Yahoo!
> San Francisco, CA
> United States
>


RE: PHP example of buffering

Posted by Mark Slee <ms...@facebook.com>.
If your client code is in PHP, there's not really a super-elegant way to
do this, since the native PHP client code is by nature single-threaded.

What you can do is take advantage of the split send_ recv_ methods that
the Thrift interface exports to do basic round robin.

$clients = array(); // assume it contains 100 clients
foreach ($clients as $c) {
  $c->send_method($args);
}
$results = array();
foreach ($clients as $c) {
  $results []= $c->recv_method();
}

Note that this is *not* a particularly good solution. The performance
will depend heavily upon the distribution of your response times. In the
worst case, the first client has a very slow response time and you can
spend a long time blocked on receiving data.

A good solution to this problem in PHP would basically require writing
an extension to do the I/O work in C.

-----Original Message-----
From: Chris Goffinet [mailto:goffinet@yahoo-inc.com] 
Sent: Thursday, July 17, 2008 10:31 PM
To: thrift-dev@incubator.apache.org
Subject: PHP example of buffering

Hi

I was wondering if anyone has an example of using Thrift to buffer a set
of functions that send data? So right now if I declared a function with
an argument and needed to send 100 of these functions in an async,
non-blocking manner, is it this possible? Best example might be like
multi-set from memcached client.

--
Chris Goffinet
MyBlogLog Senior Performance Engineer

Yahoo!
San Francisco, CA
United States