Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Low Latency Systems: How do they do it?

Low Latency Systems: How do they do it?

An overview of tips and tricks from low latency system design and the hardware trends that drive them.

Ben Darfler

March 08, 2017
Tweet

More Decks by Ben Darfler

Other Decks in Programming

Transcript

  1. Prefetch Data • Disk Readahead ◦ Data on disk is

    prefetched into memory ◦ Masks latency if data is accessed sequentially • Cache Prefetching ◦ Data in memory is prefetched into CPU cache ◦ Masks latency if data is accessed sequentially
  2. Sequential I/O • Arrays ◦ Best when used with primitive

    or value types ◦ Open Addressing - represent a hash table in an array ◦ Ring Buffer - represent a queue in an array • Write Ahead Log ◦ Most databases, many filesystems ◦ Logging for crash recovery
  3. Batch Write • Adaptive Flushing ◦ Queue data to be

    written ◦ Flushing thread loops flushing the queue ◦ Adaptively increases the size of the writes under heavy load • Group Commit / Write Coalescing ◦ MySQL, PostgreSQL, SSD/HDD Controllers ◦ Combine concurrent operations into one write
  4. Shared Nothing Architecture • Logically run one instance of the

    application per core • Linux provides the ability to ◦ Pin threads to specific cores ◦ Give each core it’s own queue for disk and network I/O • Minimize cross-core communication ◦ Partition data such that processing can occur on one core
  5. CPU Optimizations • Lock Contention ◦ Atomic CAS (Compare and

    Swap) operations ◦ Lock free data structures • Context Switching ◦ One thread per core • False Sharing ◦ Keep hot data in its own “cache line” • Branch Misprediction ◦ Branchless algorithms (bit manipulation tricks)
  6. Fin