You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by Roshan Naik <ro...@hortonworks.com> on 2015/04/29 02:58:43 UTC

Perf testing flush() - issues found

Based on recent suggestion by Joel, I am experimenting with using flush() to simulate  batched-sync behavior.
The essence of my  single threaded producer code is :

    for (int i = 0; i < numRecords;) {
        // 1- Send a batch
        for(int batchCounter=0; batchCounter<batchSz; ++batchCounter) {
            Future<RecordMetadata> f =  producer.send(record, null);
            futureList.add(f);
            i++;
        }
        // 2- Flush after sending batch
        producer.flush();

        // 3- Ensure all msgs were send
        for( Future<RecordMetadata> f : futureList) {
            f.get();
        }
    }

There are actually two batch size in play here. One is the number of messages between every flush() call made by the client. The other is the  batch.size  setting which impacts the batching internally done by the underlying Async api.

Intuitively  .. we either want to
  A) Set both batch sizes to be Equal, OR
  B) Set the underlying batch.size to a sufficiently large number so as to effectively disable internal batch management


Below numbers are in MB/s.  The 'Batch' column indicate the number of events between each explicit client flush()
Setup is 1-node broker and acks=1.

                1 partition
                Batch=4k        Batch=8k        Batch=16k
Equal batchSizes (a)    16      32      52
large batch.Size (b)    140     123     124

                4 partitions
                Batch=4k        Batch=8k        Batch=16k
Equal batchSz (a)       35      61      82
large batch.size (b)    7       7       7
                8 partitions
                Batch=4k        Batch=8k        Batch=16k
Equal batchSz (a)               49      70      99
large batch.size (b)    7       8       7


There are two issues noticeable in these number:
1 - Case A is much faster than case B for 4 and 8 partitions.
2 - Single partition mode outperforms all others and here case B is faster than case A.




Side Note: I used the  client APIs  from the trunk while the broker is running 0.8.2 (I don't think it matters, but nevertheless wanted to point out)


Re: Perf testing flush() - issues found

Posted by Jun Rao <ju...@confluent.io>.
Note that the batch size is per partition. The more partitions you have,
the longer it will take to fill up all partitions with the same batch size.
So, you probably need to increase the linger time such that in dependent of
the number of partitions, the configured batch size can be reached. There
is a jmx in the producer that tells you the average batch size.

Thanks,

Jun

On Tue, Apr 28, 2015 at 7:58 PM, Roshan Naik <ro...@hortonworks.com> wrote:

> Based on recent suggestion by Joel, I am experimenting with using flush()
> to simulate  batched-sync behavior.
> The essence of my  single threaded producer code is :
>
>     for (int i = 0; i < numRecords;) {
>         // 1- Send a batch
>         for(int batchCounter=0; batchCounter<batchSz; ++batchCounter) {
>             Future<RecordMetadata> f =  producer.send(record, null);
>             futureList.add(f);
>             i++;
>         }
>         // 2- Flush after sending batch
>         producer.flush();
>
>         // 3- Ensure all msgs were send
>         for( Future<RecordMetadata> f : futureList) {
>             f.get();
>         }
>     }
>
> There are actually two batch size in play here. One is the number of
> messages between every flush() call made by the client. The other is the
> batch.size  setting which impacts the batching internally done by the
> underlying Async api.
>
> Intuitively  .. we either want to
>   A) Set both batch sizes to be Equal, OR
>   B) Set the underlying batch.size to a sufficiently large number so as to
> effectively disable internal batch management
>
>
> Below numbers are in MB/s.  The 'Batch' column indicate the number of
> events between each explicit client flush()
> Setup is 1-node broker and acks=1.
>
>                 1 partition
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSizes (a)    16      32      52
> large batch.Size (b)    140     123     124
>
>                 4 partitions
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSz (a)       35      61      82
> large batch.size (b)    7       7       7
>                 8 partitions
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSz (a)               49      70      99
> large batch.size (b)    7       8       7
>
>
> There are two issues noticeable in these number:
> 1 - Case A is much faster than case B for 4 and 8 partitions.
> 2 - Single partition mode outperforms all others and here case B is faster
> than case A.
>
>
>
>
> Side Note: I used the  client APIs  from the trunk while the broker is
> running 0.8.2 (I don't think it matters, but nevertheless wanted to point
> out)
>
>

