发布时间:2020-02-16 19:05:30编辑:admin阅读(2580)
线上已经有kafka集群,服务运行稳定。但是因为产品升级,需要对kakfa做安全测试,也就是权限验证。
但是增加权限验证,会不会对性能有影响呢?影响大吗?不知道呀!
因此,本文就此来做一下对比!
本文使用的是单机kafka测试,仅在一台服务器做测试。
使用的kafka版本为kafka_2.12-2.1.0,zk直接使用kafka自带的。
硬件配置为:1(核)-4G内容-40G硬盘
关于普通版的kafka,请参考链接:
https://www.cnblogs.com/xiao987334176/p/10075659.html
里面有关于 kafka_server_test 镜像如何制作!
这里使用的acl设置,仅仅使用write用户来测试。赋予它所有权限,下面会说到!
新建空目录
mkdir /opt/kafka_server_acl
consumer.config
security.protocol=SASL_PLAINTEXT sasl.mechanism=PLAIN group.id=test-group
dockerfile
FROM ubuntu:16.04 # 修改更新源为阿里云 ADD sources.list /etc/apt/sources.list ADD kafka_2.12-2.1.0.tgz / ADD kafka_cluster_jaas.conf / ADD consumer.config /kafka_2.12-2.1.0/config/ ADD producer.config /kafka_2.12-2.1.0/config/ #ADD reader_jaas.conf /kafka_2.12-2.1.0/config/ ADD writer_jaas.conf /kafka_2.12-2.1.0/config/ # 安装jdk RUN apt-get update && apt-get install -y openjdk-8-jdk --allow-unauthenticated && apt-get clean all && \ cd /kafka_2.12-2.1.0 && \ mv /kafka_cluster_jaas.conf config/ && \ sed -i '$ s/^/#&/g' bin/kafka-server-start.sh && \ sed -i '$ a\exec $base_dir/kafka-run-class.sh $EXTRA_ARGS -Djava.security.auth.login.config=/kafka_2.12-2.1.0/config/kafka_cluster_jaas.conf kafka.Kafka "$@"' bin/kafka-server-start.sh EXPOSE 9092 # 添加启动脚本 ADD run.sh . RUN chmod 755 run.sh ENTRYPOINT [ "/run.sh"]
kafka_cluster_jaas.conf
KafkaServer { org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin" user_admin="admin" user_reader="reader" user_writer="writer"; };
producer.config
security.protocol=SASL_PLAINTEXT sasl.mechanism=PLAIN
run.sh
#!/bin/bash # 启动自带的zookeeper cd /kafka_2.12-2.1.0 bin/zookeeper-server-start.sh config/zookeeper.properties & # 启动kafka acl配置 echo " authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer listeners=SASL_PLAINTEXT://:9092 security.inter.broker.protocol= SASL_PLAINTEXT sasl.mechanism.inter.broker.protocol=PLAIN sasl.enabled.mechanisms=PLAIN super.users=User:admin " >> /kafka_2.12-2.1.0/config/server.properties # 进入工作目录 cd /kafka_2.12-2.1.0 # 生产者 # 最后一行注释掉,添加# sed -i '$ s/^/#&/g' bin/kafka-console-producer.sh # 最后一行添加内容 sed -i '$ a\exec $(dirname $0)/kafka-run-class.sh -Djava.security.auth.login.config=/kafka_2.12-2.1.0/config/writer_jaas.conf kafka.tools.ConsoleProducer "$@"' bin/kafka-console-producer.sh # 消费者 sed -i '$ s/^/#&/g' bin/kafka-console-consumer.sh sed -i '$ a\exec $(dirname $0)/kafka-run-class.sh -Djava.security.auth.login.config=/kafka_2.12-2.1.0/config/writer_jaas.conf kafka.tools.ConsoleConsumer "$@"' bin/kafka-console-consumer.sh # 生产者压测脚本 sed -i '$ s/^/#&/g' bin/kafka-producer-perf-test.sh sed -i '$ a\exec $(dirname $0)/kafka-run-class.sh -Djava.security.auth.login.config=/kafka_2.12-2.1.0/config/writer_jaas.conf org.apache.kafka.tools.ProducerPerformance "$@"' bin/kafka-producer-perf-test.sh # 消费者压测脚本 sed -i '$ s/^/#&/g' bin/kafka-consumer-perf-test.sh sed -i '$ a\exec $(dirname $0)/kafka-run-class.sh -Djava.security.auth.login.config=/kafka_2.12-2.1.0/config/writer_jaas.conf kafka.tools.ConsumerPerformance "$@"' bin/kafka-consumer-perf-test.sh # 启动kafka sleep 3 bin/kafka-server-start.sh config/server.properties
注意:默认的kafka压测脚本是针对于普通版的kafka。如果是已经开启了acl验证的kafkfa,运行会直接报错。
因此为了解决这个问题,有2个步骤:
1. 修改压测脚本,最后一行指定参数-Djava.security.auth.login.config
2. 运行脚本时,要增加参数。下文会说到,稍安勿躁!
sources.list
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu xenial-security main restricted deb http://mirrors.aliyun.com/ubuntu xenial-security universe deb http://mirrors.aliyun.com/ubuntu xenial-security multiverse
writer_jaas.conf
KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="writer" password="writer"; };
此时目录结构如下:
./ ├── consumer.config ├── dockerfile ├── kafka_2.12-2.1.0.tgz ├── kafka_cluster_jaas.conf ├── producer.config ├── run.sh ├── sources.list └── writer_jaas.conf
生成镜像
docker build -t kafka_server_acl /opt/kafka_server_acl
启动容器
docker run -it kafka_server_acl
查看docker进程
root@ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4f4c33fd92fa kafka_server_acl "/run.sh" 41 seconds ago Up 40 seconds 9092/tcp eager_goldberg
进入容器
root@ubuntu:~# docker exec -it 4f4c33fd92fa /bin/bashroot@4f4c33fd92fa:/# cd /kafka_2.12-2.1.0/
设置权限
bin/kafka-acls.sh --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:writer --operation All --topic=*
参数解释:
User:writer 表示用户writer
--operation All 操作权限为所有。一般操作权限分为2种,分别是Read和Write。所以All就包含了这2种权限。
--topic=* 表示所有topic
输出:
Adding ACLs for resource `Topic:LITERAL:*`: User:writer has Allow permission for operations: All from hosts: * Current ACLs for resource `Topic:LITERAL:*`: User:writer has Allow permission for operations: All from hosts: *
允许writer用户的所有组操作。一般在java代码中,组名是不固定的。有些是动态生成的,所以直接*
bin/kafka-acls.sh --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=localhost:2181 --add --allow-principal User:writer --operation All -group=*
注意:topic和grop权限,不能一条命令设置,需要分2条命令执行才行!
输出:
Adding ACLs for resource `Group:LITERAL:*`: User:writer has Allow permission for operations: All from hosts: * Current ACLs for resource `Group:LITERAL:*`: User:writer has Allow permission for operations: All from hosts: *
创建测试topic,名为test
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
进入生产者模式
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.config
进入消费者模式
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --consumer.config config/consumer.config
在生产者模式输入234
>234
消费者模式如果收到234,说明acl运行正常!
先启动镜像
docker run -it kafka_server_test
查看docker进程
root@ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eb40b250c38e kafka_server_test "/run.sh" About a minute ago Up About a minute 9092/tcp cocky_bhabha
进入容器
root@ubuntu:~# docker exec -it eb40b250c38e /bin/bashroot@eb40b250c38e:/# cd /kafka_2.12-2.1.0/
bin/kafka-producer-perf-test.sh --topic test_perf --num-records 1000000 --record-size 1000 --throughput 2000 --producer-props bootstrap.servers=localhost:9092
输出:
[2018-12-06 08:50:25,952] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 1 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:26,063] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 3 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:26,171] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 4 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:26,575] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 5 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:26,686] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 6 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:26,799] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 7 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:27,201] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 8 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:27,314] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 9 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:27,421] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 10 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:27,615] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 11 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:27,723] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 12 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:27,835] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 13 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:28,033] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 14 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:28,142] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 15 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 08:50:28,343] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 16 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) records sent, 0.2 records/sec (0.00 MB/sec), 6529.0 ms avg latency, 6529.0 max latency. records sent, 195.5 records/sec (0.19 MB/sec), 4129.0 ms avg latency, 5700.0 max latency. records sent, 505.2 records/sec (0.48 MB/sec), 7376.3 ms avg latency, 9462.0 max latency. records sent, 548.0 records/sec (0.52 MB/sec), 11849.3 ms avg latency, 14333.0 max latency. records sent, 799.5 records/sec (0.76 MB/sec), 16470.2 ms avg latency, 18490.0 max latency. records sent, 1623.0 records/sec (1.55 MB/sec), 20567.4 ms avg latency, 22227.0 max latency. records sent, 1821.4 records/sec (1.74 MB/sec), 22738.9 ms avg latency, 23278.0 max latency. records sent, 1792.0 records/sec (1.71 MB/sec), 23369.0 ms avg latency, 23889.0 max latency. records sent, 2298.0 records/sec (2.19 MB/sec), 19010.4 ms avg latency, 23768.0 max latency. records sent, 2155.4 records/sec (2.06 MB/sec), 16760.0 ms avg latency, 17435.0 max latency. records sent, 2214.9 records/sec (2.11 MB/sec), 15430.7 ms avg latency, 16299.0 max latency. records sent, 2669.8 records/sec (2.55 MB/sec), 14335.0 ms avg latency, 14934.0 max latency. records sent, 2360.1 records/sec (2.25 MB/sec), 13364.5 ms avg latency, 14022.0 max latency. records sent, 2801.1 records/sec (2.67 MB/sec), 12638.4 ms avg latency, 13613.0 max latency. records sent, 3672.2 records/sec (3.50 MB/sec), 11248.4 ms avg latency, 12355.0 max latency. records sent, 3619.3 records/sec (3.45 MB/sec), 9437.7 ms avg latency, 10156.0 max latency. records sent, 2846.6 records/sec (2.71 MB/sec), 7655.5 ms avg latency, 9229.0 max latency. records sent, 3673.6 records/sec (3.50 MB/sec), 4640.2 ms avg latency, 6955.0 max latency. records sent, 2879.2 records/sec (2.75 MB/sec), 1508.1 ms avg latency, 2735.0 max latency. records sent, 2346.7 records/sec (2.24 MB/sec), 176.9 ms avg latency, 836.0 max latency. records sent, 1967.7 records/sec (1.88 MB/sec), 64.5 ms avg latency, 416.0 max latency. records sent, 1998.0 records/sec (1.91 MB/sec), 43.7 ms avg latency, 512.0 max latency. records sent, 2002.0 records/sec (1.91 MB/sec), 11.7 ms avg latency, 296.0 max latency. records sent, 2035.6 records/sec (1.94 MB/sec), 118.2 ms avg latency, 730.0 max latency. records sent, 2001.0 records/sec (1.91 MB/sec), 47.0 ms avg latency, 423.0 max latency. records sent, 1964.6 records/sec (1.87 MB/sec), 88.8 ms avg latency, 421.0 max latency. records sent, 2036.4 records/sec (1.94 MB/sec), 39.3 ms avg latency, 418.0 max latency. records sent, 2041.9 records/sec (1.95 MB/sec), 11.3 ms avg latency, 197.0 max latency. records sent, 2006.3 records/sec (1.91 MB/sec), 22.2 ms avg latency, 329.0 max latency. records sent, 1995.7 records/sec (1.90 MB/sec), 7.3 ms avg latency, 193.0 max latency. records sent, 2036.8 records/sec (1.94 MB/sec), 1.8 ms avg latency, 36.0 max latency. records sent, 1967.2 records/sec (1.88 MB/sec), 5.9 ms avg latency, 189.0 max latency. records sent, 2001.6 records/sec (1.91 MB/sec), 3.1 ms avg latency, 109.0 max latency. records sent, 2033.6 records/sec (1.94 MB/sec), 0.6 ms avg latency, 78.0 max latency. records sent, 2003.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 89.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.4 ms avg latency, 67.0 max latency. records sent, 2001.2 records/sec (1.91 MB/sec), 0.5 ms avg latency, 70.0 max latency. records sent, 1973.4 records/sec (1.88 MB/sec), 0.4 ms avg latency, 48.0 max latency. records sent, 2028.0 records/sec (1.93 MB/sec), 0.7 ms avg latency, 63.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.4 ms avg latency, 39.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 72.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 61.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 36.0 max latency. records sent, 2002.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 71.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.5 ms avg latency, 86.0 max latency. records sent, 1999.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 44.0 max latency. records sent, 2001.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 84.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 42.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 66.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.1 ms avg latency, 84.0 max latency. records sent, 2026.4 records/sec (1.93 MB/sec), 0.6 ms avg latency, 82.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 72.0 max latency. records sent, 2002.4 records/sec (1.91 MB/sec), 0.6 ms avg latency, 53.0 max latency. records sent, 1998.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 25.0 max latency. records sent, 1979.8 records/sec (1.89 MB/sec), 0.7 ms avg latency, 87.0 max latency. records sent, 2023.2 records/sec (1.93 MB/sec), 1.3 ms avg latency, 89.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 88.0 max latency. records sent, 2001.6 records/sec (1.91 MB/sec), 0.6 ms avg latency, 58.0 max latency. records sent, 1999.6 records/sec (1.91 MB/sec), 0.8 ms avg latency, 53.0 max latency. records sent, 1976.4 records/sec (1.88 MB/sec), 0.5 ms avg latency, 53.0 max latency. records sent, 2025.0 records/sec (1.93 MB/sec), 3.6 ms avg latency, 184.0 max latency. records sent, 2000.2 records/sec (1.91 MB/sec), 3.5 ms avg latency, 183.0 max latency. records sent, 2001.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 84.0 max latency. records sent, 2001.0 records/sec (1.91 MB/sec), 1.0 ms avg latency, 88.0 max latency. records sent, 2001.6 records/sec (1.91 MB/sec), 2.8 ms avg latency, 161.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.5 ms avg latency, 88.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 72.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.7 ms avg latency, 59.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 54.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.9 ms avg latency, 54.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.3 ms avg latency, 101.0 max latency. records sent, 1999.2 records/sec (1.91 MB/sec), 0.8 ms avg latency, 77.0 max latency. records sent, 2001.6 records/sec (1.91 MB/sec), 0.8 ms avg latency, 84.0 max latency. records sent, 2031.8 records/sec (1.94 MB/sec), 2.9 ms avg latency, 177.0 max latency. records sent, 2001.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 76.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 77.0 max latency. records sent, 1999.6 records/sec (1.91 MB/sec), 1.1 ms avg latency, 100.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.7 ms avg latency, 63.0 max latency. records sent, 1984.0 records/sec (1.89 MB/sec), 0.9 ms avg latency, 86.0 max latency. records sent, 2016.4 records/sec (1.92 MB/sec), 1.0 ms avg latency, 88.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 76.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.1 ms avg latency, 82.0 max latency. records sent, 1986.4 records/sec (1.89 MB/sec), 0.7 ms avg latency, 70.0 max latency. records sent, 2014.8 records/sec (1.92 MB/sec), 0.9 ms avg latency, 70.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 76.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 1.5 ms avg latency, 104.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 89.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.9 ms avg latency, 89.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.2 ms avg latency, 99.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 80.0 max latency. records sent, 1999.6 records/sec (1.91 MB/sec), 6.0 ms avg latency, 262.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 73.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 1.3 ms avg latency, 77.0 max latency. records sent, 1999.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 80.0 max latency. records sent, 2001.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 50.0 max latency. records sent, 1975.2 records/sec (1.88 MB/sec), 0.9 ms avg latency, 83.0 max latency. records sent, 2026.8 records/sec (1.93 MB/sec), 0.7 ms avg latency, 77.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 1.2 ms avg latency, 71.0 max latency. records sent, 1999.548102 records/sec (1.91 MB/sec), 2456.76 ms avg latency, 23889.00 ms max latency, 1 ms 50th, 16296 ms 95th, 23059 ms 99th, 23583 ms 99.9th.
bin/kafka-consumer-perf-test.sh --broker-list localhost:9092 --topic test_perf --fetch-size 1048576 --messages 1000000 --threads 1
如果出现以下提示:
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec WARNING: Exiting before consuming the expected number of messages: timeout (10000 ms) exceeded. You can use the --timeout option to increase the timeout. 2018-12-06 08:59:50:915, 2018-12-06 09:00:01:374, 0.0000, 0.0000, 0, 0.0000, 0, 10459, 0.0000, 0.0000
表示超时了,请仔细检查参数是否正确!
正常输出:
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec 2018-12-06 09:36:04:667, 2018-12-06 09:36:41:194, 953.6743, 26.1088, 1000000, 27377.0088, 112, 36415, 26.1891, 27461.2110
为了公平起见,删除进程
docker rm eb40b250c38e -f
注意要增加参数 --producer.config config/producer.config
bin/kafka-producer-perf-test.sh --producer.config config/producer.config --topic test_perf --num-records 1000000 --record-size 1000 --throughput 2000 --producer-props bootstrap.servers=localhost:9092
输出:
[2018-12-06 09:04:45,631] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 1 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:45,958] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 3 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:46,153] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 4 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:46,268] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 5 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:46,878] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 6 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:46,990] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 7 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:47,388] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 8 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:47,401] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 9 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:47,594] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 10 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:47,703] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 11 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) [2018-12-06 09:04:47,907] WARN [Producer clientId=producer-1] Error while fetching metadata with correlation id 12 : {test_perf=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient) records sent, 0.1 records/sec (0.00 MB/sec), 6959.0 ms avg latency, 6959.0 max latency. records sent, 183.2 records/sec (0.17 MB/sec), 3791.8 ms avg latency, 5484.0 max latency. records sent, 572.3 records/sec (0.55 MB/sec), 6858.4 ms avg latency, 8794.0 max latency. records sent, 548.1 records/sec (0.52 MB/sec), 11087.4 ms avg latency, 13351.0 max latency. records sent, 1160.7 records/sec (1.11 MB/sec), 15455.8 ms avg latency, 17528.0 max latency. records sent, 1831.7 records/sec (1.75 MB/sec), 19294.1 ms avg latency, 21259.0 max latency. records sent, 1754.0 records/sec (1.67 MB/sec), 21916.4 ms avg latency, 22293.0 max latency. records sent, 2480.0 records/sec (2.37 MB/sec), 20387.3 ms avg latency, 22414.0 max latency. records sent, 2785.4 records/sec (2.66 MB/sec), 15041.6 ms avg latency, 16889.0 max latency. records sent, 2144.4 records/sec (2.05 MB/sec), 12817.3 ms avg latency, 13446.0 max latency. records sent, 2629.6 records/sec (2.51 MB/sec), 13026.9 ms avg latency, 13467.0 max latency. records sent, 2297.6 records/sec (2.19 MB/sec), 13915.6 ms avg latency, 14426.0 max latency. records sent, 3499.6 records/sec (3.34 MB/sec), 12703.0 ms avg latency, 14420.0 max latency. records sent, 3530.5 records/sec (3.37 MB/sec), 10118.3 ms avg latency, 11597.0 max latency. records sent, 3415.1 records/sec (3.26 MB/sec), 6927.8 ms avg latency, 8714.0 max latency. records sent, 3464.7 records/sec (3.30 MB/sec), 3330.6 ms avg latency, 5185.0 max latency. records sent, 2580.7 records/sec (2.46 MB/sec), 297.0 ms avg latency, 1450.0 max latency. records sent, 1889.8 records/sec (1.80 MB/sec), 7.2 ms avg latency, 211.0 max latency. records sent, 2113.0 records/sec (2.02 MB/sec), 81.2 ms avg latency, 518.0 max latency. records sent, 1967.5 records/sec (1.88 MB/sec), 49.0 ms avg latency, 413.0 max latency. records sent, 1965.7 records/sec (1.87 MB/sec), 19.0 ms avg latency, 210.0 max latency. records sent, 1999.6 records/sec (1.91 MB/sec), 14.1 ms avg latency, 211.0 max latency. records sent, 2075.2 records/sec (1.98 MB/sec), 35.2 ms avg latency, 422.0 max latency. records sent, 1967.9 records/sec (1.88 MB/sec), 6.2 ms avg latency, 209.0 max latency. records sent, 2008.6 records/sec (1.92 MB/sec), 17.7 ms avg latency, 308.0 max latency. records sent, 2027.4 records/sec (1.93 MB/sec), 23.7 ms avg latency, 296.0 max latency. records sent, 2124.3 records/sec (2.03 MB/sec), 36.9 ms avg latency, 397.0 max latency. records sent, 2033.4 records/sec (1.94 MB/sec), 7.6 ms avg latency, 182.0 max latency. records sent, 1969.5 records/sec (1.88 MB/sec), 22.2 ms avg latency, 397.0 max latency. records sent, 1957.6 records/sec (1.87 MB/sec), 2.7 ms avg latency, 190.0 max latency. records sent, 2074.4 records/sec (1.98 MB/sec), 3.4 ms avg latency, 187.0 max latency. records sent, 1980.7 records/sec (1.89 MB/sec), 1.0 ms avg latency, 87.0 max latency. records sent, 2030.6 records/sec (1.94 MB/sec), 0.8 ms avg latency, 76.0 max latency. records sent, 1984.8 records/sec (1.89 MB/sec), 1.0 ms avg latency, 71.0 max latency. records sent, 2017.6 records/sec (1.92 MB/sec), 1.2 ms avg latency, 86.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.7 ms avg latency, 47.0 max latency. records sent, 1990.0 records/sec (1.90 MB/sec), 0.7 ms avg latency, 77.0 max latency. records sent, 2012.4 records/sec (1.92 MB/sec), 0.8 ms avg latency, 35.0 max latency. records sent, 2001.2 records/sec (1.91 MB/sec), 1.9 ms avg latency, 107.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 54.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.5 ms avg latency, 48.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 83.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.7 ms avg latency, 70.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.7 ms avg latency, 87.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.9 ms avg latency, 67.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 58.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.7 ms avg latency, 90.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 71.0 max latency. records sent, 2002.8 records/sec (1.91 MB/sec), 1.2 ms avg latency, 89.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.9 ms avg latency, 72.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.9 ms avg latency, 85.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 85.0 max latency. records sent, 2002.0 records/sec (1.91 MB/sec), 1.2 ms avg latency, 84.0 max latency. records sent, 1984.5 records/sec (1.89 MB/sec), 0.8 ms avg latency, 70.0 max latency. records sent, 2017.6 records/sec (1.92 MB/sec), 0.8 ms avg latency, 65.0 max latency. records sent, 1996.8 records/sec (1.90 MB/sec), 0.8 ms avg latency, 72.0 max latency. records sent, 2003.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 81.0 max latency. records sent, 2001.2 records/sec (1.91 MB/sec), 0.6 ms avg latency, 66.0 max latency. records sent, 1972.0 records/sec (1.88 MB/sec), 0.8 ms avg latency, 82.0 max latency. records sent, 2016.0 records/sec (1.92 MB/sec), 0.9 ms avg latency, 89.0 max latency. records sent, 1979.0 records/sec (1.89 MB/sec), 2.2 ms avg latency, 91.0 max latency. records sent, 2035.6 records/sec (1.94 MB/sec), 11.9 ms avg latency, 310.0 max latency. records sent, 1970.4 records/sec (1.88 MB/sec), 12.4 ms avg latency, 209.0 max latency. records sent, 1996.6 records/sec (1.90 MB/sec), 2.8 ms avg latency, 108.0 max latency. records sent, 2035.8 records/sec (1.94 MB/sec), 0.9 ms avg latency, 76.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 87.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 65.0 max latency. records sent, 2000.2 records/sec (1.91 MB/sec), 1.2 ms avg latency, 84.0 max latency. records sent, 2000.6 records/sec (1.91 MB/sec), 0.8 ms avg latency, 79.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 59.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 66.0 max latency. records sent, 1999.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 88.0 max latency. records sent, 2000.6 records/sec (1.91 MB/sec), 0.5 ms avg latency, 66.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 66.0 max latency. records sent, 1965.0 records/sec (1.87 MB/sec), 0.8 ms avg latency, 90.0 max latency. records sent, 2022.4 records/sec (1.93 MB/sec), 1.0 ms avg latency, 91.0 max latency. records sent, 2014.0 records/sec (1.92 MB/sec), 5.6 ms avg latency, 211.0 max latency. records sent, 2000.8 records/sec (1.91 MB/sec), 0.9 ms avg latency, 81.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 85.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 2.3 ms avg latency, 124.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 84.0 max latency. records sent, 2001.6 records/sec (1.91 MB/sec), 1.0 ms avg latency, 108.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.4 ms avg latency, 6.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.6 ms avg latency, 84.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 65.0 max latency. records sent, 1998.8 records/sec (1.91 MB/sec), 1.3 ms avg latency, 98.0 max latency. records sent, 2066.8 records/sec (1.97 MB/sec), 3.5 ms avg latency, 163.0 max latency. records sent, 1999.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 59.0 max latency. records sent, 1981.3 records/sec (1.89 MB/sec), 0.6 ms avg latency, 61.0 max latency. records sent, 2019.2 records/sec (1.93 MB/sec), 0.6 ms avg latency, 66.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 91.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.6 ms avg latency, 65.0 max latency. records sent, 1896.9 records/sec (1.81 MB/sec), 2.0 ms avg latency, 266.0 max latency. records sent, 2106.4 records/sec (2.01 MB/sec), 8.0 ms avg latency, 266.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 36.0 max latency. records sent, 2000.0 records/sec (1.91 MB/sec), 1.1 ms avg latency, 103.0 max latency. records sent, 2002.8 records/sec (1.91 MB/sec), 1.2 ms avg latency, 92.0 max latency. records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 68.0 max latency. records sent, 1999.836013 records/sec (1.91 MB/sec), 2061.17 ms avg latency, 22414.00 ms max latency, 1 ms 50th, 14188 ms 95th, 21994 ms 99th, 22277 ms 99.9th.
注意要增加参数 --consumer.config config/consumer.config
bin/kafka-consumer-perf-test.sh --consumer.config config/consumer.config --broker-list localhost:9092 --topic test_perf --fetch-size 1048576 --messages 1000000 --threads 1
输出:
start.time, end.time, data.consumed.in.MB, MB.sec, data.consumed.in.nMsg, nMsg.sec, rebalance.time.ms, fetch.time.ms, fetch.MB.sec, fetch.nMsg.sec 2018-12-06 09:19:12:936, 2018-12-06 09:20:04:443, 953.6743, 18.5154, 1000000, 19414.8368, 621, 50886, 18.7414, 19651.7706
先来看普通版的写入100万结果
1000000 records sent, 1999.548102 records/sec (1.91 MB/sec), 2456.76 ms avg latency, 23889.00 ms max latency, 1 ms 50th, 16296 ms 95th, 23059 ms 99th, 23583 ms 99.9th.
再来看acl版的结果
1000000 records sent, 1999.836013 records/sec (1.91 MB/sec), 2061.17 ms avg latency, 22414.00 ms max latency, 1 ms 50th, 14188 ms 95th, 21994 ms 99th, 22277 ms 99.9th.
可以看出,消息延迟时间,一个平均是2456.76 ms,一个是2061.17 ms。结果相差不大!
下一篇: kafka集群搭建
47607
45987
36910
34470
29082
25713
24566
19715
19248
17756
5566°
6155°
5691°
5737°
6706°
5483°
5485°
5989°
5965°
7295°