Buffer memory configuration
Producer buffer memory controls how much memory is available for batching messages before sending to brokers.buffer.memory
Total memory allocated for producer buffering:- Too small: Producer blocks frequently when buffer fills
- Too large: Excessive memory usage, potential GC pressure
- Optimal size: Balance between memory efficiency and producer throughput
max.block.ms
Time to block when buffer is full:- Producer blocks
send()
calls when buffer is exhausted - After timeout, throws
TimeoutException
- Prevents indefinite blocking in high-load scenarios
Memory calculation
Calculate required buffer memory:Request timeout settings
Timeout configurations control how long producers wait for various operations.request.timeout.ms
Timeout for individual requests:- Message send requests
- Metadata requests
- Administrative operations
delivery.timeout.ms
Overall timeout for message delivery including retries:metadata.max.age.ms
How long to cache topic metadata:- Shorter intervals detect partition changes faster
- Longer intervals reduce metadata requests
- Balance between responsiveness and efficiency
Connection configurations
Producer connection settings affect network behavior and resource usage.connections.max.idle.ms
Close idle connections after specified time:- Reduces connection overhead
- Prevents resource leaks
- Balances connection reuse with resource management
max.in.flight.requests.per.connection
Maximum unacknowledged requests per connection:max.in.flight.requests.per.connection=1
: Strict ordering, lower throughputmax.in.flight.requests.per.connection>1
: Higher throughput, potential reordering- With
enable.idempotence=true
: Can use up to 5 while maintaining ordering
reconnect.backoff.ms
Wait time before reconnecting failed connections:reconnect.backoff.max.ms
Maximum reconnect backoff time:Metadata and discovery
Producer metadata management configurations.bootstrap.servers
Initial broker list for cluster discovery:- Include multiple brokers for redundancy
- Use broker DNS names rather than IP addresses
- Include brokers from different racks if possible
metadata.max.idle.ms
Cache metadata when idle:retry.backoff.ms
Wait time between metadata refresh retries:Message size and batching
Advanced message size configurations.max.request.size
Maximum size of request (batch + headers):- Must be less than or equal to broker’s
message.max.bytes
setting - Affects largest possible batch size
- Consider network MTU and broker memory
send.buffer.bytes
TCP send buffer size:receive.buffer.bytes
TCP receive buffer size:Performance tuning
Advanced performance-related configurations.max.poll.interval.ms
Not directly a producer setting, but affects producer threads:socket.connection.setup.timeout.ms
Timeout for socket connections:socket.connection.setup.timeout.max.ms
Maximum socket connection timeout with backoff:Monitoring and metrics
Producer monitoring configurations.metrics.recording.level
Granularity of metrics collection:- INFO: Basic metrics, low overhead
- DEBUG: Detailed metrics, moderate overhead
- TRACE: All metrics, high overhead (development only)
metrics.sample.window.ms
Metrics sampling window:metrics.num.samples
Number of samples to maintain:metric.reporters
Custom metrics reporters:Client identification
Producer identification and naming.client.id
Unique identifier for this producer:- Easier troubleshooting with meaningful names
- Better monitoring and alerting
- Correlation with application logs
client.dns.lookup
DNS resolution strategy:Advanced reliability settings
Additional reliability configurations.enable.idempotence
Enable idempotent producer (prevents duplicates):retries=Integer.MAX_VALUE
max.in.flight.requests.per.connection=5
acks=all
transaction.timeout.ms
Timeout for transactions (when using transactions):transactional.id
Unique identifier for transactional producer:Configuration templates
High-throughput configuration
Low-latency configuration
High-reliability configuration
Memory-constrained configuration
Network-optimized configuration
Environment-specific tuning
Development environment
Testing environment
Production environment
Monitoring key configurations
Essential metrics to track
Buffer utilization:buffer-available-bytes
: Available buffer spacebuffer-exhausted-rate
: Rate of buffer exhaustion events
request-latency-avg
: Average request latencyrequest-rate
: Requests per secondresponse-rate
: Responses per second
connection-count
: Number of active connectionsconnection-creation-rate
: Rate of new connectionsconnection-close-rate
: Rate of closed connections
record-error-rate
: Rate of failed recordsrecord-retry-rate
: Rate of retried records
JMX monitoring configuration
Common configuration mistakes
Pitfalls to avoid
- Insufficient buffer memory: Causes frequent blocking
- Too high linger.ms: Increases latency unnecessarily
- Mismatched timeouts: delivery.timeout.ms too small for retry configuration
- Ignoring idempotence: Missing duplicate prevention in production
- No client.id: Makes troubleshooting difficult
- Wrong max.in.flight.requests: Affects ordering guarantees
Configuration validation
Troubleshooting configurations
High latency issues
Memory pressure
Connection issues
Configuration compatibilitySome configurations are interdependent. For example, enabling
enable.idempotence=true
automatically sets retries=Integer.MAX_VALUE
, max.in.flight.requests.per.connection=5
, and acks=all
.Start simpleBegin with default configurations and adjust one parameter at a time based on monitoring data. Most applications work well with minimal configuration changes.