22
33[ ![ CI] ( https://github.com/codenimja/nimsync/actions/workflows/ci.yml/badge.svg )] ( https://github.com/codenimja/nimsync/actions/workflows/ci.yml )
44[ ![ Benchmark] ( https://github.com/codenimja/nimsync/actions/workflows/benchmark.yml/badge.svg )] ( https://github.com/codenimja/nimsync/actions/workflows/benchmark.yml )
5- [ ![ Nimble] ( https://img.shields.io/badge/nimble-v1.1 .0-orange.svg )] ( https://nimble.directory/pkg/nimsync )
5+ [ ![ Nimble] ( https://img.shields.io/badge/nimble-v1.0 .0-orange.svg )] ( https://nimble.directory/pkg/nimsync )
66[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-blue.svg )] ( LICENSE )
77[ ![ Nim] ( https://img.shields.io/badge/nim-2.0.0%2B-yellow.svg?style=flat&logo=nim )] ( https://nim-lang.org )
88![ Peak] ( https://img.shields.io/badge/peak-615M_ops/sec-success )
99![ P99] ( https://img.shields.io/badge/p99_latency-31ns-blue )
1010![ Contention] ( https://img.shields.io/badge/contention-0%25-brightgreen )
1111
12- ** Lock-free SPSC and MPSC channels for Nim with production-grade performance validation**
12+ ** Lock-free SPSC channels for Nim with production-grade performance validation**
1313
14- nimsync v1.1 .0 is production-ready for both SPSC and MPSC channels with comprehensive benchmarking following industry standards (Tokio, Go, LMAX Disruptor, Redis). Performance: 615M ops/sec SPSC peak, 16M ops/sec MPSC (2 producers) , 31ns P99 latency, stable under burst loads. This is verified, tested, real code.
14+ nimsync v1.0 .0 is production-ready for SPSC channels with comprehensive benchmarking following industry standards (Tokio, Go, LMAX Disruptor, Redis). Performance: 615M ops/sec peak throughput , 31ns P99 latency, stable under burst loads. This is verified, tested, real code.
1515
1616## Features
1717
18- - ** High throughput** : 615M ops/sec SPSC (raw), 16M ops/sec MPSC (2 producers), 512K ops/sec (async) - [ See benchmarks] ( #performance )
18+ - ** High throughput** : 615M ops/sec (raw), 512K ops/sec (async) - [ See all 7 benchmarks] ( #performance )
1919- ** Production-validated** : Comprehensive benchmark suite (throughput, latency, burst, stress, sustained)
2020- ** Industry-standard testing** : Following Tokio, Go, Rust Criterion, LMAX Disruptor methodologies
21- - ** SPSC and MPSC modes** : Single-producer or multi-producer with single consumer
2221- Lock-free ring buffer with atomic operations
2322- Zero GC pressure with ORC memory management
2423- Cache-line aligned (64 bytes) to prevent false sharing
25- - Wait-free MPSC algorithm (based on dbittman + JCTools patterns)
2624- Power-of-2 sizing for efficient operations
2725- Non-blocking ` trySend ` /` tryReceive `
2826- Async ` send ` /` recv ` wrappers for Chronos
@@ -47,7 +45,7 @@ nimble install
4745
4846## Quick Start
4947
50- ### Basic Usage (SPSC)
48+ ### Basic Usage
5149``` nim
5250import nimsync
5351
@@ -63,36 +61,6 @@ if chan.tryReceive(value):
6361 echo "Received: ", value
6462```
6563
66- ### Multi-Producer Usage (MPSC)
67- ``` nim
68- import nimsync
69- import std/[os, threadpool]
70-
71- # Create MPSC channel for multiple producers
72- let chan = newChannel[int](1024, ChannelMode.MPSC)
73-
74- # Multiple producer threads
75- proc producer(ch: Channel[int], id: int) =
76- for i in 0..<1000:
77- while not ch.trySend(id * 1000 + i):
78- discard # Spin until space available
79-
80- # Start multiple producers
81- spawn producer(chan, 1)
82- spawn producer(chan, 2)
83- spawn producer(chan, 3)
84-
85- # Single consumer
86- var count = 0
87- var value: int
88- while count < 3000:
89- if chan.tryReceive(value):
90- echo "Received: ", value
91- count.inc
92-
93- sync()
94- ```
95-
9664### Async Operations
9765``` nim
9866import nimsync
@@ -121,10 +89,7 @@ waitFor main()
12189proc newChannel[T](size: int, mode: ChannelMode): Channel[T]
12290```
12391Creates a channel with specified size (rounded to next power of 2).
124-
125- ** Modes** :
126- - ` ChannelMode.SPSC ` : Single Producer Single Consumer (fastest)
127- - ` ChannelMode.MPSC ` : Multi-Producer Single Consumer (wait-free producers)
92+ Only ` ChannelMode.SPSC ` is implemented.
12893
12994### Non-Blocking Operations
13095``` nim
@@ -150,9 +115,7 @@ proc isFull[T](channel: Channel[T]): bool
150115
151116### Comprehensive Benchmark Suite
152117
153- nimsync includes benchmarks for both SPSC and MPSC modes following industry best practices:
154-
155- #### SPSC Benchmarks (Single Producer Single Consumer)
118+ nimsync includes 7 official benchmarks following industry best practices:
156119
157120| Benchmark | Metric | Result | Industry Reference |
158121| -----------| --------| --------| --------------------|
@@ -164,36 +127,18 @@ nimsync includes benchmarks for both SPSC and MPSC modes following industry best
164127| ** Sustained** | Long-duration | Stable over 10s | Cassandra/ScyllaDB |
165128| ** Async** | Overhead | 512K ops/sec | Standard async benchmarking |
166129
167- #### MPSC Benchmarks (Multi-Producer Single Consumer)
168-
169- | Producers | Throughput | Latency (avg) | Notes |
170- | -----------| -----------| ---------------| -------|
171- | 1P | 33M ops/sec | 30ns | Comparable to SPSC |
172- | 2P | 16M ops/sec | 62ns | Optimal sweet spot |
173- | 4P | 9M ops/sec | 111ns | Good scalability |
174- | 8P | 4M ops/sec | 250ns | Contention limited |
175-
176- ** Key Findings** :
177- - Wait-free MPSC algorithm: No CAS retry loops
178- - Best performance: 2 producers (16M ops/sec)
179- - Stress test: 1M items across 8 producers (5.65M ops/sec)
180- - Latency stable: 96-117ns across 1-4 producers
181-
182130### Quick Run
183131``` bash
184- # Run SPSC benchmark suite (~18 seconds)
132+ # Run complete benchmark suite (~18 seconds)
185133./tests/performance/run_all_benchmarks.sh
186134
187- # Run MPSC benchmarks
188- nim c -d:danger --opt:speed --mm:orc tests/performance/benchmark_mpsc.nim
189- ./tests/performance/benchmark_mpsc
190-
191- # Run individual SPSC benchmarks
135+ # Run individual benchmarks
192136nim c -d:danger --opt:speed --mm:orc tests/performance/benchmark_latency.nim
193137./tests/performance/benchmark_latency
194138```
195139
196140** Full Documentation** : See [ ` tests/performance/README.md ` ] ( tests/performance/README.md ) for detailed explanations of each benchmark.
141+ ```
197142
198143### Third-Party Verification
199144
@@ -205,10 +150,9 @@ Want to verify these claims yourself?
205150
206151## Limitations
207152
208- 1 . ** Single Consumer Only** - All modes require single consumer
209- - SPSC: ONE sender, ONE receiver (fastest)
210- - MPSC: MULTIPLE senders, ONE receiver (wait-free)
211- - SPMC/MPMC not implemented
153+ 1. **SPSC Only** - Single Producer Single Consumer only
154+ - Each channel: ONE sender, ONE receiver
155+ - MPSC/SPMC/MPMC will raise `ValueError`
212156
2131572. **No close()** - Channels don't have close operation
214158 - Use sentinel values for shutdown signaling
@@ -220,16 +164,12 @@ Want to verify these claims yourself?
220164 - Starts at 1ms, backs off to 100ms max
221165 - Use `trySend`/`tryReceive` for zero-latency
222166
223- 5 . ** MPSC contention** - Best performance with 2-4 producers
224- - 8+ producers experience diminishing returns due to contention
225-
226167## Development
227168
228169### Testing
229170```bash
230- nim c -r tests/unit/test_channel.nim # Basic SPSC tests
231- nim c -r tests/unit/channels/test_mpsc_channel.nim # MPSC tests
232- nim c -r tests/unit/test_basic.nim # Version check
171+ nim c -r tests/unit/test_channel.nim # Basic tests
172+ nim c -r tests/unit/test_basic.nim # Version check
233173```
234174
235175### Benchmarking
@@ -258,8 +198,8 @@ This repository contains experimental implementations of:
258198## Roadmap
259199
260200- ✅ ** v1.0.0** : Production SPSC channels (DONE!)
261- - ✅ ** v1.1.0** : MPSC channels (DONE!)
262- - ** v1.2.0** : TaskGroup fixes + Production-ready Streams
201+ - ** v1.1.0** : MPSC channels + TaskGroup fixes
202+ - ** v1.2.0** : Production-ready Streams
263203- ** v2.0.0** : Full async runtime with actors
264204
265205## Known Issues
@@ -268,17 +208,18 @@ See [GitHub Issues](.github/) for experimental features and known limitations:
268208
269209- ** Async wrappers use polling** - exponential backoff (1ms-100ms), use ` trySend ` /` tryReceive ` for zero-latency
270210- ** TaskGroup has bugs** - nested async macros fail (not exported) - [ See issue template] ( .github/ISSUE_TASKGROUP_BUG.md )
211+ - ** MPSC not implemented** - multi-producer channels needed for actors - [ See issue template] ( .github/ISSUE_MPSC_CHANNELS.md )
271212- ** NUMA untested** - cross-socket performance unknown - [ See issue template] ( .github/ISSUE_NUMA_VALIDATION.md )
272213
273214** These are documented limitations, not intentional behavior.** Contributions to fix welcome!
274215
275216## Contributing
276217
277218Contributions welcome! Priority areas:
278- 1 . Fix TaskGroup nested async bug - [ Details] ( .github/ISSUE_TASKGROUP_BUG.md )
279- 2 . Validate NUMA performance - [ Details] ( .github/ISSUE_NUMA_VALIDATION .md )
280- 3 . Cross-platform support (macOS/Windows )
281- 4 . SPMC/MPMC channel implementations
219+ 1 . Fix TaskGroup nested async bug (blocking v0.3.0) - [ Details] ( .github/ISSUE_TASKGROUP_BUG.md )
220+ 2 . Implement MPSC channels (enables actors) - [ Details] ( .github/ISSUE_MPSC_CHANNELS .md )
221+ 3 . Validate NUMA performance - [ Details ] ( .github/ISSUE_NUMA_VALIDATION.md )
222+ 4 . Cross-platform support (macOS/Windows)
282223
283224See [ issue templates] ( .github/ ) for detailed specifications and acceptance criteria.
284225
@@ -288,17 +229,16 @@ MIT License - see LICENSE for details.
288229
289230---
290231
291- ** Status** : Production-ready SPSC and MPSC channels with comprehensive validation. Other features (TaskGroup, actors, streams ) are experimental - see [ GitHub Issues] ( .github/ ) for contributor opportunities.
232+ ** Status** : Production-ready SPSC channels with comprehensive validation. Other features (TaskGroup, MPSC, actors ) are experimental - see [ GitHub Issues] ( .github/ ) for contributor opportunities.
292233
293234---
294235
295236## Disclaimer
296237
297- ** nimsync v1.1 .0 is production-ready for SPSC and MPSC channels.**
238+ ** nimsync v1.0 .0 is production-ready for SPSC channels.**
298239
299- ✅ ** SPSC channels verified** - 615M ops/sec peak, 31ns P99 latency, 7-benchmark suite validation
300- ✅ ** MPSC channels verified** - 16M ops/sec (2 producers), wait-free algorithm, comprehensive stress testing
301- ⚠️ ** Experimental features** - TaskGroup, actors, streams not yet production-ready ([ help wanted] ( .github/ ) )
240+ ✅ ** SPSC channels verified** - 615M ops/sec peak, 31ns P99 latency, 7-benchmark suite validation
241+ ⚠️ ** Experimental features** - TaskGroup, MPSC, actors not yet production-ready ([ help wanted] ( .github/ ) )
302242
303243We document performance honestly. We benchmark rigorously. We're transparent about limitations.
304244
0 commit comments