Bird
Raised Fist0
Kafkadevops~20 mins

Disk I/O optimization in Kafka - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Kafka Disk I/O Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Understanding Kafka Disk Flush Behavior
What is the output of the following Kafka producer configuration snippet regarding disk flush frequency?
Kafka
props.put("linger.ms", "500");
props.put("batch.size", "16384");
props.put("acks", "all");
// Producer sends 10 messages rapidly
for (int i = 0; i < 10; i++) {
    producer.send(new ProducerRecord<>("topic", Integer.toString(i), "message" + i));
}
producer.flush();
System.out.println("Messages sent and flushed.");
AMessages sent and flushed. Producer never flushes automatically; manual flush is required only.
BMessages sent and flushed. Producer flushes after every single message immediately.
CMessages sent and flushed. Producer batches messages and flushes every 500ms or when batch size is reached.
DMessages sent and flushed. Producer flushes only after 10 seconds regardless of batch size.
Attempts:
2 left
💡 Hint
Think about how linger.ms and batch.size affect when Kafka flushes data to disk.
🧠 Conceptual
intermediate
1:30remaining
Effect of Kafka Log Segment Size on Disk I/O
How does increasing the Kafka log segment size affect disk I/O performance?
ALog segment size has no effect on disk I/O performance in Kafka.
BLarger log segments reduce the frequency of disk flushes, improving sequential disk writes and reducing I/O overhead.
CLarger log segments increase random disk writes, causing more disk I/O overhead.
DSmaller log segments always improve disk I/O by reducing disk seek times.
Attempts:
2 left
💡 Hint
Think about how disk writes benefit from sequential large writes versus many small writes.
🔧 Debug
advanced
2:30remaining
Identifying Disk I/O Bottleneck in Kafka Consumer
Given this Kafka consumer code snippet, which option correctly identifies the cause of high disk I/O latency?
Kafka
consumer.subscribe(Collections.singletonList("topic"));
while (true) {
    ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
    for (ConsumerRecord<String, String> record : records) {
        process(record.value());
        consumer.commitSync();
    }
}
ASubscribing to a single topic causes disk I/O bottleneck due to lack of parallelism.
BPolling every 100ms causes excessive disk I/O and should be increased to 1000ms.
CNot using commitAsync() causes disk I/O latency due to synchronous commits.
DCalling commitSync() inside the for-loop causes frequent disk writes, increasing disk I/O latency.
Attempts:
2 left
💡 Hint
Consider how often commitSync() writes to disk and its impact on performance.
📝 Syntax
advanced
2:00remaining
Correct Kafka Producer Configuration for Disk I/O Optimization
Which option shows the correct Java code snippet to configure a Kafka producer for optimized disk I/O with compression and batching?
A
props.put("compression.type", "snappy");
props.put("batch.size", 32768);
props.put("linger.ms", 100);
B
props.put("compression", "snappy");
props.put("batchSize", "32768");
props.put("linger", 100);
C
props.put("compression.type", snappy);
props.put("batch.size", "32768");
props.put("linger.ms", "100");
D
props.put("compression.type", "gzip");
props.put("batch.size", 100);
props.put("linger.ms", 1000);
Attempts:
2 left
💡 Hint
Check property names and value types carefully.
🚀 Application
expert
3:00remaining
Optimizing Kafka Broker Disk Usage for High Throughput
You manage a Kafka cluster with high disk I/O load. Which configuration change will most effectively reduce disk I/O pressure on brokers while maintaining high throughput?
AIncrease log.segment.bytes to a larger size and enable log compaction to reduce disk writes.
BDecrease log.retention.hours to delete old logs faster and reduce disk usage.
CSet num.io.threads to 1 to serialize disk access and reduce contention.
DDisable log.cleaner to avoid extra disk I/O from compaction processes.
Attempts:
2 left
💡 Hint
Think about how log segment size and compaction affect disk write patterns.

Practice

(1/5)
1. Which Kafka configuration setting primarily affects how many threads handle disk read and write operations?
easy
A. num.io.threads
B. log.retention.hours
C. zookeeper.connect
D. auto.create.topics.enable

Solution

  1. Step 1: Identify the setting related to disk I/O threads

    The setting num.io.threads controls the number of threads Kafka uses for disk input/output operations.
  2. Step 2: Compare other options for relevance

    Other options like log.retention.hours relate to data retention, zookeeper.connect is for cluster coordination, and auto.create.topics.enable controls topic creation, none affect disk I/O threads.
  3. Final Answer:

    num.io.threads -> Option A
  4. Quick Check:

    Disk I/O threads = num.io.threads [OK]
