Commit 947c7a1
authored
feat: Add comprehensive lock-free implementations with performance improvements (#4)
* Add typed_lockfree_job_queue and convert samples to use logger
Major changes:
1. Renamed lockfree_mpmc_queue to lockfree_job_queue throughout codebase
- Updated all references in sources, tests, and benchmarks
- Maintained backward compatibility with existing interfaces
2. Implemented typed_lockfree_job_queue based on lockfree_job_queue
- High-performance lock-free priority-based job queue
- Maintains separate lock-free queues for each job type/priority
- Supports dynamic queue creation and priority-based dequeuing
- Added comprehensive sample demonstrating usage
3. Converted all sample programs to use logger instead of std::cout
- Updated hazard_pointer_sample, lockfree_thread_pool_sample,
lockfree_typed_thread_pool_sample, node_pool_sample, and
typed_lockfree_job_queue_sample
- Added logger dependencies to CMakeLists.txt files
- Fixed thread_id formatting issues with std::ostringstream
- Maintained logger callback demos with explanatory comments
All tests pass and samples run successfully with consistent logging output.
* feat: Add lock-free typed thread pool implementation
- Implement typed_lockfree_thread_pool with per-type lock-free queues
- Add typed_lockfree_thread_worker for priority-based job processing
- Enhance typed_lockfree_job_queue with statistics and empty() overload
- Create comprehensive benchmarks comparing mutex vs lock-free implementations
- Add sample demonstrating lock-free thread pool usage and performance
- Update performance documentation with detailed benchmark results
- Update README with lock-free implementation details and project structure
Performance improvements:
- 7-71% faster under load compared to mutex implementation
- 2-4x better scalability under high contention
- True priority scheduling with 99.6% accuracy
- Per-type queue isolation for better cache locality
* feat: Add high-performance lock-free thread pool implementation
This commit introduces a lock-free thread pool as a high-performance alternative
to the standard mutex-based implementation, providing significant performance
improvements under high contention scenarios.
Core Features:
- Lock-free MPMC queue using Michael & Scott algorithm with hazard pointers
- Exponential backoff strategy for contention handling
- Batch processing support for improved throughput
- Per-worker statistics tracking and performance monitoring
- Drop-in API compatibility with standard thread_pool
Performance Improvements:
- 2.14x average throughput improvement (2.48M vs 1.16M jobs/s)
- 7.7x faster enqueue operations (320ns vs 2,450ns)
- 5.4x faster dequeue operations (580ns vs 3,120ns)
- Up to 3.46x better performance under high contention (16+ producers)
- Maintains performance with extreme thread counts (64+)
Implementation Details:
- Added lockfree_thread_pool class in thread_pool module
- Added lockfree_thread_worker with configurable backoff strategies
- Worker statistics include jobs processed, processing time, idle time
- Memory usage ~188KB per worker (includes hazard pointers)
- Fixed all compilation warnings (sign conversion, volatile increment)
Benchmarks:
- Added lockfree_comparison_benchmark using Google Benchmark
- Added lockfree_performance_benchmark for detailed analysis
- Moved performance tests from root to benchmarks directory
- Updated CMakeLists.txt to build new benchmarks
Documentation:
- Updated README.md with lock-free pool features and usage examples
- Updated performance.md with comprehensive benchmark results
- Added usage guidelines for choosing between implementations
- Documented when to use lock-free vs standard pools
Sample Updates:
- Converted lockfree_thread_pool_sample to showcase new implementation
- Added batch processing and statistics examples
- Demonstrated high-contention scenarios
* feat: Add lock-free logger implementation with spdlog comparison
- Implement lock-free logger using lockfree_job_queue for high-concurrency scenarios
- Add comprehensive benchmarks comparing standard vs lock-free logger performance
- Add spdlog to dependencies and create comparison benchmark suite
- Performance improvements: up to 237% better throughput at 16 threads
- Single-threaded overhead: -22% (acceptable trade-off for scalability)
- Add lockfree_logger_sample demonstrating usage and performance benefits
Benchmark results (vs spdlog):
- Single-thread: spdlog async leads (5.35M/s) vs Thread System (4.34M/s)
- Multi-thread: Thread System Lock-free dominates (2.1x faster at 4 threads)
- Latency: Thread System 15.7x lower latency than spdlog (148ns vs 2,333ns)
- Scalability: Only Thread System Lock-free maintains performance under contention
* Fix Windows ARM64 build script to handle test target properly
- Handle multiple build targets correctly by parsing semicolon-separated list
- Replace test targets with sample targets on Windows where tests are disabled
- Update library target names to match actual CMake target names
- Improve error handling to continue building remaining targets on failure
- Add appropriate warnings when tests are requested on Windows
* Add pragma warning suppression for C4324 in lock-free headers
- Add #pragma warning(push/pop) with disable 4324 in hazard_pointer.h
- Add same suppression in lockfree_job_queue.h
- Add same suppression in node_pool.h
- C4324 warnings are expected for cache-line aligned structures
- This is intentional design to prevent false sharing in lock-free code
* Fix C4127 warning by using if constexpr for compile-time conditions
- Replace if with if constexpr for sizeof(wchar_t) comparisons
- These are compile-time constants so if constexpr is appropriate
- Eliminates conditional expression is constant warning1 parent b93b92a commit 947c7a1
64 files changed
Lines changed: 9031 additions & 493 deletions
File tree
- benchmarks
- logger_benchmarks
- thread_base_benchmarks
- thread_pool_benchmarks
- typed_thread_pool_benchmarks
- docs
- samples
- hazard_pointer_sample
- lockfree_thread_pool_sample
- lockfree_typed_thread_pool_sample
- logger_samples
- mpmc_queue_sample
- node_pool_sample
- thread_pool_sample
- typed_lockfree_job_queue_sample
- typed_lockfree_thread_pool_sample
- typed_thread_pool_sample_2
- typed_thread_pool_sample
- sources
- lockfree
- logger/core
- thread_base/lockfree
- memory
- queues
- thread_pool
- core
- workers
- typed_thread_pool
- pool
- scheduling
- utilities/conversion
- unittest/thread_base_test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
23 | 33 | | |
| 34 | + | |
| 35 | + | |
24 | 36 | | |
25 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
26 | 48 | | |
27 | 49 | | |
28 | 50 | | |
29 | | - | |
| 51 | + | |
30 | 52 | | |
31 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
32 | 59 | | |
33 | 60 | | |
34 | 61 | | |
| |||
51 | 78 | | |
52 | 79 | | |
53 | 80 | | |
| 81 | + | |
54 | 82 | | |
55 | 83 | | |
56 | 84 | | |
| |||
Lines changed: 293 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
0 commit comments