一、场景

线上已经有kafka集群,服务运行稳定。但是因为产品升级,需要对kakfa做安全测试,也就是权限验证。

但是增加权限验证,会不会对性能有影响呢?影响大吗?不知道呀!

因此,本文就此来做一下对比!

 

测试环境

本文使用的是单机kafka测试,仅在一台服务器做测试。

使用的kafka版本为kafka_2.12-2.1.0,zk直接使用kafka自带的。

硬件配置为:1(核)-4G内容-40G硬盘

 

二、普通版安装

 

里面有关于 kafka_server_test

 

三、acl版安装

这里使用的acl设置,仅仅使用write用户来测试。赋予它所有权限,下面会说到!

新建空目录

mkdir /opt/kafka_server_acl

 

consumer.config

security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
group.id=test-group

 

dockerfile

kafka写入速度测试 kafka单机写入性能_apache

kafka写入速度测试 kafka单机写入性能_ubuntu_02

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"]

View Code

 

kafka_cluster_jaas.conf

kafka写入速度测试 kafka单机写入性能_apache

kafka写入速度测试 kafka单机写入性能_ubuntu_02

KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin"
user_admin="admin"
user_reader="reader"
user_writer="writer";
};

View Code

 

producer.config

security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN

 

run.sh

kafka写入速度测试 kafka单机写入性能_apache

kafka写入速度测试 kafka单机写入性能_ubuntu_02

#!/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

View Code

 

注意:默认的kafka压测脚本是针对于普通版的kafka。如果是已经开启了acl验证的kafkfa,运行会直接报错。

因此为了解决这个问题,有2个步骤:

1. 修改压测脚本,最后一行指定参数-Djava.security.auth.login.config

2. 运行脚本时,要增加参数。下文会说到,稍安勿躁!

 

sources.list

kafka写入速度测试 kafka单机写入性能_apache

kafka写入速度测试 kafka单机写入性能_ubuntu_02

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

View Code

 

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/bash
root@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运行正常!

四、100万性能对比

普通版

先启动镜像

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/bash
root@eb40b250c38e:/# cd /kafka_2.12-2.1.0/

 

写入100万

bin/kafka-producer-perf-test.sh --topic test_perf --num-records 1000000 --record-size 1000  --throughput 2000 --producer-props bootstrap.servers=localhost:9092

 

输出:

kafka写入速度测试 kafka单机写入性能_apache

kafka写入速度测试 kafka单机写入性能_ubuntu_02

