Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kafka Benchmark Commands
Producer
Setup
bin/kafka-topics.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --create --topic test-rep-one --partitions 6 --replication-factor 1
bin/kafka-topics.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --create --topic test --partitions 6 --replication-factor 3
Single thread, no replication
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test7 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196
Single-thread, async 3x replication
bin/kafktopics.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --create --topic test --partitions 6 --replication-factor 3
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test6 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196
Single-thread, sync 3x replication
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test 50000000 100 -1 acks=-1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=64000
Three Producers, 3x async replication
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196
Throughput Versus Stored Data
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test 50000000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196
Effect of message size
for i in 10 100 1000 10000 100000;
do
echo ""
echo $i
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test $((1000*1024*1024/$i)) $i -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=128000
done;
Consumer
Consumer throughput
bin/kafka-consumer-perf-test.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --messages 50000000 --topic test --threads 1
3 Consumers
On three servers, run:
bin/kafka-consumer-perf-test.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --messages 50000000 --topic test --threads 1
End-to-end Latency
bin/kafka-run-class.sh kafka.tools.TestEndToEndLatency esv4-hcl198.grid.linkedin.com:9092 esv4-hcl197.grid.linkedin.com:2181 test 5000
Producer and consumer
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196
bin/kafka-consumer-perf-test.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --messages 50000000 --topic test --threads 1
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# see kafka.server.KafkaConfig for additional details and defaults
############################# Server Basics #############################
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
############################# Socket Server Settings #############################
# The port the socket server listens on
port=9092
# Hostname the broker will bind to and advertise to producers and consumers.
# If not set, the server will bind to all interfaces and advertise the value returned from
# from java.net.InetAddress.getCanonicalHostName().
#host.name=localhost
# The number of threads handling network requests
num.network.threads=4
# The number of threads doing disk I/O
num.io.threads=8
# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=1048576
# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=1048576
# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600
############################# Log Basics #############################
# The directory under which to store log files
log.dirs=/grid/a/dfs-data/kafka-logs,/grid/b/dfs-data/kafka-logs,/grid/c/dfs-data/kafka-logs,/grid/d/dfs-data/kafka-logs,/grid/e/dfs-data/kafka-logs,/grid/f/dfs-data/kafka-logs
# The number of logical partitions per topic per server. More partitions allow greater parallelism
# for consumption, but also mean more files.
num.partitions=8
############################# Log Flush Policy #############################
# The following configurations control the flush of data to disk. This is the most
# important performance knob in kafka.
# There are a few important trade-offs here:
# 1. Durability: Unflushed data is at greater risk of loss in the event of a crash.
# 2. Latency: Data is not made available to consumers until it is flushed (which adds latency).
# 3. Throughput: The flush is generally the most expensive operation.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.
# Per-topic overrides for log.flush.interval.ms
#log.flush.intervals.ms.per.topic=topic1:1000, topic2:3000
############################# Log Retention Policy #############################
# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.
# The minimum age of a log file to be eligible for deletion
log.retention.hours=168
# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824
# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=536870912
# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.cleanup.interval.mins=1
############################# Zookeeper #############################
# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=esv4-hcl197.grid.linkedin.com:2181
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=1000000
# metrics reporter properties
kafka.metrics.polling.interval.secs=5
kafka.metrics.reporters=kafka.metrics.KafkaCSVMetricsReporter
kafka.csv.metrics.dir=/tmp/kafka_metrics
# Disable csv reporting by default.
kafka.csv.metrics.reporter.enabled=false
replica.lag.max.messages=10000000
@viper25

This comment has been minimized.

Show comment
Hide comment
@viper25

viper25 Jun 22, 2014

Where can one get the org.apache.kafka.clients.tools.ProducerPerformance classes?

viper25 commented Jun 22, 2014

Where can one get the org.apache.kafka.clients.tools.ProducerPerformance classes?

@baransn

This comment has been minimized.

Show comment
Hide comment
@baransn

baransn Jun 24, 2014

