Kafka Production Rate and CPU Usage
This section describes performance tests on Distributed Message Service (DMS) for Kafka. The performance is measured by the message production rate on the client side and CPU usage on the server side. The tests cover the following scenarios:
- Scenario 1 (batch size): same Kafka instance, same topics, different message size settings
- Scenario 2 (cross-AZ or intra-AZ production): same Kafka instance, same topics, different AZ settings for the client and server
- Scenario 3 (number of replicas): same Kafka instance, different numbers of replicas
- Scenario 4 (synchronous or asynchronous replication): same Kafka instance, topics with different replication settings
Partitions |
Replicas |
Synchronous Replication |
batch.size |
Cross-AZ Production |
---|---|---|---|---|
3 |
1 |
No |
1 KB |
No |
3 |
1 |
No |
16 KB |
No |
3 |
1 |
No |
1 KB |
Yes |
3 |
3 |
Yes |
1 KB |
No |
3 |
3 |
No |
1 KB |
No |
Environment
Perform the following steps to set up the test environment.
- Purchase a Kafka instance with parameters specified as follows. For details about how to purchase one, see Buying a Kafka Instance.
- Region:
- Project:
- AZ: Select 1.
- Instance Name: Enter "kafka-test".
- Enterprise Project: Select default.
- Version: Select 2.7.
- Broker Flavor: Select kafka.2u4g.cluster.
- Brokers: 3
- Storage space per broker: ultra-high I/O, 200 GB
- Capacity Threshold Policy: Select Automatically delete.
- VPC: Select a VPC.
- Security Group: Select a security group.
- Advanced Settings: Do not enable Public Network Access, SASL_SSL, and Automatic Topic Creation.
After the purchase, obtain on the instance details page.
- Create three topics with parameters specified as follows for the purchased Kafka instance. For details, see Creating a Kafka Topic.
- Topic-01: 3 partitions, 1 replica, asynchronous replication
- Topic-02: 3 partitions, 3 replicas, asynchronous replication
- Topic-03: 3 partitions, 3 replicas, synchronous replication
- Obtain the test tool.
Obtain Kafka CLI v2.7.2.
- Purchase a server for the client.
Buy two ECSs with the following configurations. For details about how to purchase an ECS, see Purchasing an ECS.
- One ECS is 4 vCPUs | 8 GB, runs Linux, and is configured with the same region, AZ, VPC, subnet, and security group as the Kafka instance.
- The other ECS is 4 vCPUs | 8 GB, runs Linux, and is configured with the same region, VPC, subnet, and security group but a different AZ from the Kafka instance.
Perform the following operations on the ECSs:
- Install Java JDK and configure the environment variables JAVA_HOME and PATH.
export JAVA_HOME=/root/jdk1.8.0_231 export PATH=$JAVA_HOME/bin:$PATH
- Download Kafka CLI v2.7.2 and decompress it.
tar -zxf kafka_2.12-2.7.2.tgz
Script
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=${connection address} acks=1 batch.size=${batch.size} linger.ms=0 --topic ${topic name} --num-records ${num-records} --record-size 1024 --throughput 102400
- bootstrap.servers: address of the Kafka instance obtained in 1.
- acks: message synchronization policy. acks=1 indicates asynchronous replication, and acks=-1 indicates synchronous replication.
- batch.size: size of messages sent in each batch, in bytes.
- linger.ms: interval between two batches.
- topic: topic name set in 2.
- num-records: total number of messages to be sent.
- record-size: size of each message.
- throughput: number of messages sent per second.
Procedure
Scenario 1: Varied Batch Sizes
- Log in to the client server, go to the kafka_2.12-2.7.2/bin directory, and run the following scripts.
Set batch.size to 1 KB, and run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=1024 linger.ms=0 --topic Topic-01 --num-records 8000000 --record-size 1024 --throughput 102400
Result:
8000000 records sent, 27417.353814 records/sec (26.77 MB/sec), 1095.79 ms avg latency, 5989.00 ms max latency, 679 ms 50th, 2957 ms 95th, 3505 ms 99th, 5951 ms 99.9th.
Message production rate: 27,417 records/second
Set batch.size to 16 KB, and run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=16384 linger.ms=0 --topic Topic-01 --num-records 100000000 --record-size 1024 --throughput 102400
Result:
100000000 records sent, 102399.213574 records/sec (100.00 MB/sec), 11.27 ms avg latency, 876 ms max latency, 1 ms 50th, 15 ms 95th, 384 ms 99th, 724 ms 99.9th.
Message production rate: 102,399 records/second
- Log in to the Kafka console and click the name of the test instance.
- In the navigation pane, choose Monitoring.
- On the Brokers tab page, view the CPU usage of the server nodes.
Figure 1 broker-0 CPU usage (batch.size = 1 KB)
CPU usage: 57%
Figure 2 broker-0 CPU usage (batch.size = 16 KB)
CPU usage: 31%
Figure 3 broker-1 CPU usage (batch.size = 1 KB)
CPU usage: 58%
Figure 4 broker-1 CPU usage (batch.size = 16 KB)
CPU usage: 33%
Figure 5 broker-2 CPU usage (batch.size = 1 KB)
CPU usage: 58%
Figure 6 broker-2 CPU usage (batch.size = 16 KB)
CPU usage: 31%
Scenario 2: Cross-AZ or Intra-AZ Production
- Log in to the client server, go to the kafka_2.12-2.7.2/bin directory, and run the following scripts.
Configure the same AZ for the client and the instance, and run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=1024 linger.ms=0 --topic Topic-01 --num-records 8000000 --record-size 1024 --throughput 102400
Result:
8000000 records sent, 27417.353814 records/sec (26.77 MB/sec), 1095.79 ms avg latency, 5989.00 ms max latency, 679 ms 50th, 2957 ms 95th, 3505 ms 99th, 5951 ms 99.9th.
Message production rate: 27,417 records/second
Configure different AZs for the client and the instance, and run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=1024 linger.ms=0 --topic Topic-01 --num-records 4000000 --record-size 1024 --throughput 102400
Result:
4000000 records sent, 15351.079181 records/sec (14.99 MB/sec), 1927.26 ms avg latency, 8974.00 ms max latency, 15 ms 50th, 5925 ms 95th, 6838 ms 99th, 8925 ms 99.9th.
Message production rate: 15,351 records/second
- Log in to the Kafka console and click the name of the test instance.
- In the navigation pane, choose Monitoring.
- On the Brokers tab page, view the CPU usage of the server nodes.
Figure 7 broker-0 CPU usage (same AZ)
CPU usage: 57%
Figure 8 broker-0 CPU usage (different AZs)
CPU usage: 37%
Figure 9 broker-1 CPU usage (same AZ)
CPU usage: 58%
Figure 10 broker-1 CPU usage (different AZs)
CPU usage: 39%
Figure 11 broker-2 CPU usage (same AZ)
CPU usage: 58%
Figure 12 broker-2 CPU usage (different AZs)
CPU usage: 36%
Scenario 3: Varied Numbers of Replicas
- Log in to the client server, go to the kafka_2.12-2.7.2/bin directory, and run the following scripts.
For the one-replica topic, run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=1024 linger.ms=0 --topic Topic-01 --num-records 8000000 --record-size 1024 --throughput 102400
Result:
8000000 records sent, 27417.353814 records/sec (26.77 MB/sec), 1095.79 ms avg latency, 5989.00 ms max latency, 679 ms 50th, 2957 ms 95th, 3505 ms 99th, 5951 ms 99.9th.
Message production rate: 27,417 records/second
For the three-replica topic, run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=1024 linger.ms=0 --topic Topic-02 --num-records 4000000 --record-size 1024 --throughput 102400
Result:
4000000 records sent, 11557.954473 records/sec (11.29 MB/sec), 2591.66 ms avg latency, 8071.00 ms max latency, 2566 ms 50th, 5396 ms 95th, 6276 ms 99th, 8003 ms 99.9th.
Message production rate: 11,558 records/second
- Log in to the Kafka console and click the name of the test instance.
- In the navigation pane, choose Monitoring.
- On the Brokers tab page, view the CPU usage of the server nodes.
Figure 13 broker-0 CPU usage (one replica)
CPU usage: 57%
Figure 14 broker-0 CPU usage (three replicas)
CPU usage: 89%
Figure 15 broker-1 CPU usage (one replica)
CPU usage: 58%
Figure 16 broker-1 CPU usage (three replicas)
CPU usage: 88%
Figure 17 broker-2 CPU usage (one replica)
CPU usage: 58%
Figure 18 broker-2 CPU usage (three replicas)
CPU usage: 87%
Scenario 4: Synchronous/Asynchronous Replication
- Log in to the client server, go to the kafka_2.12-2.7.2/bin directory, and run the following scripts.
For asynchronous replication, run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=1 batch.size=1024 linger.ms=0 --topic Topic-02 --num-records 4000000 --record-size 1024 --throughput 102400
Result:
4000000 records sent, 11557.954473 records/sec (11.29 MB/sec), 2591.66 ms avg latency, 8071.00 ms max latency, 2566 ms 50th, 5396 ms 95th, 6276 ms 99th, 8003 ms 99.9th.
Message production rate: 11,558 records/second
For synchronous replication, run the following script:
./kafka-producer-perf-test.sh --producer-props bootstrap.servers=192.168.0.69:9092,192.168.0.42:9092,192.168.0.66:9092 acks=-1 batch.size=1024 linger.ms=0 --topic Topic-03 --num-records 1000000 --record-size 1024 --throughput 102400
Result:
1000000 records sent, 3859.960628 records/sec (3.77 MB/sec), 7675.00 ms avg latency, 13852.00 ms max latency, 7695 ms 50th, 11056 ms 95th, 12907 ms 99th, 13809 ms 99.9th.
Message production rate: 3859 records/second
- Log in to the Kafka console and click the name of the test instance.
- In the navigation pane, choose Monitoring.
- On the Brokers tab page, view the CPU usage of the server nodes.
Figure 19 broker-0 CPU usage (asynchronous replication)
CPU usage: 89%
Figure 20 broker-0 CPU usage (synchronous replication)
CPU usage: 62%
Figure 21 broker-1 CPU usage (asynchronous replication)
CPU usage: 88%
Figure 22 broker-1 CPU usage (synchronous replication)
CPU usage: 62%
Figure 23 broker-2 CPU usage (asynchronous replication)
CPU usage: 87%
Figure 24 broker-2 CPU usage (synchronous replication)
CPU usage: 60%
Result
Partitions |
Replicas |
Synchronous Replication |
batch.size |
Cross-AZ Production |
Message Production Rate on the Client Side (Records/Second) |
CPU Usage on the Server Side (broker-0) |
CPU Usage on the Server Side (broker-1) |
CPU Usage on the Server Side (broker-2) |
---|---|---|---|---|---|---|---|---|
3 |
1 |
No |
1 KB |
No |
27417 |
57% |
58% |
58% |
3 |
1 |
No |
16 KB |
No |
102399 |
31% |
33% |
31% |
3 |
1 |
No |
1 KB |
Yes |
15351 |
37% |
39% |
36% |
3 |
3 |
Yes |
1 KB |
No |
3859 |
62% |
62% |
60% |
3 |
3 |
No |
1 KB |
No |
11558 |
89% |
88% |
87% |
Based on the test results, the following conclusions are drawn (for reference only):
- When the batch.size of production requests is 16 times larger, the message production rate increases, and the CPU usage decreases.
- Compared with cross-AZ production, intra-AZ production significantly increases message production rate and CPU usage.
- When the number of replicas changes from 1 to 3, the message production rate decreases significantly, and the CPU usage increases.
- Compared with synchronous replication, asynchronous replication increases the message production rate and the CPU usage.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.