[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)
1 records sent, 0.2 records/sec (0.00 MB/sec), 6529.0 ms avg latency, 6529.0 max latency.
993 records sent, 195.5 records/sec (0.19 MB/sec), 4129.0 ms avg latency, 5700.0 max latency.
2528 records sent, 505.2 records/sec (0.48 MB/sec), 7376.3 ms avg latency, 9462.0 max latency.
2896 records sent, 548.0 records/sec (0.52 MB/sec), 11849.3 ms avg latency, 14333.0 max latency.
4064 records sent, 799.5 records/sec (0.76 MB/sec), 16470.2 ms avg latency, 18490.0 max latency.
8256 records sent, 1623.0 records/sec (1.55 MB/sec), 20567.4 ms avg latency, 22227.0 max latency.
9648 records sent, 1821.4 records/sec (1.74 MB/sec), 22738.9 ms avg latency, 23278.0 max latency.
8960 records sent, 1792.0 records/sec (1.71 MB/sec), 23369.0 ms avg latency, 23889.0 max latency.
11968 records sent, 2298.0 records/sec (2.19 MB/sec), 19010.4 ms avg latency, 23768.0 max latency.
10928 records sent, 2155.4 records/sec (2.06 MB/sec), 16760.0 ms avg latency, 17435.0 max latency.
11504 records sent, 2214.9 records/sec (2.11 MB/sec), 15430.7 ms avg latency, 16299.0 max latency.
13600 records sent, 2669.8 records/sec (2.55 MB/sec), 14335.0 ms avg latency, 14934.0 max latency.
12032 records sent, 2360.1 records/sec (2.25 MB/sec), 13364.5 ms avg latency, 14022.0 max latency.
14224 records sent, 2801.1 records/sec (2.67 MB/sec), 12638.4 ms avg latency, 13613.0 max latency.
18640 records sent, 3672.2 records/sec (3.50 MB/sec), 11248.4 ms avg latency, 12355.0 max latency.
18368 records sent, 3619.3 records/sec (3.45 MB/sec), 9437.7 ms avg latency, 10156.0 max latency.
14768 records sent, 2846.6 records/sec (2.71 MB/sec), 7655.5 ms avg latency, 9229.0 max latency.
18368 records sent, 3673.6 records/sec (3.50 MB/sec), 4640.2 ms avg latency, 6955.0 max latency.
14416 records sent, 2879.2 records/sec (2.75 MB/sec), 1508.1 ms avg latency, 2735.0 max latency.
11736 records sent, 2346.7 records/sec (2.24 MB/sec), 176.9 ms avg latency, 836.0 max latency.
9992 records sent, 1967.7 records/sec (1.88 MB/sec), 64.5 ms avg latency, 416.0 max latency.
10156 records sent, 1998.0 records/sec (1.91 MB/sec), 43.7 ms avg latency, 512.0 max latency.
10186 records sent, 2002.0 records/sec (1.91 MB/sec), 11.7 ms avg latency, 296.0 max latency.
10180 records sent, 2035.6 records/sec (1.94 MB/sec), 118.2 ms avg latency, 730.0 max latency.
10005 records sent, 2001.0 records/sec (1.91 MB/sec), 47.0 ms avg latency, 423.0 max latency.
9943 records sent, 1964.6 records/sec (1.87 MB/sec), 88.8 ms avg latency, 421.0 max latency.
10184 records sent, 2036.4 records/sec (1.94 MB/sec), 39.3 ms avg latency, 418.0 max latency.
10342 records sent, 2041.9 records/sec (1.95 MB/sec), 11.3 ms avg latency, 197.0 max latency.
10162 records sent, 2006.3 records/sec (1.91 MB/sec), 22.2 ms avg latency, 329.0 max latency.
10152 records sent, 1995.7 records/sec (1.90 MB/sec), 7.3 ms avg latency, 193.0 max latency.
10184 records sent, 2036.8 records/sec (1.94 MB/sec), 1.8 ms avg latency, 36.0 max latency.
9942 records sent, 1967.2 records/sec (1.88 MB/sec), 5.9 ms avg latency, 189.0 max latency.
10036 records sent, 2001.6 records/sec (1.91 MB/sec), 3.1 ms avg latency, 109.0 max latency.
10168 records sent, 2033.6 records/sec (1.94 MB/sec), 0.6 ms avg latency, 78.0 max latency.
10018 records sent, 2003.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 89.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.4 ms avg latency, 67.0 max latency.
10008 records sent, 2001.2 records/sec (1.91 MB/sec), 0.5 ms avg latency, 70.0 max latency.
9958 records sent, 1973.4 records/sec (1.88 MB/sec), 0.4 ms avg latency, 48.0 max latency.
10140 records sent, 2028.0 records/sec (1.93 MB/sec), 0.7 ms avg latency, 63.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.4 ms avg latency, 39.0 max latency.
10006 records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 72.0 max latency.
10006 records sent, 2000.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 61.0 max latency.
10004 records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 36.0 max latency.
10012 records sent, 2002.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 71.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.5 ms avg latency, 86.0 max latency.
9999 records sent, 1999.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 44.0 max latency.
10007 records sent, 2001.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 84.0 max latency.
10004 records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 42.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 66.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 1.1 ms avg latency, 84.0 max latency.
10134 records sent, 2026.4 records/sec (1.93 MB/sec), 0.6 ms avg latency, 82.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 72.0 max latency.
10014 records sent, 2002.4 records/sec (1.91 MB/sec), 0.6 ms avg latency, 53.0 max latency.
10002 records sent, 1998.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 25.0 max latency.
10006 records sent, 1979.8 records/sec (1.89 MB/sec), 0.7 ms avg latency, 87.0 max latency.
10118 records sent, 2023.2 records/sec (1.93 MB/sec), 1.3 ms avg latency, 89.0 max latency.
10004 records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 88.0 max latency.
10008 records sent, 2001.6 records/sec (1.91 MB/sec), 0.6 ms avg latency, 58.0 max latency.
10002 records sent, 1999.6 records/sec (1.91 MB/sec), 0.8 ms avg latency, 53.0 max latency.
9896 records sent, 1976.4 records/sec (1.88 MB/sec), 0.5 ms avg latency, 53.0 max latency.
10127 records sent, 2025.0 records/sec (1.93 MB/sec), 3.6 ms avg latency, 184.0 max latency.
10003 records sent, 2000.2 records/sec (1.91 MB/sec), 3.5 ms avg latency, 183.0 max latency.
10009 records sent, 2001.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 84.0 max latency.
10007 records sent, 2001.0 records/sec (1.91 MB/sec), 1.0 ms avg latency, 88.0 max latency.
10012 records sent, 2001.6 records/sec (1.91 MB/sec), 2.8 ms avg latency, 161.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.5 ms avg latency, 88.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 72.0 max latency.
10008 records sent, 2000.8 records/sec (1.91 MB/sec), 0.7 ms avg latency, 59.0 max latency.
10006 records sent, 2000.8 records/sec (1.91 MB/sec), 0.5 ms avg latency, 54.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.9 ms avg latency, 54.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 1.3 ms avg latency, 101.0 max latency.
9998 records sent, 1999.2 records/sec (1.91 MB/sec), 0.8 ms avg latency, 77.0 max latency.
10038 records sent, 2001.6 records/sec (1.91 MB/sec), 0.8 ms avg latency, 84.0 max latency.
10161 records sent, 2031.8 records/sec (1.94 MB/sec), 2.9 ms avg latency, 177.0 max latency.
10005 records sent, 2001.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 76.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 77.0 max latency.
9998 records sent, 1999.6 records/sec (1.91 MB/sec), 1.1 ms avg latency, 100.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.7 ms avg latency, 63.0 max latency.
9950 records sent, 1984.0 records/sec (1.89 MB/sec), 0.9 ms avg latency, 86.0 max latency.
10082 records sent, 2016.4 records/sec (1.92 MB/sec), 1.0 ms avg latency, 88.0 max latency.
10004 records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 76.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 1.1 ms avg latency, 82.0 max latency.
9932 records sent, 1986.4 records/sec (1.89 MB/sec), 0.7 ms avg latency, 70.0 max latency.
10076 records sent, 2014.8 records/sec (1.92 MB/sec), 0.9 ms avg latency, 70.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 76.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 1.5 ms avg latency, 104.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 89.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.9 ms avg latency, 89.0 max latency.
10006 records sent, 2000.4 records/sec (1.91 MB/sec), 1.2 ms avg latency, 99.0 max latency.
10004 records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 80.0 max latency.
10000 records sent, 1999.6 records/sec (1.91 MB/sec), 6.0 ms avg latency, 262.0 max latency.
10006 records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 73.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 1.3 ms avg latency, 77.0 max latency.
10000 records sent, 1999.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 80.0 max latency.
10008 records sent, 2001.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 50.0 max latency.
9876 records sent, 1975.2 records/sec (1.88 MB/sec), 0.9 ms avg latency, 83.0 max latency.
10138 records sent, 2026.8 records/sec (1.93 MB/sec), 0.7 ms avg latency, 77.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 1.2 ms avg latency, 71.0 max latency.
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.

