Disk I/O optimization in Kafka - Commands & Configuration
log.dirs=/var/lib/kafka-logs-1,/var/lib/kafka-logs-2 num.io.threads=8 num.replica.fetchers=4 log.flush.interval.messages=10000 log.flush.interval.ms=1000 log.segment.bytes=1073741824 log.retention.hours=168 log.retention.bytes=10737418240
log.dirs: Lists multiple directories on different disks to spread Kafka logs and reduce disk I/O bottlenecks.
num.io.threads: Number of threads Kafka uses for disk I/O operations, increasing parallelism.
num.replica.fetchers: Threads fetching data from leader replicas, affecting disk read load.
log.flush.interval.messages and log.flush.interval.ms: Control how often Kafka flushes data to disk, balancing durability and performance.
log.segment.bytes: Size of log segments to optimize disk writes.
log.retention.hours and log.retention.bytes: Manage how long and how much data Kafka keeps on disk to avoid disk full issues.
kafka-server-start.sh /opt/kafka/config/server.properties
iostat -dx 2 3
kafka-topics.sh --describe --topic example-topic --bootstrap-server localhost:9092--describe - Shows detailed information about the topic--bootstrap-server - Specifies the Kafka server to connect toIf you remember nothing else from disk I/O optimization, remember: spreading Kafka logs across multiple disks and tuning I/O threads improves performance and reduces bottlenecks.
Practice
Solution
Step 1: Identify the setting related to disk I/O threads
The settingnum.io.threadscontrols the number of threads Kafka uses for disk input/output operations.Step 2: Compare other options for relevance
Other options likelog.retention.hoursrelate to data retention,zookeeper.connectis for cluster coordination, andauto.create.topics.enablecontrols topic creation, none affect disk I/O threads.Final Answer:
num.io.threads -> Option AQuick Check:
Disk I/O threads = num.io.threads [OK]
- Confusing retention settings with I/O threads
- Choosing zookeeper settings instead of I/O
- Selecting topic creation options
Solution
Step 1: Understand Kafka's configuration syntax for sizes
Kafka expects byte values as integers for size settings, so 1 GB must be expressed in bytes (1 GB = 1073741824 bytes).Step 2: Evaluate each option's correctness
log.segment.bytes=1073741824 uses the correct keylog.segment.bytesand the correct byte value. log.segment.size=1GB uses an invalid key and unit. segment.log.bytes=1024 uses wrong key and too small value. log.segment.bytes=1GB uses correct key but invalid unit '1GB'.Final Answer:
log.segment.bytes=1073741824 -> Option DQuick Check:
Size in bytes = 1073741824 [OK]
- Using units like GB instead of bytes
- Incorrect property names
- Using too small or wrong numeric values
num.io.threads=4 log.segment.bytes=10485760 log.dirs=/kafka-logs
What is the effect of setting
num.io.threads to 4?Solution
Step 1: Understand the role of num.io.threads
This setting controls how many threads Kafka uses for disk input/output operations, allowing parallel reads and writes.Step 2: Check other options for relevance
Options about limiting topics, creating directories, or retention hours do not relate tonum.io.threads.Final Answer:
Kafka will use 4 threads to handle disk I/O operations, improving parallelism. -> Option CQuick Check:
num.io.threads = 4 threads for disk I/O [OK]
- Confusing thread count with topic count
- Assuming it controls log retention
- Thinking it creates multiple directories
log.segment.bytes=10485760 but Kafka still creates very small log segments. What is the most likely cause?Solution
Step 1: Understand segment rolling behavior
Kafka rolls log segments based on size or time. Iflog.roll.msis set low, segments roll by time before reaching the size limit.Step 2: Evaluate other options
Lownum.io.threadsaffects performance but not segment size. Incorrectlog.dirscauses errors but not small segments. Kafka supports segment size configuration.Final Answer:
The log.roll.ms setting causes segments to roll before reaching the size limit. -> Option AQuick Check:
Segment rolling time overrides size limit [OK]
- Blaming I/O threads for segment size
- Ignoring time-based rolling settings
- Assuming Kafka ignores segment size config
Solution
Step 1: Understand the impact of num.io.threads and segment size
Increasingnum.io.threadsallows more parallel disk operations. Moderate segment size balances write efficiency and disk usage.Step 2: Consider flushing settings
Tuninglog.flush.interval.messagescontrols how often data is flushed to disk, improving performance without excessive disk writes.Step 3: Evaluate other options
Decreasing threads or disabling flushing harms performance or data safety. Small segments and frequent flushes increase disk I/O. Ignoring threads or retention does not optimize writes.Final Answer:
Increase num.io.threads, set moderate log.segment.bytes, and tune log.flush.interval.messages -> Option BQuick Check:
Balanced threads, segment size, and flush tuning optimize disk I/O [OK]
- Setting too large segments causing disk bloat
- Disabling flushing risking data loss
- Using too few I/O threads limiting throughput
Ready to prove it?
Pass the test and this pattern moves unknown