Re: Perf testing flush() - issues found

Posted by Roshan Naik <ro...@hortonworks.com>.
Thanks @Jay for suggesting changes to batch.size and linger.ms.  I tried
them out. It appears one can do better than the default batch.size for
this synchronous batch mode with flush().

These new measurements are giving more "rational" numbers which with I can
reason and infer some thumb rules (for batch-sync mode using flush).


Here are my observations:
   - The new producer API does much better than the older one for *single
threaded* producer. (best# i saw with old is ~68MB/s, with new ~140MB/s)
   - Higher linger.ms sometimes helps perf and at other times hurts. No
simple rule here. Best to try it out and decide whether default is good
for your case or not.
   - For single threaded producer: To get the most throughput, set
batch.size = (total bytes between flushes / partition count).
   - Running more single threaded producer processes helped (till about
till 3 / 4 processes)
   - 1-producer going to single partition is faster than 1 producer going
to multiple partitions
   - The number of bytes between two explicit flushes (ie. flush interval)
made much smaller impact than the buffer.size. Something to be learnt
here.. my speculation is that with smaller flush intervals this might
change. Having two knobs (batch.size & flush interval is a a bit confusing
for end users trying to tune it, will be good if we can find if there is
some simple guidance feasible)
- Other than some inconveniences previously mentioned, I feel flush()
could be used as a way to simulate sync-batch behavior.

Producer Limits:
   - Able to exceed 1gigEthernet capacity, but not 10gigEthernet. Does not
appear to go beyond ~460MB/s. Verified my test machines are able to
achieve 1GB/s.

Todo:
- Need to try Multi threaded producer.
- I did some testing of the Consumer APIs as well with 0.8.1 consumer-perf
tool. Wasnt able to push it beyond  30MB/s. When producers ran in parallel
it fell to under 10MB/s. Need to dig deeper. Will report back. Suggestions
welcome.



Measurements:

 - See attachment 
 - Also available on paste bin:  http://pastebin.com/p3kSAjy6



Re: Perf testing flush() - issues found

Posted by Jay Kreps <ja...@gmail.com>.
Roshan,

The client allocates a batch per partition and has a hard cap on memory
usage (default 32MB). When it hits that cap it waits for in-flight requests
to complete to use their memory. Setting the batch size to 20M is not
good--that means each partition has a 20MB array allocated for it. This is
not needed.

If you just want good performance I think leave the batch.size alone, the
16k default is probably fine and more than 64k is unlikely to help at all.
Instead make sure you set linger.ms > 0 so you actually wait for the buffer
to fill up (or for flush to be called) instead of immediately sending
requests as soon as soon as there is some data to send.

-Jay

On Wed, Apr 29, 2015 at 8:32 PM, Roshan Naik <ro...@hortonworks.com> wrote:

>
> @Jay,
> My bad. I mistook the batch.size to be number of messages instead of
> bytes. Below are revised measurements based on computing the batch.size in
> bytes .
>
> @Jun,
>
>    With explicit flush()...  linger should not impact. Isn't it ?
>
> @Wang,
>    Larger batches are not necessarily giving better numbers are you can
> see below.
>
>
> The 2 problems I noted earlier still exist in the batched sync mode (using
> flush() ).
>
>   *   batch.size still seems to play a factor even when set to a larger
> value than the bytes generated by client
>   *   4 & 8 partition see a big slowdown
>
>
>
> Revised measurements for new Producer API:
>
> - All cases...Single threaded, 1k event size
>
>
> Batched SYNC using flus() , acks=1
>
>
>
>
>
>
>
>
>
>
>         1 partition
>
>
>
>
>
>
>         Batch=4k        Batch=8k        Batch=16k
>
>
>         batch.size == clientBatch       140
>         124
>
>
>         batch.size = 10MB       140     123     124
>
>
>         batch.Size = 20MB       31      30      42
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>         4 partitions
>
>
>
>
>
>
>         Batch=4k        Batch=8k        Batch=16k
>
>
>         batch.size == clientBatch       60      8       6
>
>
>         batch.size = 10M        7       7       7
>
>
>         batch.Size = 20M        6       6       5
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>         8 partitions
>
>
>
>
>
>
>         Batch=4k        Batch=8k        Batch=16k
>
>
>         batch.size == clientBatch       7       8       8
>
>
>         batch.size = 10M        7       8       7
>
>
>         batch.Size = 20M        6       6       6
>
>
>
> Just for reference I also took the number for  default ASYNC mode with
> acks=1 :
>
>
>
>
>
>
>         batch.size=deafult      batch.size=4MB  batch.size=8MB
> batch.size=16MB
> 1 partition     53      130     113     76
> 4 partitions    84      126     9       7
> 8 partitions    9       12      10      5
>
>
>
>
>
>
>
>
>

Re: Perf testing flush() - issues found

Posted by Roshan Naik <ro...@hortonworks.com>.
For some reason the HTML formatting is being dropped from my email..
Making it harder to read the measurements table.


On 4/29/15 8:32 PM, "Roshan Naik" <ro...@hortonworks.com> wrote:

>
>@Jay,
>My bad. I mistook the batch.size to be number of messages instead of
>bytes. Below are revised measurements based on computing the batch.size
>in bytes .
>
>@Jun,
>
>   With explicit flush()...  linger should not impact. Isn't it ?
>
>@Wang,
>   Larger batches are not necessarily giving better numbers are you can
>see below.
>
>
>The 2 problems I noted earlier still exist in the batched sync mode
>(using flush() ).
>
>  *   batch.size still seems to play a factor even when set to a larger
>value than the bytes generated by client
>  *   4 & 8 partition see a big slowdown
>
>
>
>Revised measurements for new Producer API:
>
>- All cases...Single threaded, 1k event size
>
>
>Batched SYNC using flus() , acks=1
>
>
>
>
>
>
>
>
>
>
>        1 partition
>
>
>
>
>
>
>        Batch=4k        Batch=8k        Batch=16k
>
>
>        batch.size == clientBatch       140
>        124
>
>
>        batch.size = 10MB       140     123     124
>
>
>        batch.Size = 20MB       31      30      42
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>        4 partitions
>
>
>
>
>
>
>        Batch=4k        Batch=8k        Batch=16k
>
>
>        batch.size == clientBatch       60      8       6
>
>
>        batch.size = 10M        7       7       7
>
>
>        batch.Size = 20M        6       6       5
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>        8 partitions
>
>
>
>
>
>
>        Batch=4k        Batch=8k        Batch=16k
>
>
>        batch.size == clientBatch       7       8       8
>
>
>        batch.size = 10M        7       8       7
>
>
>        batch.Size = 20M        6       6       6
>
>
>
>Just for reference I also took the number for  default ASYNC mode with
>acks=1 :
>
>
>
>
>
>
>        batch.size=deafult      batch.size=4MB  batch.size=8MB
>batch.size=16MB
>1 partition     53      130     113     76
>4 partitions    84      126     9       7
>8 partitions    9       12      10      5
>
>
>
>
>
>
>
>


Re: Perf testing flush() - issues found

Posted by Roshan Naik <ro...@hortonworks.com>.
@Jay,
My bad. I mistook the batch.size to be number of messages instead of bytes. Below are revised measurements based on computing the batch.size in bytes .

@Jun,

   With explicit flush()...  linger should not impact. Isn't it ?

@Wang,
   Larger batches are not necessarily giving better numbers are you can see below.


The 2 problems I noted earlier still exist in the batched sync mode (using flush() ).

  *   batch.size still seems to play a factor even when set to a larger value than the bytes generated by client
  *   4 & 8 partition see a big slowdown



Revised measurements for new Producer API:

- All cases...Single threaded, 1k event size


Batched SYNC using flus() , acks=1










        1 partition






        Batch=4k        Batch=8k        Batch=16k


        batch.size == clientBatch       140
        124


        batch.size = 10MB       140     123     124


        batch.Size = 20MB       31      30      42




















        4 partitions






        Batch=4k        Batch=8k        Batch=16k


        batch.size == clientBatch       60      8       6


        batch.size = 10M        7       7       7


        batch.Size = 20M        6       6       5




















        8 partitions






        Batch=4k        Batch=8k        Batch=16k


        batch.size == clientBatch       7       8       8


        batch.size = 10M        7       8       7


        batch.Size = 20M        6       6       6



Just for reference I also took the number for  default ASYNC mode with acks=1 :






        batch.size=deafult      batch.size=4MB  batch.size=8MB  batch.size=16MB
1 partition     53      130     113     76
4 partitions    84      126     9       7
8 partitions    9       12      10      5









Re: Perf testing flush() - issues found

Posted by Guozhang Wang <wa...@gmail.com>.
Just to add to Jun's suggestion:

1. since the batch.size config is per-partition, with for example 4K
messages * 1K message size between flush() and batch.size set to 4Mb, then
with 8 partition, by the time of flush() each partition will get 0.5Mb
only, meaning you may not be batching sufficiently to get best performance.

2. with one partition, then the throughput is mainly dependent on the
"actual" batch size, since the semantics of batch.size config is that if
this amount of bytes has been accumulated, then send out the request right
away. So case B outperforming case A makes sense as it will batch more data
before sending out the request.

Guozhang

On Wed, Apr 29, 2015 at 8:57 AM, Jay Kreps <ja...@gmail.com> wrote:

> Just want to confirm that when you say batch.size and number of records
> will be equal you don't mean that literally. The batch.size is in bytes so
> if you wanted a batch size of 16 1k messages for a single partition then
> you are setting batch.size=16*1024.
>
> -Jay
>
> On Tue, Apr 28, 2015 at 5:58 PM, Roshan Naik <ro...@hortonworks.com>
> wrote:
>
> > Based on recent suggestion by Joel, I am experimenting with using flush()
> > to simulate  batched-sync behavior.
> > The essence of my  single threaded producer code is :
> >
> >     for (int i = 0; i < numRecords;) {
> >         // 1- Send a batch
> >         for(int batchCounter=0; batchCounter<batchSz; ++batchCounter) {
> >             Future<RecordMetadata> f =  producer.send(record, null);
> >             futureList.add(f);
> >             i++;
> >         }
> >         // 2- Flush after sending batch
> >         producer.flush();
> >
> >         // 3- Ensure all msgs were send
> >         for( Future<RecordMetadata> f : futureList) {
> >             f.get();
> >         }
> >     }
> >
> > There are actually two batch size in play here. One is the number of
> > messages between every flush() call made by the client. The other is the
> > batch.size  setting which impacts the batching internally done by the
> > underlying Async api.
> >
> > Intuitively  .. we either want to
> >   A) Set both batch sizes to be Equal, OR
> >   B) Set the underlying batch.size to a sufficiently large number so as
> to
> > effectively disable internal batch management
> >
> >
> > Below numbers are in MB/s.  The 'Batch' column indicate the number of
> > events between each explicit client flush()
> > Setup is 1-node broker and acks=1.
> >
> >                 1 partition
> >                 Batch=4k        Batch=8k        Batch=16k
> > Equal batchSizes (a)    16      32      52
> > large batch.Size (b)    140     123     124
> >
> >                 4 partitions
> >                 Batch=4k        Batch=8k        Batch=16k
> > Equal batchSz (a)       35      61      82
> > large batch.size (b)    7       7       7
> >                 8 partitions
> >                 Batch=4k        Batch=8k        Batch=16k
> > Equal batchSz (a)               49      70      99
> > large batch.size (b)    7       8       7
> >
> >
> > There are two issues noticeable in these number:
> > 1 - Case A is much faster than case B for 4 and 8 partitions.
> > 2 - Single partition mode outperforms all others and here case B is
> faster
> > than case A.
> >
> >
> >
> >
> > Side Note: I used the  client APIs  from the trunk while the broker is
> > running 0.8.2 (I don't think it matters, but nevertheless wanted to point
> > out)
> >
> >
>