View Code

 

消费100万

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

 

acl版

写入100万

注意要增加参数 --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

输出:

kafka写入速度测试 kafka单机写入性能_apache

kafka写入速度测试 kafka单机写入性能_ubuntu_02

[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)
1 records sent, 0.1 records/sec (0.00 MB/sec), 6959.0 ms avg latency, 6959.0 max latency.
929 records sent, 183.2 records/sec (0.17 MB/sec), 3791.8 ms avg latency, 5484.0 max latency.
2912 records sent, 572.3 records/sec (0.55 MB/sec), 6858.4 ms avg latency, 8794.0 max latency.
2784 records sent, 548.1 records/sec (0.52 MB/sec), 11087.4 ms avg latency, 13351.0 max latency.
6016 records sent, 1160.7 records/sec (1.11 MB/sec), 15455.8 ms avg latency, 17528.0 max latency.
9296 records sent, 1831.7 records/sec (1.75 MB/sec), 19294.1 ms avg latency, 21259.0 max latency.
9056 records sent, 1754.0 records/sec (1.67 MB/sec), 21916.4 ms avg latency, 22293.0 max latency.
12400 records sent, 2480.0 records/sec (2.37 MB/sec), 20387.3 ms avg latency, 22414.0 max latency.
14080 records sent, 2785.4 records/sec (2.66 MB/sec), 15041.6 ms avg latency, 16889.0 max latency.
10928 records sent, 2144.4 records/sec (2.05 MB/sec), 12817.3 ms avg latency, 13446.0 max latency.
13424 records sent, 2629.6 records/sec (2.51 MB/sec), 13026.9 ms avg latency, 13467.0 max latency.
11488 records sent, 2297.6 records/sec (2.19 MB/sec), 13915.6 ms avg latency, 14426.0 max latency.
17680 records sent, 3499.6 records/sec (3.34 MB/sec), 12703.0 ms avg latency, 14420.0 max latency.
18288 records sent, 3530.5 records/sec (3.37 MB/sec), 10118.3 ms avg latency, 11597.0 max latency.
17328 records sent, 3415.1 records/sec (3.26 MB/sec), 6927.8 ms avg latency, 8714.0 max latency.
17632 records sent, 3464.7 records/sec (3.30 MB/sec), 3330.6 ms avg latency, 5185.0 max latency.
12906 records sent, 2580.7 records/sec (2.46 MB/sec), 297.0 ms avg latency, 1450.0 max latency.
9757 records sent, 1889.8 records/sec (1.80 MB/sec), 7.2 ms avg latency, 211.0 max latency.
10567 records sent, 2113.0 records/sec (2.02 MB/sec), 81.2 ms avg latency, 518.0 max latency.
9991 records sent, 1967.5 records/sec (1.88 MB/sec), 49.0 ms avg latency, 413.0 max latency.
10157 records sent, 1965.7 records/sec (1.87 MB/sec), 19.0 ms avg latency, 210.0 max latency.
10348 records sent, 1999.6 records/sec (1.91 MB/sec), 14.1 ms avg latency, 211.0 max latency.
10376 records sent, 2075.2 records/sec (1.98 MB/sec), 35.2 ms avg latency, 422.0 max latency.
9936 records sent, 1967.9 records/sec (1.88 MB/sec), 6.2 ms avg latency, 209.0 max latency.
10043 records sent, 2008.6 records/sec (1.92 MB/sec), 17.7 ms avg latency, 308.0 max latency.
10139 records sent, 2027.4 records/sec (1.93 MB/sec), 23.7 ms avg latency, 296.0 max latency.
10753 records sent, 2124.3 records/sec (2.03 MB/sec), 36.9 ms avg latency, 397.0 max latency.
10171 records sent, 2033.4 records/sec (1.94 MB/sec), 7.6 ms avg latency, 182.0 max latency.
9956 records sent, 1969.5 records/sec (1.88 MB/sec), 22.2 ms avg latency, 397.0 max latency.
9870 records sent, 1957.6 records/sec (1.87 MB/sec), 2.7 ms avg latency, 190.0 max latency.
10372 records sent, 2074.4 records/sec (1.98 MB/sec), 3.4 ms avg latency, 187.0 max latency.
9941 records sent, 1980.7 records/sec (1.89 MB/sec), 1.0 ms avg latency, 87.0 max latency.
10155 records sent, 2030.6 records/sec (1.94 MB/sec), 0.8 ms avg latency, 76.0 max latency.
9944 records sent, 1984.8 records/sec (1.89 MB/sec), 1.0 ms avg latency, 71.0 max latency.
10088 records sent, 2017.6 records/sec (1.92 MB/sec), 1.2 ms avg latency, 86.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.7 ms avg latency, 47.0 max latency.
9956 records sent, 1990.0 records/sec (1.90 MB/sec), 0.7 ms avg latency, 77.0 max latency.
10062 records sent, 2012.4 records/sec (1.92 MB/sec), 0.8 ms avg latency, 35.0 max latency.
10006 records sent, 2001.2 records/sec (1.91 MB/sec), 1.9 ms avg latency, 107.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 54.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.5 ms avg latency, 48.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 1.0 ms avg latency, 83.0 max latency.
10006 records sent, 2000.8 records/sec (1.91 MB/sec), 0.7 ms avg latency, 70.0 max latency.
10004 records sent, 2000.8 records/sec (1.91 MB/sec), 0.7 ms avg latency, 87.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.9 ms avg latency, 67.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 58.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.7 ms avg latency, 90.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.8 ms avg latency, 71.0 max latency.
10016 records sent, 2002.8 records/sec (1.91 MB/sec), 1.2 ms avg latency, 89.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.9 ms avg latency, 72.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.9 ms avg latency, 85.0 max latency.
10004 records sent, 2000.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 85.0 max latency.
10010 records sent, 2002.0 records/sec (1.91 MB/sec), 1.2 ms avg latency, 84.0 max latency.
10004 records sent, 1984.5 records/sec (1.89 MB/sec), 0.8 ms avg latency, 70.0 max latency.
10088 records sent, 2017.6 records/sec (1.92 MB/sec), 0.8 ms avg latency, 65.0 max latency.
10002 records sent, 1996.8 records/sec (1.90 MB/sec), 0.8 ms avg latency, 72.0 max latency.
10020 records sent, 2003.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 81.0 max latency.
10006 records sent, 2001.2 records/sec (1.91 MB/sec), 0.6 ms avg latency, 66.0 max latency.
9984 records sent, 1972.0 records/sec (1.88 MB/sec), 0.8 ms avg latency, 82.0 max latency.
10080 records sent, 2016.0 records/sec (1.92 MB/sec), 0.9 ms avg latency, 89.0 max latency.
10012 records sent, 1979.0 records/sec (1.89 MB/sec), 2.2 ms avg latency, 91.0 max latency.
10180 records sent, 2035.6 records/sec (1.94 MB/sec), 11.9 ms avg latency, 310.0 max latency.
9976 records sent, 1970.4 records/sec (1.88 MB/sec), 12.4 ms avg latency, 209.0 max latency.
10095 records sent, 1996.6 records/sec (1.90 MB/sec), 2.8 ms avg latency, 108.0 max latency.
10181 records sent, 2035.8 records/sec (1.94 MB/sec), 0.9 ms avg latency, 76.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 87.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 65.0 max latency.
10003 records sent, 2000.2 records/sec (1.91 MB/sec), 1.2 ms avg latency, 84.0 max latency.
10005 records sent, 2000.6 records/sec (1.91 MB/sec), 0.8 ms avg latency, 79.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 59.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 66.0 max latency.
10003 records sent, 1999.8 records/sec (1.91 MB/sec), 0.8 ms avg latency, 88.0 max latency.
10005 records sent, 2000.6 records/sec (1.91 MB/sec), 0.5 ms avg latency, 66.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 66.0 max latency.
9996 records sent, 1965.0 records/sec (1.87 MB/sec), 0.8 ms avg latency, 90.0 max latency.
10116 records sent, 2022.4 records/sec (1.93 MB/sec), 1.0 ms avg latency, 91.0 max latency.
10072 records sent, 2014.0 records/sec (1.92 MB/sec), 5.6 ms avg latency, 211.0 max latency.
10006 records sent, 2000.8 records/sec (1.91 MB/sec), 0.9 ms avg latency, 81.0 max latency.
10004 records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 85.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 2.3 ms avg latency, 124.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.7 ms avg latency, 84.0 max latency.
10010 records sent, 2001.6 records/sec (1.91 MB/sec), 1.0 ms avg latency, 108.0 max latency.
10002 records sent, 2000.0 records/sec (1.91 MB/sec), 0.4 ms avg latency, 6.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.6 ms avg latency, 84.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 65.0 max latency.
10004 records sent, 1998.8 records/sec (1.91 MB/sec), 1.3 ms avg latency, 98.0 max latency.
10336 records sent, 2066.8 records/sec (1.97 MB/sec), 3.5 ms avg latency, 163.0 max latency.
10002 records sent, 1999.6 records/sec (1.91 MB/sec), 0.7 ms avg latency, 59.0 max latency.
9934 records sent, 1981.3 records/sec (1.89 MB/sec), 0.6 ms avg latency, 61.0 max latency.
10096 records sent, 2019.2 records/sec (1.93 MB/sec), 0.6 ms avg latency, 66.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.6 ms avg latency, 91.0 max latency.
10002 records sent, 2000.4 records/sec (1.91 MB/sec), 0.6 ms avg latency, 65.0 max latency.
9786 records sent, 1896.9 records/sec (1.81 MB/sec), 2.0 ms avg latency, 266.0 max latency.
10534 records sent, 2106.4 records/sec (2.01 MB/sec), 8.0 ms avg latency, 266.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 0.5 ms avg latency, 36.0 max latency.
10000 records sent, 2000.0 records/sec (1.91 MB/sec), 1.1 ms avg latency, 103.0 max latency.
10016 records sent, 2002.8 records/sec (1.91 MB/sec), 1.2 ms avg latency, 92.0 max latency.
10004 records sent, 2000.4 records/sec (1.91 MB/sec), 0.8 ms avg latency, 68.0 max latency.
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.

View Code

 

消费100万

注意要增加参数 --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。结果相差不大!