꾸준히 오래오래

데이터 엔지니어의 공부 곳간✏️

Data/kafka

[Kafka] producer max.request.size configuration 오류 및 궁금증

zzi_yun 2023. 2. 17. 00:06

kafka로 cdc 구축을 위해 테스트하던 중, max.request.size를 넘었다는 오류가 발생하였다.

해당 오류는 Producer에서 보낼 수 있는 요청 당 최대 메시지 크기를 넘었다는 것이었다.

카프카 공식 문서에서 프로듀서 config에 해당 설정이 있으며 기본적으로 약 1MB로 되어있다.

 

해당 문제를 해결 위해서는,

producer의 max.request.size를 늘려주고, 그에 따라서 kafka broker의 message.max.byte도 살펴보아야 한다.

 

카프카 공식 문서 max.request.size 정의

The maximum size of a request in bytes. This setting will limit the number of record batches the producer will send in a single request to avoid sending huge requests. This is also effectively a cap on the maximum uncompressed record batch size. Note that the server has its own cap on the record batch size (after compression if compression is enabled) which may be different from this.

 

카프카 공식 문서 message.max.bytes 정의

The largest record batch size allowed by Kafka (after compression if compression is enabled). If this is increased and there are consumers older than 0.10.2, the consumers' fetch size must also be increased so that they can fetch record batches this large. In the latest message format version, records are always grouped into batches for efficiency. In previous message format versions, uncompressed records are not grouped into batches and this limit only applies to a single record in that case.This can be set per topic with the topic level 
max.message.bytes
 config.

여기서 broker 쪽에서 message.max.byte config는 압축을 했다면 압축 후 메시지 크기임을 기억해둬야 한다.

 

 

여기서 바보 같을지도 모르지만 한 가지 궁금증이 생겼다.🤔 

Q. 해당 사이즈 제한 의미가 단일 메시지를 의미하는 것일까? 아님 해당 요청으로 보내는 메시지 전체 크기를 의미하는 것일까?

이런 궁금증에는 현재 linger.msbatch.size producer configuration을 만져 준 상태였기 때문에

배치 형태로 작동하여 요청 당 메시지가 단 건이 아닐 수도 있었기 때문에 갑자기 이 부분이 헷갈렸으나

공식문서와 아래 글을 읽고 명료해졌다.

 

A. 한 요청으로 보내는 메시지의 전체 크기 제한으로, 보낼 수 있는 가장 큰 메시지 크기와 하나의 요청으로 보낼 수 있는 메세지 수(크기) 둘다 의미할 수 있다.

가정을 해보면 만약 메세지 하나 크기가 1MB이면 max.request.size의 제한이 1MB인 경우 단일 메시지의 크기 제한이라는 관점이 되고,

메시지가 1KB라면 최대 1000개의 메세지를 한 요청에 보낼 수 있다는 메세지 수라는 관점도 가능하다.

-> 해석의 관점을 빼면 그냥 요청 하나에 가져갈 수 있는 최대 바이트 수!

 

 

 

정리하자면, 프로듀서 입장에서

linger.ms가 최대 이만큼 기다릴 수 있어라는 상한선

batch.size가 최소 이만큼은 채워서 요청을 보낼게라는 하한선

-> 여기서 linger.ms가 되면 batch.size에 도달하지 못해도 메시지 전송  반대로 linger.ms에 도달하지 못해도 batch.size가 차면 메세지 전송

max.request.size는 최대 요청 당 가져갈 수 있는 메세지 바이트 수는 이거야 라는 상한선

 

 

 

 

 

[참고 자료]

카프카 공식 문서 : https://kafka.apache.org/33/documentation.html

https://stackoverflow.com/questions/54193852/is-this-possible-producer-batch-size-max-request-size-broker-max-message-by