kwonslog / how-to-use-kafka

0 stars 0 forks source link

Kafka 성능 테스트 - Kafka Performance 사용하기 #9

Open kwonslog opened 1 year ago

kwonslog commented 1 year ago

Kafka Performance 도구로 성능 테스트

image

주키퍼 및 브로커 서버 실행은?

networks: test-kafka-net: external: true


### 테스트를 위한 토픽 생성
- 아래와 같이 명령을 실행하여 테스트를 위한 토픽을 생성한다.

docker exec -it test-kf1 kafka-topics --create --topic test-topic --partitions 1 --replication-factor 1 --bootstrap-server localhost:9092


### Producer Performance Test
- Kafka 프로듀서의 성능을 측정해 보자.
- 아래 도구는 윈도우 환경에서 ubuntu 22.04.2 LTS 앱을 설치하고 진행한다.
- 도구 사용법

kafka-producer-perf-test.sh --topic --num-records --record-size --throughput --producer-props --print-metrics --producer-threads

> 명령을 실행하고 나서 Classpath is empty. Please build the project first e.g. by running './gradlew jar -PscalaVersion=2.13.10' 메세지와 비슷하게 출력되면 bin 폴더의 상위 경로로 이동하고 gradlew 명령을 실행하자.

> 위 명령을 실행하고 완료되기까지 약 56분 걸렸다.

<details><summary>참고 이미지</summary>
<img width="854" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/d7f03e0d-d2bb-4ff2-9d5b-f5ca7289aedc">
<img width="840" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/01e2323a-233a-4e26-8b05-97e4b8d09933">
<img width="708" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/07c62ebd-2df2-4579-9c5b-612542691aef">
<img width="356" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/a7409249-6b4c-45b6-89ab-ea28059e2a09">
</details> 

- `--topic`: 테스트에 사용할 Kafka 토픽 이름
- `--num-records`: 생성할 메시지 수
- `--record-size`: 각 메시지의 크기(바이트 단위)
- `--throughput`: 초당 전송할 메시지 수
- `--producer-props`: 프로듀서의 설정 속성 (예: acks, compression.type 등)
- `--print-metrics`: 프로듀서 메트릭 출력 여부
- `--producer-threads`: 프로듀서 스레드 수

- 테스트를 위해 초당 100개씩 1000개의 레코드를 처리하는 명령을 실행 한다.

./kafka-producer-perf-test.sh --topic test-topic --num-records 1000 --record-size 1024 --throughput 100 --print-metrics --producer-props bootstrap.servers=localhost:9092

> 명령을 실행하고 조금 기다리면 테스트 결과값을 볼 수 있다.
<img width="849" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/571c653b-da42-4df8-8d47-51138b5dbfb2">
- 이 결과값에 대한 해석은 다음과 같다.

- `502 records sent`: 총 502개의 레코드가 전송
- `100.3 records/sec`: 초당 평균 100.3개의 레코드가 처리
- `0.10 MB/sec`: 초당 평균 0.10 메가바이트의 데이터 처리율
- `7.5 ms avg latency`: 평균 지연 시간은 7.5 밀리초
- `727.0 ms max latency`: 가장 큰 지연 시간은 727.0 밀리초

- `1000 records sent`: 총 1000개의 레코드가 전송
- `100.000000 records/sec`: 초당 평균 100개의 레코드가 처리
- `0.10 MB/sec`: 초당 평균 0.10 메가바이트의 데이터 처리율
- `4.81 ms avg latency`: 평균 지연 시간은 4.81 밀리초
- `727.00 ms max latency`: 가장 큰 지연 시간은 727.00 밀리초
- `2 ms 50th`: 50%의 레코드는 2밀리초 이내에 처리
- `25 ms 95th`: 95%의 레코드는 25밀리초 이내에 처리
- `27 ms 99th`: 99%의 레코드는 27밀리초 이내에 처리
- `727 ms 99.9th`: 99.9%의 레코드는 727밀리초 이내에 처리

> 토픽 메세지의 크기는 최대 1MB가 기본값이다. 이것보다 큰 값을 사용헤야 한다면 다음 옵션들을 확인해 보자.
- message.max.bytes
- max.request.size
- max.partition.fetch.bytes
- 아래는 2MB 크기의 메세지를 테스트 했을때 나오는 결과값이다.
<img width="847" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/444a12ce-5b5b-4dcb-bb27-1c1eb2034272">

### Consumer Performance Test
- Kafka 컨슈머의 성능을 측정해 보자.
- 도구 사용법

kafka-consumer-perf-test.sh --bootstrap-server --group --topic --messages --consumer-props --print-metrics


- `--bootstrap-server`: Kafka 브로커의 호스트 및 포트 정보
- `--group`: 컨슈머 그룹 ID
- `--topic`: 테스트에 사용할 Kafka 토픽 이름
- `--messages`: 읽을 메시지 수
- - `--print-metrics`: 메트릭 출력 여부
- `--consumer-props`: 컨슈머의 설정 속성 (예: auto.offset.reset, fetch.min.bytes 등)

- 아래와 같이 테스트를 실행 하였다.

./kafka-consumer-perf-test.sh --bootstrap-server localhost:9092 --group test-group-1 --topic test-topic --messages 10 --print-metrics


- 실행 결과는 다음과 같다.
<img width="848" alt="image" src="https://github.com/kwonslog/how-to-use-kafka/assets/65941166/17be91f8-16e7-48d4-aafe-7dd04f963a0d">

- `start.time`: 테스트가 시작된 시간. 여기서는 2023년 7월 13일 23시 5분 6.456초에 테스트가 시작

- `end.time`: 테스트가 종료된 시간. 여기서는 2023년 7월 13일 23시 5분 10.611초에 테스트가 종료

- `data.consumed.in.MB`: 컨슈머가 소비한 데이터의 총 용량. 위 출력에서는 0.4883 메가바이트

- `MB.sec`: 초당 평균 데이터 소비 속도. 위 출력에서는 0.1175 메가바이트/초. 이 값은 컨슈머가 초당 평균적으로 처리한 데이터 속도

- `data.consumed.in.nMsg`: 컨슈머가 소비한 메시지의 총 개수. 위 출력에서는 500개의 메시지를 소비

- `nMsg.sec`: 초당 평균 메시지 소비 속도. 위 출력에서는 120.3369개의 메시지/초 이 값은 컨슈머가 초당 평균적으로 처리한 메시지의 개수

- `rebalance.time.ms`: 리밸런스(rebalance)에 소요된 시간. 리밸런스는 컨슈머 그룹 내의 파티션 할당을 조정하는 프로세스. 위 출력에서는 4040밀리초(4.04초)가 소요

- `fetch.time.ms`: 메시지를 가져오는(fetch)데 소요된 시간. 위 출력에서는 115밀리초(0.115초)가 소요

- `fetch.MB.sec`: 초당 평균 메시지 가져오기 속도. 위 출력에서는 4.2459 메가바이트/초. 이 값은 컨슈머가 초당 평균적으로 데이터를 가져오는 속도

- `fetch.nMsg.sec`: 초당 평균 메시지 가져오기 속도. 위 출력에서는 4347.8261개의 메시지/초. 이 값은 컨슈머가 초당 평균적으로 메시지를 가져오는 속도