Hint: Look for settings with 'io.threads' for disk I/O control [OK]
Common Mistakes:
  • Confusing retention settings with I/O threads
  • Choosing zookeeper settings instead of I/O
  • Selecting topic creation options
2. Which of the following is the correct syntax to set the log segment size to 1 GB in Kafka's server.properties file?
easy
A. log.segment.bytes=1GB
B. log.segment.size=1GB
C. segment.log.bytes=1024
D. log.segment.bytes=1073741824

Solution

  1. 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).
  2. Step 2: Evaluate each option's correctness

    log.segment.bytes=1073741824 uses the correct key log.segment.bytes and 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'.
  3. Final Answer:

    log.segment.bytes=1073741824 -> Option D
  4. Quick Check:

    Size in bytes = 1073741824 [OK]
Hint: Use bytes as integer for size settings, no units like GB [OK]
Common Mistakes:
  • Using units like GB instead of bytes
  • Incorrect property names
  • Using too small or wrong numeric values
3. Given the following Kafka configuration snippet:
num.io.threads=4
log.segment.bytes=10485760
log.dirs=/kafka-logs

What is the effect of setting num.io.threads to 4?
medium
A. Kafka limits the number of topics to 4.
B. Kafka will create 4 log directories.
C. Kafka will use 4 threads to handle disk I/O operations, improving parallelism.
D. Kafka will retain logs for 4 hours.

Solution

  1. 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.
  2. Step 2: Check other options for relevance

    Options about limiting topics, creating directories, or retention hours do not relate to num.io.threads.
  3. Final Answer:

    Kafka will use 4 threads to handle disk I/O operations, improving parallelism. -> Option C
  4. Quick Check:

    num.io.threads = 4 threads for disk I/O [OK]
Hint: num.io.threads sets disk I/O thread count, not topics or retention [OK]
Common Mistakes:
  • Confusing thread count with topic count
  • Assuming it controls log retention
  • Thinking it creates multiple directories
4. You have set log.segment.bytes=10485760 but Kafka still creates very small log segments. What is the most likely cause?
medium
A. The log.roll.ms setting causes segments to roll before reaching the size limit.
B. The num.io.threads is too low.
C. The log.dirs path is incorrect.
D. Kafka does not support segment size configuration.

Solution

  1. Step 1: Understand segment rolling behavior

    Kafka rolls log segments based on size or time. If log.roll.ms is set low, segments roll by time before reaching the size limit.
  2. Step 2: Evaluate other options

    Low num.io.threads affects performance but not segment size. Incorrect log.dirs causes errors but not small segments. Kafka supports segment size configuration.
  3. Final Answer:

    The log.roll.ms setting causes segments to roll before reaching the size limit. -> Option A
  4. Quick Check:

    Segment rolling time overrides size limit [OK]
Hint: Check log.roll.ms if segments are smaller than expected [OK]
Common Mistakes:
  • Blaming I/O threads for segment size
  • Ignoring time-based rolling settings
  • Assuming Kafka ignores segment size config
5. You want to optimize Kafka disk I/O for a high-throughput system. Which combination of settings is best to improve write performance without increasing disk usage too much?
hard
A. Decrease num.io.threads, set very large log.segment.bytes, and disable flushing
B. Increase num.io.threads, set moderate log.segment.bytes, and tune log.flush.interval.messages
C. Set num.io.threads to 1, use small log.segment.bytes, and flush after every message
D. Ignore num.io.threads, set log.segment.bytes to default, and increase retention time

Solution

  1. Step 1: Understand the impact of num.io.threads and segment size

    Increasing num.io.threads allows more parallel disk operations. Moderate segment size balances write efficiency and disk usage.
  2. Step 2: Consider flushing settings

    Tuning log.flush.interval.messages controls how often data is flushed to disk, improving performance without excessive disk writes.
  3. 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.
  4. Final Answer:

    Increase num.io.threads, set moderate log.segment.bytes, and tune log.flush.interval.messages -> Option B
  5. Quick Check:

    Balanced threads, segment size, and flush tuning optimize disk I/O [OK]
Hint: Balance threads, segment size, and flush interval for best write speed [OK]
Common Mistakes:
  • Setting too large segments causing disk bloat
  • Disabling flushing risking data loss
  • Using too few I/O threads limiting throughput
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard