Reduce Kafka publish latency for messages
This commit is contained in:
@@ -39,6 +39,7 @@ type kafkaConfig struct {
|
||||
DialTimeoutMS int `json:"dial_timeout_ms"`
|
||||
WriteTimeoutMS int `json:"write_timeout_ms"`
|
||||
ReadTimeoutMS int `json:"read_timeout_ms"`
|
||||
BatchTimeoutMS int `json:"batch_timeout_ms"`
|
||||
RequiredAcks int `json:"required_acks"`
|
||||
AllowAutoTopic bool `json:"allow_auto_topic_creation"`
|
||||
TLSEnabled bool `json:"tls_enabled"`
|
||||
@@ -131,6 +132,7 @@ func initKafkaRuntime(raw json.RawMessage) error {
|
||||
Transport: transport,
|
||||
RequiredAcks: kafka.RequiredAcks(cfg.RequiredAcks),
|
||||
AllowAutoTopicCreation: cfg.AllowAutoTopic,
|
||||
BatchTimeout: time.Duration(cfg.BatchTimeoutMS) * time.Millisecond,
|
||||
WriteTimeout: time.Duration(cfg.WriteTimeoutMS) * time.Millisecond,
|
||||
ReadTimeout: time.Duration(cfg.ReadTimeoutMS) * time.Millisecond,
|
||||
MaxAttempts: cfg.MaxRetryCount,
|
||||
@@ -162,6 +164,9 @@ func normalizeKafkaConfig(cfg *kafkaConfig) {
|
||||
if cfg.ReadTimeoutMS <= 0 {
|
||||
cfg.ReadTimeoutMS = 3000
|
||||
}
|
||||
if cfg.BatchTimeoutMS <= 0 {
|
||||
cfg.BatchTimeoutMS = 10
|
||||
}
|
||||
if cfg.RequiredAcks == 0 {
|
||||
cfg.RequiredAcks = int(kafka.RequireOne)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,17 @@ func TestKafkaTopicsKeepOnlyMessageInternalAsyncTopics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeKafkaConfigUsesLowLatencyBatchTimeout(t *testing.T) {
|
||||
cfg := kafkaConfig{}
|
||||
normalizeKafkaConfig(&cfg)
|
||||
if cfg.BatchTimeoutMS != 10 {
|
||||
t.Fatalf("unexpected kafka batch timeout: %d", cfg.BatchTimeoutMS)
|
||||
}
|
||||
if cfg.MaxRetryCount != 3 {
|
||||
t.Fatalf("unexpected kafka max retry count: %d", cfg.MaxRetryCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnqueueKafkaAuditEventPublishesCrossSystemEvent(t *testing.T) {
|
||||
oldKafkaBus := kafkaBus
|
||||
oldPublisher := publishKafkaAuditEventEnvelope
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
"dial_timeout_ms": 3000,
|
||||
"write_timeout_ms": 3000,
|
||||
"read_timeout_ms": 3000,
|
||||
"batch_timeout_ms": 10,
|
||||
"required_acks": 1,
|
||||
"allow_auto_topic_creation": false,
|
||||
"tls_enabled": false,
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
"dial_timeout_ms": 3000,
|
||||
"write_timeout_ms": 3000,
|
||||
"read_timeout_ms": 3000,
|
||||
"batch_timeout_ms": 10,
|
||||
"required_acks": 1,
|
||||
"allow_auto_topic_creation": false,
|
||||
"tls_enabled": false,
|
||||
|
||||
Reference in New Issue
Block a user