shm-tensor-ring
Demonstrates cross-process tensor descriptor streaming and wake-latency
benchmarking over a shared mmapped file backed by x/ossync
(OS_SYNC_WAIT_ON_ADDRESS_SHARED / OS_SYNC_WAKE_BY_ADDRESS_SHARED),
compared against a POSIX pipe baseline.
The parent process initializes two lock-free ossync.Rings (request and ack)
inside a temporary MAP_SHARED file, spawns a helper subprocess via
os.Args[0] -role=consumer, and runs four checks:
- Streams 10,000 64-byte
TensorDesc descriptors with FNV-1a checksums and
verifies 0 drops and strict sequence ordering.
- Benchmarks cross-process 1-way wake latency (ping-pong
RTT / 2) over the
shared mmap rings.
- Verifies that
Ring.PopTimeout on an empty shared ring classifies Darwin's
errno as ossync.ErrTimeout / syscall.ETIMEDOUT.
- Benchmarks an equivalent cross-process POSIX pipe ping-pong baseline.
Running
CGO_ENABLED=0 go run ./examples/os/shm-tensor-ring
Flags:
-count: number of tensor descriptors to stream (default 10000)
-warmup: warmup ping-pong iterations (default 100)
-bench-samples: measured ping-pong iterations (default 1000)
-timeout: duration for the ETIMEDOUT verification check (default 20ms)
Measured Results
Measured on an Apple M4 Max (16 cores, macOS 26.6.2) with
CGO_ENABLED=0 go run ./examples/os/shm-tensor-ring:
shm-tensor-ring: count=10000 slot=64B cap=256 warmup=100 samples=1000
stream: sent=10000 received=10000 drops=0 elapsed=19.949ms throughput=501282.5 desc/s
timeout: requested=20ms elapsed=23.829ms err="ossync: wait timed out: operation timed out" (ETIMEDOUT=true)
TRANSPORT (1-WAY WAKE) P50 P95 P99
x/ossync Shared mmap 9.604µs 115.292µs 569.792µs
POSIX pipe baseline 9.791µs 122.542µs 684.187µs
ossync vs pipe p50 ratio: 1.02x