Kafka性能テストのproduce

9368 ワード

kafkaのbinディレクトリの下には、kafka-producer-perf-testの2つのスクリプトがあります.shとkafka-consumer-perf-test.sh,この2つのスクリプトの役割は,生産者と消費者をテストするために用いられる.
[root@hostname bin]# ./kafka-producer-perf-test.sh --help
usage: producer-performance [-h] --topic TOPIC --num-records NUM-RECORDS [--payload-delimiter PAYLOAD-DELIMITER] --throughput THROUGHPUT
                            [--producer-props PROP-NAME=PROP-VALUE [PROP-NAME=PROP-VALUE ...]] [--producer.config CONFIG-FILE] (--record-size RECORD-SIZE |
                            --payload-file PAYLOAD-FILE)

This tool is used to verify the producer performance.

optional arguments:
  -h, --help             show this help message and exit
  --topic TOPIC          produce messages to this topic
  --num-records NUM-RECORDS
                         number of messages to produce
  --payload-delimiter PAYLOAD-DELIMITER
                         provides delimiter to be used when --payload-file is  provided.  Defaults  to  new  line.  Note  that this parameter will be ignored if --
                         payload-file is not provided. (default: 
) --throughput THROUGHPUT throttle maximum message throughput to *approximately* THROUGHPUT messages/sec --producer-props PROP-NAME=PROP-VALUE [PROP-NAME=PROP-VALUE ...] kafka producer related configuration properties like bootstrap.servers,client.id etc. These configs take precedence over those passed via --producer.config. --producer.config CONFIG-FILE producer config properties file. either --record-size or --payload-file must be specified but not both. --record-size RECORD-SIZE message size in bytes. Note that you must provide exactly one of --record-size or --payload-file. --payload-file PAYLOAD-FILE file to read the message payloads from. This works only for UTF-8 encoded text files. Payloads will be read from this file and a payload will be randomly selected when sending messages. Note that you must provide exactly one of --record-size or --payload-file.

helpコマンドにより、関連パラメータおよびパラメータの意味がわかります.
[root@hadoop-sh1-core1 bin]# ./kafka-topics.sh --zookeeper hadoop-sh1-master2:2181 --topic "test003" --describe                                
Topic:test003   PartitionCount:3        ReplicationFactor:1     Configs:
        Topic: test003  Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: test003  Partition: 1    Leader: 1       Replicas: 1     Isr: 1
        Topic: test003  Partition: 2    Leader: 2       Replicas: 2     Isr: 2
        