I downloaded the sources, unpacked, and built the classes with this command:
cd (untar'ed directory)
./gradlew clean && ./gradlew jar && ./gradlew releaseTarGz -x signArchives

from there you can run the commands

baransn commented Jun 24, 2014

I downloaded the sources, unpacked, and built the classes with this command:
cd (untar'ed directory)
./gradlew clean && ./gradlew jar && ./gradlew releaseTarGz -x signArchives

from there you can run the commands

@thecrazymonkey

This comment has been minimized.

Show comment
Hide comment
@thecrazymonkey

thecrazymonkey Jun 27, 2014

Hi Jay,
can you please share your producer and consumer properties as well as OS version and any tuning done to the default installation.
Thanks,
Ivan

thecrazymonkey commented Jun 27, 2014

Hi Jay,
can you please share your producer and consumer properties as well as OS version and any tuning done to the default installation.
Thanks,
Ivan

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 3, 2014

Quick ? - I built kafka-0.8.1.1-src - when I run the first test "single thread, no replication" I see the following:

USAGE: java org.apache.kafka.clients.tools.ProducerPerformance url num_records record_size

I am using this syntax:

/var/tmp/kafka-0.8.1.1-src/bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test7 50000000 100 -1 acks=1 bootstrap.servers=dojo3s20006.rtp1.hadoop.corp.com:9092 buffer.memory=67108864 batch.size=8196

Is this not the correct version?

ghost commented Jul 3, 2014

Quick ? - I built kafka-0.8.1.1-src - when I run the first test "single thread, no replication" I see the following:

USAGE: java org.apache.kafka.clients.tools.ProducerPerformance url num_records record_size

I am using this syntax:

/var/tmp/kafka-0.8.1.1-src/bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test7 50000000 100 -1 acks=1 bootstrap.servers=dojo3s20006.rtp1.hadoop.corp.com:9092 buffer.memory=67108864 batch.size=8196

Is this not the correct version?

@garlicbulbxian

This comment has been minimized.

Show comment
Hide comment
@garlicbulbxian

garlicbulbxian Jul 8, 2014

What is the major difference between org.apache.kafka.clients.producer.Producer and regular Producer like kafka.javaapi.producer.Producer? What makes the former getting much more throughput.

garlicbulbxian commented Jul 8, 2014

What is the major difference between org.apache.kafka.clients.producer.Producer and regular Producer like kafka.javaapi.producer.Producer? What makes the former getting much more throughput.

@kondratovich

This comment has been minimized.

Show comment
Hide comment
@kondratovich

kondratovich Aug 20, 2014

On trunk (commit a30491ac5d3fc5967e8c4b16c68bdbfc312748f5) we have broken consumer test.

Consumer show zero stats and on brokers we have the next error:

[2014-08-20 11:41:33,614] ERROR Closing socket for /10.209.22.11 because of error (kafka.network.Processor)
java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
        at sun.nio.ch.IOUtil.read(IOUtil.java:197)
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
        at kafka.utils.Utils$.read(Utils.scala:380)
        at kafka.network.BoundedByteBufferReceive.readFrom(BoundedByteBufferReceive.scala:54)
        at kafka.network.Processor.read(SocketServer.scala:408)
        at kafka.network.Processor.run(SocketServer.scala:314)
        at java.lang.Thread.run(Thread.java:745)

kondratovich commented Aug 20, 2014

On trunk (commit a30491ac5d3fc5967e8c4b16c68bdbfc312748f5) we have broken consumer test.

Consumer show zero stats and on brokers we have the next error:

[2014-08-20 11:41:33,614] ERROR Closing socket for /10.209.22.11 because of error (kafka.network.Processor)
java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
        at sun.nio.ch.IOUtil.read(IOUtil.java:197)
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
        at kafka.utils.Utils$.read(Utils.scala:380)
        at kafka.network.BoundedByteBufferReceive.readFrom(BoundedByteBufferReceive.scala:54)
        at kafka.network.Processor.read(SocketServer.scala:408)
        at kafka.network.Processor.run(SocketServer.scala:314)
        at java.lang.Thread.run(Thread.java:745)
@shek007

This comment has been minimized.

Show comment
Hide comment
@shek007

shek007 Apr 20, 2015

What is the default location of kafka-topics.sh?

shek007 commented Apr 20, 2015

What is the default location of kafka-topics.sh?

@KalpeshJ

This comment has been minimized.

Show comment
Hide comment
@KalpeshJ

KalpeshJ May 14, 2015

inside bin folder

KalpeshJ commented May 14, 2015

inside bin folder

@yuhengd

This comment has been minimized.

Show comment
Hide comment
@yuhengd

yuhengd Jul 13, 2015

Hi Jay,

Does the ProducerPerformance class still works? I tried to run the command:
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test7 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196

and I got the following error:
Error: Could not find or load main class org.apache.kafka.client.tools.ProducerPerformance

What should I fix? Thank you!

yuhengd commented Jul 13, 2015

Hi Jay,

Does the ProducerPerformance class still works? I tried to run the command:
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test7 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196

and I got the following error:
Error: Could not find or load main class org.apache.kafka.client.tools.ProducerPerformance

What should I fix? Thank you!

@Evildethow

This comment has been minimized.

Show comment
Hide comment
@Evildethow

Evildethow Aug 24, 2015

Hey @yuhengd

From kafka base directory:

./gradlew jarAll -x signArchives -x test -x javadoc -x scaladoc

That should build kafka-tools, which is where ProducerPerformance.class gets loaded from.

Evildethow commented Aug 24, 2015

Hey @yuhengd

From kafka base directory:

./gradlew jarAll -x signArchives -x test -x javadoc -x scaladoc

That should build kafka-tools, which is where ProducerPerformance.class gets loaded from.

@AgustinCB

This comment has been minimized.

Show comment
Hide comment
@AgustinCB

AgustinCB Sep 28, 2015

On lines 9 and 14, it uses topics test6 and test7 which weren't created previously, so they won't probably have the expected replication factor.

The results on the article are made with that mistake in the commands?

AgustinCB commented Sep 28, 2015

On lines 9 and 14, it uses topics test6 and test7 which weren't created previously, so they won't probably have the expected replication factor.

The results on the article are made with that mistake in the commands?

@b-slim

This comment has been minimized.

Show comment
Hide comment
@b-slim

b-slim Nov 11, 2015

Hi Guys i am wondering if you have any idea about the impact of batch.size on the overall performance ?
i am guessing increasing it to the order of 1MB would increase the throughput ?

b-slim commented Nov 11, 2015

Hi Guys i am wondering if you have any idea about the impact of batch.size on the overall performance ?
i am guessing increasing it to the order of 1MB would increase the throughput ?

@jianghaitao

This comment has been minimized.

Show comment
Hide comment
@jianghaitao

jianghaitao Jan 20, 2016

It would be nice that topics created in the setup: test and test-rep-one can be explained as how they are used in the later tests. This is not obvious. Also, how the batch size 8K v.s 60K was chosen. Finally on line 21, how do we know 3 threads were used?

jianghaitao commented Jan 20, 2016

It would be nice that topics created in the setup: test and test-rep-one can be explained as how they are used in the later tests. This is not obvious. Also, how the batch size 8K v.s 60K was chosen. Finally on line 21, how do we know 3 threads were used?

@ssinganamalla

This comment has been minimized.

Show comment
Hide comment
@ssinganamalla

ssinganamalla Mar 2, 2016

You could run the benchmark tests out of the box without building it first in 0.9. Note the difference in the package name for ProducerPerformance

bin/kafka-run-class.sh org.apache.kafka.tools.ProducerPerformance --topic first --num-records 50000000 --record-size 100 --throughput -1 --producer-props acks=1 bootstrap.servers=localhost:9092 buffer.memory=67108864 batch.size=8196

ssinganamalla commented Mar 2, 2016

You could run the benchmark tests out of the box without building it first in 0.9. Note the difference in the package name for ProducerPerformance

bin/kafka-run-class.sh org.apache.kafka.tools.ProducerPerformance --topic first --num-records 50000000 --record-size 100 --throughput -1 --producer-props acks=1 bootstrap.servers=localhost:9092 buffer.memory=67108864 batch.size=8196

@glory5

This comment has been minimized.

Show comment
Hide comment
@glory5

glory5 Apr 1, 2016

@ssinganamalla will you plz provide mi script for local machine bechmark test?

glory5 commented Apr 1, 2016

@ssinganamalla will you plz provide mi script for local machine bechmark test?

@ToniYang

This comment has been minimized.

Show comment
Hide comment
@ToniYang

ToniYang Jun 14, 2016

kafka version is lastest
Error: Could not find or load main class test7

mybe is the test file can not work in lastest version kafka.
Does the file need update?

ToniYang commented Jun 14, 2016

kafka version is lastest
Error: Could not find or load main class test7

mybe is the test file can not work in lastest version kafka.
Does the file need update?

@gaurav6351

This comment has been minimized.

Show comment
Hide comment
@gaurav6351

gaurav6351 Nov 15, 2016

can we pass file instead of message size for producer perf test , which have my real time data.?

gaurav6351 commented Nov 15, 2016

can we pass file instead of message size for producer perf test , which have my real time data.?

@dskarbek

This comment has been minimized.

Show comment
Hide comment
@dskarbek

dskarbek Mar 15, 2017

Would be great to have an updated version of this for latest version of Kafka. I've got kafka_2.11-0.10.20.0, and bin/kafka-run-class.sh kafka.tools.TestEndToEndLatency can't find the class. Is it renamed? Do I have to do something to get it? A previous comment mentioned running gradlew from the top directory, but that is not present either. I see the consumer and producer performance test scripts in the bin directory, but I want to run the end to end performance test and there doesn't seem to be a script for that.

dskarbek commented Mar 15, 2017

Would be great to have an updated version of this for latest version of Kafka. I've got kafka_2.11-0.10.20.0, and bin/kafka-run-class.sh kafka.tools.TestEndToEndLatency can't find the class. Is it renamed? Do I have to do something to get it? A previous comment mentioned running gradlew from the top directory, but that is not present either. I see the consumer and producer performance test scripts in the bin directory, but I want to run the end to end performance test and there doesn't seem to be a script for that.

@csaroff

This comment has been minimized.

Show comment
Hide comment
@csaroff

csaroff Oct 6, 2017

After what seems like way too long I figured it out. Looks like it's actually named EndToEndLatency. The above command should be

bin/kafka-run-class.sh kafka.tools.EndToEndLatency

in the root of the project. Strangely, neither command worked for me in kafka 0.8.1. I kept getting the "Could not find or load main class" error.

Just in case anyone else is having trouble running the latency tests, try version 0.11.0.1(kafka_2.11-0.11.0.1.tgz) and use class EndToEndLatency instead of TestEndToEndLatency.

csaroff commented Oct 6, 2017

After what seems like way too long I figured it out. Looks like it's actually named EndToEndLatency. The above command should be

bin/kafka-run-class.sh kafka.tools.EndToEndLatency

in the root of the project. Strangely, neither command worked for me in kafka 0.8.1. I kept getting the "Could not find or load main class" error.

Just in case anyone else is having trouble running the latency tests, try version 0.11.0.1(kafka_2.11-0.11.0.1.tgz) and use class EndToEndLatency instead of TestEndToEndLatency.

@Hallomann93

This comment has been minimized.

Show comment
Hide comment
@Hallomann93

Hallomann93 Dec 7, 2017

Where do I find the source of the consumer test? In the kafka-consumer-perf-test.sh the class is kafka.tools.ConsumerPerformance I don't find this one in the sources, only as a compiled .class file. I would like to look at the insides, but can't locate the .java, it isn't in the same package as the org.apache.kafka.tools.ProducerPerformance.

Hallomann93 commented Dec 7, 2017

Where do I find the source of the consumer test? In the kafka-consumer-perf-test.sh the class is kafka.tools.ConsumerPerformance I don't find this one in the sources, only as a compiled .class file. I would like to look at the insides, but can't locate the .java, it isn't in the same package as the org.apache.kafka.tools.ProducerPerformance.

@Jane870103

This comment has been minimized.

Show comment
Hide comment
@Jane870103

Jane870103 Dec 21, 2017

how can we change the number of producers?

Jane870103 commented Dec 21, 2017

how can we change the number of producers?

@ZhijiaYang

This comment has been minimized.

Show comment
Hide comment
@ZhijiaYang

ZhijiaYang Jan 26, 2018

"how can we change the number of producers?"

just run it in three diff machine.

Detail in this blog: https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines

ZhijiaYang commented Jan 26, 2018

"how can we change the number of producers?"

just run it in three diff machine.

Detail in this blog: https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines

@nahdukesaba

This comment has been minimized.

Show comment
Hide comment
@nahdukesaba

nahdukesaba Mar 5, 2018

@jkreps could you please update the code using the latest kafka released?

nahdukesaba commented Mar 5, 2018

@jkreps could you please update the code using the latest kafka released?

@zodvik

This comment has been minimized.

Show comment
Hide comment

zodvik commented Mar 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment