Using Modern C++ In Anger
Todd L. Montgomery @toddlmontgomery
StoneTor
Using Modern C++ In Anger Todd L. Montgomery @toddlmontgomery Aeron - - PowerPoint PPT Presentation
StoneTor Using Modern C++ In Anger Todd L. Montgomery @toddlmontgomery Aeron and C++? What constitutes Modern C++ ? How Aeron Adopts Modern C++? What Lessons were learned? Whats Next ? Aeron and C++? Truly modern
Using Modern C++ In Anger
Todd L. Montgomery @toddlmontgomery
StoneTor
Feature Bloat & Complexity
Not Fast Enough
Low & Predictable Latency is key
We are in a new world
Multi-core, Multi-socket, Cloud...
We are in a new world
UDP, IPC, InfiniBand, RDMA, PCI-e Multi-core, Multi-socket, Cloud...
Aeron is trying a new approach
The Team
Todd Montgomery Richard Warburton Martin Thompson
Publishers Subscribers Channel Stream
Messaging
Channel
A library, not a framework, on which other abstractions and applications can be built
Composable Design
OSI layer 4 Transport for message oriented streams
OSI Layer 4 (Transport) Services
Multi-Everything World!
Publishers Subscribers Channel Stream
Multi-Everything World
Design Principles
Publisher Subscriber Subscriber Publisher
Architecture
IPC Log Buffer
Sender Receiver Receiver Sender Publisher Subscriber Subscriber Publisher
Architecture
Media IPC Log Buffer Media (UDP, InfiniBand, PCI-e 3.0)
Conductor Sender Receiver Conductor Receiver Sender Publisher Subscriber Subscriber Publisher Admin Events
Architecture
Admin Events Media IPC Log Buffer Media (UDP, InfiniBand, PCI-e 3.0) Function/Method Call Volatile Fields & Queues
Client Media Driver Media Driver Conductor Sender Receiver Conductor Receiver Sender Client Publisher Conductor Conductor Subscriber Subscriber Publisher Admin Events
Architecture
Admin Events Media IPC Log Buffer IPC Ring/Broadcast Buffer Media (UDP, InfiniBand, PCI-e 3.0) Function/Method Call Volatile Fields & Queues
Client Media Driver Media Driver Conductor Sender Receiver Conductor Receiver Sender Client Publisher Conductor Conductor Subscriber Subscriber Publisher Admin Events
Architecture
Admin Events Media IPC Log Buffer IPC Ring/Broadcast Buffer Media (UDP, InfiniBand, PCI-e 3.0) Function/Method Call Volatile Fields & Queues
Client Media Driver Media Driver Conductor Sender Receiver Conductor Receiver Sender Client Publisher Conductor Conductor Subscriber Subscriber Publisher Admin Events
Architecture
Admin Events Media IPC Log Buffer IPC Ring/Broadcast Buffer Media (UDP, InfiniBand, PCI-e 3.0) Function/Method Call Volatile Fields & Queues Client
Modern C++
Modern C++
std::lock_guard std::unique_ptr
Resource Acquisition is Initialization (RAII)
http://en.cppreference.com/w/cpp/language/raii
Modern C++
std::shared_ptr std::unique_ptr std::weak_ptr
Smart Pointers
http://en.cppreference.com/w/cpp/memory
Modern C++
Modern C++
std::atomic<bool> std::atomic_flag
Atomic Operations
http://en.cppreference.com/w/cpp/atomic
Modern C++
std::thread std::mutex std::promise std::future
Thread Support
http://en.cppreference.com/w/cpp/thread
Modern C++
Modern C++
CMake Google Test Google Mock etc.
Modern Toolchain
https://cmake.org/ https://github.com/google/googletest
Smart Pointers
Lambda’s & Function Objects
Thread Support
Lessons - What do you think?
Lessons
RAII & Smart Pointers
RAII & Smart Pointers
RAII & Smart Pointers
[insert excuse Y] … Escape Analysis Value Types …
Stack Allocation (Lack of)
Lessons
Move Construction/Assignment
Move Construction/Assignment
Move Construction/Assignment
Move Construction/Assignment
Lessons
Client Media Driver Media Driver Conductor Sender Receiver Conductor Receiver Sender Client Publisher Conductor Conductor Subscriber Subscriber Publisher Admin Events
Architecture
Admin Events Media IPC Log Buffer IPC Ring/Broadcast Buffer Media (UDP, InfiniBand, PCI-e 3.0) Function/Method Call Volatile Fields & Queues
Data Structures (Shared Memory)
Creates a
replicated persistent log
What Aeron does
Tail File
Tail File Message 1 Header
Tail File Message 1 Header Message 2 Header
Tail File Message 1 Header Message 2 Header
Tail File Message 1 Header Message 2 Header Message 3
Tail File Message 1 Header Message 2 Header Message 3 Header
Log Buffer File
Term 0 Term 1 Term 2 Term Meta Data 0 Term Meta Data 2 Term Meta Data 1 Log Meta Data
Log Buffer File
Term 0 Term 1 Term 2 Term Meta Data 0 Term Meta Data 2 Term Meta Data 1 Log Meta Data
Atomic & Ordered Operations
Position
Unique identification of a byte within each stream
Publishers, Senders, Receivers, and Subscribers all keep position counters
Position counters are the key to flow control and monitoring
Statistics & Position Counters are accessible in shared memory
Atomic & Ordered Operations
Multiple Challenges
Size Matters (Atomics)
Memory Models
So… Aeron uses its own atomic
(JMM compatible)
* gcc x86_64 initially contributed by phaynes (phaynes@threatmetrix.com)
Finished a few passes of Profiling and Tuning
C++ to C++ 32+ Million messages per second
IPC, 32-byte Messages
C++: 32M msg/sec Java: 30M msg/sec .NET: 15M msg/sec
IPC, 32-byte Messages
Replication Services Aeron Core Persistence Performance C/C++ Driver Multi Unicast Send Efficient FEC Encryption/Security
https://github.com/real-logic/Aeron
Where can I find it?
Aeron: https://github.com/real-logic/Aeron Twitter: @toddlmontgomery
Thank You!
Questions?