Skip to content

Commit

Permalink
Added dlsm::Disruptor
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarneliuk committed May 2, 2024
1 parent 60228ef commit 1459869
Show file tree
Hide file tree
Showing 22 changed files with 4,162 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ install(EXPORT DLSM-Development
include(CTest)
if(BUILD_TESTING)
set(CMAKE_CTEST_ARGUMENTS -V) # Enable verbose output on test target
add_subdirectory(tests/apps)
add_subdirectory(tests/perf)
add_subdirectory(tests/unit)
endif()
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,48 @@ This project contains scripts and snippets in C++.
- Integration with [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
- Integration with [Doxygen](https://github.com/doxygen/doxygen)

## Disruptor
Yet another implementation of [LMAX Disruptor](https://lmax-exchange.github.io/disruptor/disruptor.html) in `C++20`.
<details><summary>Details</summary>

#### Other known implementations
- Original [LMAX Disruptor](https://github.com/LMAX-Exchange/disruptor) in `Java`
- [Abc-Arbitrage/Disruptor-cpp](https://github.com/Abc-Arbitrage/Disruptor-cpp)
- [lewissbaker/disruptorplus](https://github.com/lewissbaker/disruptorplus)
- [Vallest/Disruptor-CPP](https://github.com/Vallest/Disruptor-CPP)
- [jeremyko/disruptorCpp-IPC](https://github.com/jeremyko/disruptorCpp-IPC)

#### Features of [dlsm::Disruptor](include/impl/Disruptor.hpp)
- Template-based implementation with different components for customization:
- Barriers::
- PointerBarrier - minimal container for dependencies of a sequence
- AtomicsBarrier - `std::atomic` pointers to dependencies
- OffsetsBarrier - `std::atomic` offsets to dependencies for placing in shared memory
- Waits::
- SpinsStrategy - busy-wait based on exponential `__x86_64__` `_mm_pause()` intrinsic
- YieldStrategy - busy-wait based on `std::this_thread::yield()`
- BlockStrategy - blocking strategy based on `std::std::condition_variable_any`
- ShareStrategy - blocking strategy based on `pthreads` for placing in shared memory
- Sequencers::
- `SPMC` - Single Producer Multiple Consumers pattern
- `MPMC` - Multiple Producers Multiple Consumers pattern
- Ring - adapter for external random-access container(`std::array/vector`) for ring-access to Events
- External memory injection(optional) for sequencers, useful for placement in HugePages/SharedMemory
- [Unit](tests/unit/TestDisruptor.cpp) and [Performance(latency&throughput)](tests/perf/PerfDisruptor.cpp) tests
- [dlsm::Disruptor::Graph](include/impl/DisruptorGraph.hpp) - high-level API

#### Known defects and limitations
- Implementation of lock-free operations in not portable to `Weak Memory Model` platforms(ARM, PowerPC)
- `Claim-Timeout`/`Consume-Timeout` operations are not implemented in Sequencers(Publishers and Consumers)
- `SPSC` - Single Producer Single Consumer pattern is not implemented
- dlsm::Disruptor::Graph has high overhead caused by indirections and virtual calls
- dlsm::Disruptor::Graph is incomplete and unstable

#### Latency & Throughput tests
Results of performance tests are in separate [tests/perf/Disruptor.md](tests/perf/Disruptor.md).

</details>

## Useful Scripts
```sh
./scripts/format.sh # Apply .clang-format rules on hpp/cpp files
Expand All @@ -31,3 +73,4 @@ This project contains scripts and snippets in C++.
## Links and References
- [Measuring Latency in Linux](http://btorpey.github.io/blog/2014/02/18/clock-sources-in-linux/)
- [Weak vs. Strong Memory Models](https://preshing.com/20120930/weak-vs-strong-memory-models/)
- [Fast and/or Large Memory – Cache and Memory Hierarchy](https://cw.fel.cvut.cz/b192/_media/courses/b35apo/en/lectures/04/b35apo_lecture04-cache-en.pdf)
Binary file added docs/images/delays-Disruptor-1P4C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1459869

Please sign in to comment.