-- 
-- Guozhang

Re: Perf testing flush() - issues found

Posted by Jay Kreps <ja...@gmail.com>.
Just want to confirm that when you say batch.size and number of records
will be equal you don't mean that literally. The batch.size is in bytes so
if you wanted a batch size of 16 1k messages for a single partition then
you are setting batch.size=16*1024.

-Jay

On Tue, Apr 28, 2015 at 5:58 PM, Roshan Naik <ro...@hortonworks.com> wrote:

> Based on recent suggestion by Joel, I am experimenting with using flush()
> to simulate  batched-sync behavior.
> The essence of my  single threaded producer code is :
>
>     for (int i = 0; i < numRecords;) {
>         // 1- Send a batch
>         for(int batchCounter=0; batchCounter<batchSz; ++batchCounter) {
>             Future<RecordMetadata> f =  producer.send(record, null);
>             futureList.add(f);
>             i++;
>         }
>         // 2- Flush after sending batch
>         producer.flush();
>
>         // 3- Ensure all msgs were send
>         for( Future<RecordMetadata> f : futureList) {
>             f.get();
>         }
>     }
>
> There are actually two batch size in play here. One is the number of
> messages between every flush() call made by the client. The other is the
> batch.size  setting which impacts the batching internally done by the
> underlying Async api.
>
> Intuitively  .. we either want to
>   A) Set both batch sizes to be Equal, OR
>   B) Set the underlying batch.size to a sufficiently large number so as to
> effectively disable internal batch management
>
>
> Below numbers are in MB/s.  The 'Batch' column indicate the number of
> events between each explicit client flush()
> Setup is 1-node broker and acks=1.
>
>                 1 partition
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSizes (a)    16      32      52
> large batch.Size (b)    140     123     124
>
>                 4 partitions
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSz (a)       35      61      82
> large batch.size (b)    7       7       7
>                 8 partitions
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSz (a)               49      70      99
> large batch.size (b)    7       8       7
>
>
> There are two issues noticeable in these number:
> 1 - Case A is much faster than case B for 4 and 8 partitions.
> 2 - Single partition mode outperforms all others and here case B is faster
> than case A.
>
>
>
>
> Side Note: I used the  client APIs  from the trunk while the broker is
> running 0.8.2 (I don't think it matters, but nevertheless wanted to point
> out)
>
>