[root@hadoop-sh1-core1 bin]# ./kafka-producer-perf-test.sh --topic test003 --num-records 1000000 --record-size 1024  --throughput -1 --producer.config ../config/producer.properties
[2018-07-02 14:29:03,086] WARN Error while fetching metadata with correlation id 1 : {test003=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
250992 records sent, 50198.4 records/sec (49.02 MB/sec), 425.2 ms avg latency, 1167.0 max latency.
526995 records sent, 103616.8 records/sec (101.19 MB/sec), 266.2 ms avg latency, 1080.0 max latency.
1000000 records sent, 83998.320034 records/sec (82.03 MB/sec), 317.24 ms avg latency, 1314.00 ms max latency, 259 ms 50th, 868 ms 95th, 1212 ms 99th, 1228 ms 99.9th.

スループットを制限せず、3つのpartitionのtopic、3つのバックアップ、ack=allの場合、最高101.19 MB/secの速度に達し、平均遅延は200以上400以上、最高遅延は1228 msである.
topicパラメータ(または3台のマシン)を調整し、topicのpartition数を10に引き上げ、バックアップ数を1に下げるか、スループットを制限しないか
Created topic "test004".
[root@hadoop-sh1-core1 bin]# ./kafka-topics.sh --zookeeper hadoop-sh1-master2:2181 --topic "test004" --describe                                                         Topic:test004   PartitionCount:10       ReplicationFactor:1     Configs:
        Topic: test004  Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: test004  Partition: 1    Leader: 1       Replicas: 1     Isr: 1
        Topic: test004  Partition: 2    Leader: 2       Replicas: 2     Isr: 2
        Topic: test004  Partition: 3    Leader: 3       Replicas: 3     Isr: 3
        Topic: test004  Partition: 4    Leader: 0       Replicas: 0     Isr: 0
        Topic: test004  Partition: 5    Leader: 1       Replicas: 1     Isr: 1
        Topic: test004  Partition: 6    Leader: 2       Replicas: 2     Isr: 2
        Topic: test004  Partition: 7    Leader: 3       Replicas: 3     Isr: 3
        Topic: test004  Partition: 8    Leader: 0       Replicas: 0     Isr: 0
        Topic: test004  Partition: 9    Leader: 1       Replicas: 1     Isr: 1
        
[root@hadoop-sh1-core1 bin]# ./kafka-producer-perf-test.sh --topic test004 --num-records 1000000 --record-size 1024  --throughput -1 --producer.config ../config/producer.properties
525946 records sent, 105189.2 records/sec (102.72 MB/sec), 209.1 ms avg latency, 1107.0 max latency.
1000000 records sent, 114155.251142 records/sec (111.48 MB/sec), 226.50 ms avg latency, 1203.00 ms max latency, 152 ms 50th, 1007 ms 95th, 1191 ms 99th, 1196 ms 99.9th.        

平均遅延と最大遅延、スループットが大幅に上昇していることがわかります.まだ3台の機械しかないので、スループットは100 M以上毎秒にしかならない可能性があります.これ以上増加しても向上するかどうか分かりません.
それとも3つのpartiton、3つのバックアップ、スループットを1 wに下げて、テストの状況を見てみましょう
[root@hadoop-sh1-core1 bin]# ./kafka-producer-perf-test.sh --topic test003 --num-records 1000000 --record-size 1024  --throughput 10000 --producer.config ../config/producer.properties
49979 records sent, 9995.8 records/sec (9.76 MB/sec), 1.4 ms avg latency, 203.0 max latency.
50043 records sent, 10008.6 records/sec (9.77 MB/sec), 0.6 ms avg latency, 18.0 max latency.
49973 records sent, 9994.6 records/sec (9.76 MB/sec), 0.7 ms avg latency, 41.0 max latency.
50057 records sent, 10009.4 records/sec (9.77 MB/sec), 0.5 ms avg latency, 23.0 max latency.
50002 records sent, 10000.4 records/sec (9.77 MB/sec), 0.6 ms avg latency, 46.0 max latency.
50015 records sent, 10003.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 24.0 max latency.
49993 records sent, 9996.6 records/sec (9.76 MB/sec), 0.6 ms avg latency, 47.0 max latency.
50010 records sent, 10000.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 26.0 max latency.
50015 records sent, 10003.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 26.0 max latency.
50005 records sent, 10001.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 19.0 max latency.
50010 records sent, 10002.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 24.0 max latency.
50010 records sent, 10002.0 records/sec (9.77 MB/sec), 0.5 ms avg latency, 18.0 max latency.
50010 records sent, 10002.0 records/sec (9.77 MB/sec), 0.5 ms avg latency, 23.0 max latency.
50000 records sent, 10000.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 23.0 max latency.
50016 records sent, 10003.2 records/sec (9.77 MB/sec), 0.6 ms avg latency, 31.0 max latency.
49994 records sent, 9998.8 records/sec (9.76 MB/sec), 0.6 ms avg latency, 29.0 max latency.
50010 records sent, 10002.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 21.0 max latency.
50010 records sent, 10002.0 records/sec (9.77 MB/sec), 0.6 ms avg latency, 21.0 max latency.
50019 records sent, 10001.8 records/sec (9.77 MB/sec), 0.6 ms avg latency, 32.0 max latency.
1000000 records sent, 9999.200064 records/sec (9.76 MB/sec), 0.61 ms avg latency, 203.00 ms max latency, 1 ms 50th, 1 ms 95th, 2 ms 99th, 19 ms 99.9th.

平均遅延は0.6 msに低下し,最大遅延は数十ms以内であった.
次にrecord sizeのサイズを調整し、影響を及ぼすかどうかを確認します.
[root@hadoop-sh1-core1 bin]# ./kafka-producer-perf-test.sh --topic test004 --num-records 1000000 --record-size 258  --throughput -1 --producer.config ../config/producer.properties
1000000 records sent, 323519.896474 records/sec (79.60 MB/sec), 4.77 ms avg latency, 210.00 ms max latency, 3 ms 50th, 18 ms 95th, 39 ms 99th, 46 ms 99.9th.


[root@hadoop-sh1-core1 bin]# ./kafka-producer-perf-test.sh --topic test004 --num-records 1000000 --record-size 1024  --throughput -1 --producer.config ../config/producer.properties
525946 records sent, 105189.2 records/sec (102.72 MB/sec), 209.1 ms avg latency, 1107.0 max latency.
1000000 records sent, 114155.251142 records/sec (111.48 MB/sec), 226.50 ms avg latency, 1203.00 ms max latency, 152 ms 50th, 1007 ms 95th, 1191 ms 99th, 1196 ms 99.9th.


[root@hadoop-sh1-core1 bin]# ./kafka-producer-perf-test.sh --topic test004 --num-records 10000000 --record-size 258  --throughput -1 --producer.config ../config/producer.properties
1949374 records sent, 389874.8 records/sec (95.93 MB/sec), 3.6 ms avg latency, 212.0 max latency.
2392851 records sent, 478570.2 records/sec (117.75 MB/sec), 2.3 ms avg latency, 21.0 max latency.
2372680 records sent, 474536.0 records/sec (116.76 MB/sec), 2.4 ms avg latency, 26.0 max latency.
2362539 records sent, 472507.8 records/sec (116.26 MB/sec), 2.3 ms avg latency, 24.0 max latency.
10000000 records sent, 455435.624175 records/sec (112.06 MB/sec), 2.54 ms avg latency, 212.00 ms max latency, 2 ms 50th, 4 ms 95th, 10 ms 99th, 20 ms 99.9th.

両者を比較すると、sizeは1024から258に下がり、性能が著しく向上し、遅延が少なくなった.3つ目は、recordsの数を1000 wに上昇させた.遅延は上昇対少ではなく、スループットは110 M以上に安定していることが分かった.3台の機械のボトルネックはこれだけかもしれない.
以上のテストの結論から,kafkaのproduce効率は,record sizeサイズ,partition数,バックアップ数,ackの値などと関係があることが分かった.(もちろん、1台の機器の性能にも若干の関係があります._)