Re: Perf testing flush() - issues found

Posted by Roshan Naik <ro...@hortonworks.com>.
- Event size = 1kB.
- broker and client running on different machines (identical config, 32
cores, 256GB ram, 6x 1500rpm disk, 10gigEhernet)
- Don't readily have number for old batch sync API for the same params.
But can get it soon. However .. does it matter ?



-roshan






On 4/28/15 6:57 PM, "Joel Koshy" <jj...@gmail.com> wrote:

>- What is the record size?
>- Is this a local setup? i.e., producer/broker running local?
>- Any overrides apart from batch size? E.g., linger time.
>- Can you establish a baseline - with the old producer's sync-send?
>
>Thanks,
>
>Joel
>
>On Wed, Apr 29, 2015 at 12:58:43AM +0000, Roshan Naik wrote:
>> Based on recent suggestion by Joel, I am experimenting with using
>>flush() to simulate  batched-sync behavior.
>> The essence of my  single threaded producer code is :
>> 
>>     for (int i = 0; i < numRecords;) {
>>         // 1- Send a batch
>>         for(int batchCounter=0; batchCounter<batchSz; ++batchCounter) {
>>             Future<RecordMetadata> f =  producer.send(record, null);
>>             futureList.add(f);
>>             i++;
>>         }
>>         // 2- Flush after sending batch
>>         producer.flush();
>> 
>>         // 3- Ensure all msgs were send
>>         for( Future<RecordMetadata> f : futureList) {
>>             f.get();
>>         }
>>     }
>> 
>> There are actually two batch size in play here. One is the number of
>>messages between every flush() call made by the client. The other is the
>> batch.size  setting which impacts the batching internally done by the
>>underlying Async api.
>> 
>> Intuitively  .. we either want to
>>   A) Set both batch sizes to be Equal, OR
>>   B) Set the underlying batch.size to a sufficiently large number so as
>>to effectively disable internal batch management
>> 
>> 
>> Below numbers are in MB/s.  The 'Batch' column indicate the number of
>>events between each explicit client flush()
>> Setup is 1-node broker and acks=1.
>> 
>>                 1 partition
>>                 Batch=4k        Batch=8k        Batch=16k
>> Equal batchSizes (a)    16      32      52
>> large batch.Size (b)    140     123     124
>> 
>>                 4 partitions
>>                 Batch=4k        Batch=8k        Batch=16k
>> Equal batchSz (a)       35      61      82
>> large batch.size (b)    7       7       7
>>                 8 partitions
>>                 Batch=4k        Batch=8k        Batch=16k
>> Equal batchSz (a)               49      70      99
>> large batch.size (b)    7       8       7
>> 
>> 
>> There are two issues noticeable in these number:
>> 1 - Case A is much faster than case B for 4 and 8 partitions.
>> 2 - Single partition mode outperforms all others and here case B is
>>faster than case A.
>> 
>> 
>> 
>> 
>> Side Note: I used the  client APIs  from the trunk while the broker is
>>running 0.8.2 (I don't think it matters, but nevertheless wanted to
>>point out)
>> 
>


Re: Perf testing flush() - issues found

Posted by Joel Koshy <jj...@gmail.com>.
- What is the record size?
- Is this a local setup? i.e., producer/broker running local?
- Any overrides apart from batch size? E.g., linger time.
- Can you establish a baseline - with the old producer's sync-send?

Thanks,

Joel

On Wed, Apr 29, 2015 at 12:58:43AM +0000, Roshan Naik wrote:
> Based on recent suggestion by Joel, I am experimenting with using flush() to simulate  batched-sync behavior.
> The essence of my  single threaded producer code is :
> 
>     for (int i = 0; i < numRecords;) {
>         // 1- Send a batch
>         for(int batchCounter=0; batchCounter<batchSz; ++batchCounter) {
>             Future<RecordMetadata> f =  producer.send(record, null);
>             futureList.add(f);
>             i++;
>         }
>         // 2- Flush after sending batch
>         producer.flush();
> 
>         // 3- Ensure all msgs were send
>         for( Future<RecordMetadata> f : futureList) {
>             f.get();
>         }
>     }
> 
> There are actually two batch size in play here. One is the number of messages between every flush() call made by the client. The other is the  batch.size  setting which impacts the batching internally done by the underlying Async api.
> 
> Intuitively  .. we either want to
>   A) Set both batch sizes to be Equal, OR
>   B) Set the underlying batch.size to a sufficiently large number so as to effectively disable internal batch management
> 
> 
> Below numbers are in MB/s.  The 'Batch' column indicate the number of events between each explicit client flush()
> Setup is 1-node broker and acks=1.
> 
>                 1 partition
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSizes (a)    16      32      52
> large batch.Size (b)    140     123     124
> 
>                 4 partitions
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSz (a)       35      61      82
> large batch.size (b)    7       7       7
>                 8 partitions
>                 Batch=4k        Batch=8k        Batch=16k
> Equal batchSz (a)               49      70      99
> large batch.size (b)    7       8       7
> 
> 
> There are two issues noticeable in these number:
> 1 - Case A is much faster than case B for 4 and 8 partitions.
> 2 - Single partition mode outperforms all others and here case B is faster than case A.
> 
> 
> 
> 
> Side Note: I used the  client APIs  from the trunk while the broker is running 0.8.2 (I don't think it matters, but nevertheless wanted to point out)
>