Developer Tools Systems Programming 1 vues

riyaneel/Tachyon: Sub-100ns Cross-Language IPC for ML and Trading

M
Mohamed IDBRAHIM
Auteur
riyaneel/Tachyon: Sub-100ns Cross-Language IPC for ML and Trading

riyaneel/Tachyon: Sub-100ns Cross-Language IPC for ML and Trading

Developers building high-performance systems face a persistent bottleneck: moving data between processes written in different languages without sacrificing speed. A C++ inference engine generating tensors for a PyTorch model, a Rust market-data feed pushing ticks to a Python↗ Bright Coding Blog strategy, or a real-time encoder streaming frames to a consumer—all require inter-process communication that doesn't introduce serialization overhead, kernel copies, or language barriers. Most solutions force a trade-off: either stay within one language ecosystem or accept microsecond-to-millisecond latency penalties.

riyaneel/Tachyon addresses this directly. It is an IPC/RPC primitive built on shared memory that achieves 49.9 ns round-trip latency across eight languages—Python, Node.js, Java, Kotlin, Rust, Go, C#, and C++—with zero-copy semantics and no broker or daemon. This article examines what Tachyon is, how it works, and where it fits in performance-critical architectures.

What is riyaneel/Tachyon?

riyaneel/Tachyon is an open-source IPC/RPC primitive written in C++ and distributed under the Apache License 2.0. With 298 GitHub stars and 15 forks as of its last commit on June 23, 2026, it is a relatively young but technically focused project maintained by riyaneel. The repository provides native bindings for eight languages, making it one of the few shared-memory IPC solutions designed explicitly for polyglot environments.

Tachyon's core design principle is same-machine, RAM-speed communication. It uses Linux memfd (memory file descriptors) and SCM_RIGHTS socket passing to establish a shared-memory segment between processes, then discards the control socket entirely. All subsequent data transfer happens in userspace through a lock-free single-producer, single-consumer (SPSC) ring buffer. The project explicitly does not support network transport—this is a deliberate constraint that eliminates entire categories of overhead.

The relevance of Tachyon lies in its specific targeting of cross-language workloads that other fast IPC systems ignore. iceoryx achieves ~150 ns but is C++-only. Aeron reaches ~250 ns but requires matching languages on both endpoints. Chronicle Queue is Java-only. Tachyon's claim is unique: sub-100 ns latency with native bindings for eight languages, including high-level runtimes like Python and Node.js that traditionally pay heavy serialization costs.

Key Features

Sub-100 nanosecond round-trip latency. The benchmarked p50 ping-pong RTT is 49.9 ns for 32-byte payloads, with one-way latency of 24.9 ns. This is measured on an i7-12650H with DDR5-5600, GCC 14, SCHED_FIFO priority 99, mlockall, and pinned cores.

True zero-copy semantics. Data written by a producer is read directly by the consumer with no intermediate copies. In Python, this surfaces as memoryview buffers and DLPack tensors—PyTorch can consume C++-produced tensors with no memcpy, no pickle, no JSON. The C++ and Rust APIs expose raw pointers tied to ring-buffer lifetimes.

Eight native language bindings. The project ships packages on PyPI (tachyon-ipc), npm (@tachyon-ipc/core), Maven Central (Java/Kotlin), Crates.io, Go modules, NuGet, and CMake FetchContent for C++. Each binding preserves the zero-copy contract where the host language's memory model permits.

No broker, no daemon, no media driver. Tachyon's only runtime dependency is the kernel. Two processes, one shared memfd segment, and a discarded Unix domain socket for bootstrap. This eliminates operational complexity and failure modes from intermediary processes.

Lock-free SPSC ring with hardware-aware padding. Control structures are padded to 64-byte or 128-byte boundaries to prevent false sharing. Atomic operations use memory_order_acquire/release with amortized batch publication (head/tail updates at most every 32 messages or on explicit flush()).

Hybrid wait strategy. Consumers spin briefly (cpu_relax()), then sleep via SYS_futex (Linux) or __ulock_wait (macOS) with a 200 ms watchdog. This bounds kernel sleep duration while allowing signal processing.

Native bidirectional RPC. Version 0.5.1 adds RpcBus with request/reply semantics. Two independent arenas (forward and reverse) transfer as paired memfd descriptors. Each message carries a correlation_id; replies write directly into the reverse arena with no intermediate buffer.

Use Cases

ML inference pipelines. A C++ or Rust pre-processing engine generates feature vectors faster than Python can consume them through traditional serialization. Tachyon's DLPack support lets PyTorch read tensors directly from shared memory. The documented example achieves 533K frames/second (0.53 GB/s) for 1024-byte f32[256] tensors from C++ producer to Python consumer.

Low-latency trading feeds. A native order book process pushes market data ticks at 1M+ messages/second to a Python strategy. The send_zero_copy path with typed type_id routing keeps producer latency below 100 ns per message. The RPC variant handles snapshot requests with p50 61.8 ns RTT for 176-byte payloads.

Real-time audio/video inter-process. A DSP or encoder process pushes fixed-size frames to a consumer on the same machine. The SPSC ring absorbs bursts during consumer pauses without dropping frames or blocking the producer—critical for glitch-free real-time pipelines.

Cross-language microservices on single hosts. When decomposition demands language specialization—Rust for performance, Python for ML, Node.js for I/O—but deployment stays on one machine, Tachyon eliminates the serialization tax of gRPC or ZeroMQ over localhost.

Installation & Setup

Tachyon's installation varies by language. The C++ core compiles at install time for Python; other languages use prebuilt packages.

Python (requires GCC 14+ or Clang 17+):

pip install tachyon-ipc

Note: The PyPI package is tachyon-ipc, not tachyon (an unrelated quantum simulator).

Node.js:

npm install @tachyon-ipc/core

Java (Maven):

<dependency>
    <groupId>dev.tachyon-ipc</groupId>
    <artifactId>tachyon-java</artifactId>
    <version>0.5.1</version>
</dependency>

Kotlin (Gradle):

implementation("dev.tachyon-ipc:tachyon-kotlin:0.5.1")

Rust:

cargo add tachyon-ipc

Go:

go get github.com/riyaneel/tachyon/bindings/go@v0.5.1

C#:

dotnet add package TachyonIpc

C++ (CMake FetchContent):

include(FetchContent)
FetchContent_Declare(tachyon
    GIT_REPOSITORY https://github.com/riyaneel/tachyon.git
    GIT_TAG v0.5.1
)
FetchContent_MakeAvailable(tachyon)

target_link_libraries(my_app PRIVATE tachyon)

System requirements: Linux 5.10+ (primary), macOS 13+ (tier-2). Windows is not supported—memfd and SCM_RIGHTS are POSIX-only. CMake 3.31+, Clang 17+ (21+ for preset builds).

Real Code Examples

Basic Python IPC: Producer and Consumer

Two terminals demonstrate the standard API. The consumer must start first to own the socket:

# Terminal 1 — consumer
import tachyon
with tachyon.Bus.listen("/tmp/demo.sock", 1 << 16) as bus:
    msg = next(iter(bus))
    print(f"received type_id={msg.type_id} data={msg.data}")
# Terminal 2 — producer
import tachyon
with tachyon.Bus.connect("/tmp/demo.sock") as bus:
    bus.send(b"hello tachyon", type_id=1)

The Bus.listen() call creates the Unix domain socket and shared memory segment; Bus.connect() attaches to it. The type_id parameter enables typed routing without parsing payload contents.

Python Zero-Copy with memoryview

For payloads where copying is unacceptable, the zero-copy API exposes writable and readable buffers:

# Terminal 1 — consumer
import tachyon
with tachyon.Bus.listen("/tmp/demo_zc.sock", 1 << 16) as bus:
    with bus.recv_zero_copy() as rx:
        with memoryview(rx) as mv:
            print(f"received {mv.tobytes()}")
# Terminal 2 — producer
import tachyon
payload = b"zero_copy_payload"
with tachyon.Bus.connect("/tmp/demo_zc.sock") as bus:
    with bus.send_zero_copy(size=len(payload), type_id=42) as tx:
        with memoryview(tx) as mv:
            mv[:] = payload
        tx.actual_size = len(payload)

The producer acquires a slot in the ring buffer, writes through memoryview, and commits with actual_size. No intermediate buffer is allocated.

DLPack / PyTorch Tensor Transfer

This example shows C++-to-Python tensor streaming without serialization:

# Terminal 1 — PyTorch consumer
import torch, tachyon
with tachyon.Bus.listen("/tmp/demo_dl.sock", 1 << 16) as bus:
    with bus.drain_batch() as batch:
        tensor = torch.from_dlpack(batch[0]).view(torch.float32)
        print(tensor)  # tensor([1., 2., 3., 4.])
        del tensor  # release shared memory reference
# Terminal 2 — raw data producer
import struct, tachyon
data = struct.pack("4f", 1.0, 2.0, 3.0, 4.0)
with tachyon.Bus.connect("/tmp/demo_dl.sock") as bus:
    with bus.send_zero_copy(size=len(data), type_id=1) as tx:
        with memoryview(tx) as mv:
            mv[:] = data
        tx.actual_size = len(data)

torch.from_dlpack() creates a tensor view into shared memory. The del tensor is critical—shared memory cannot be reclaimed while PyTorch holds a reference.

Rust Producer-Consumer

The Rust API mirrors C++ semantics with ownership safety:

use std::thread;
use tachyon_ipc::Bus;

const SOCK: &str = "/tmp/demo_rust.sock";
const CAP: usize = 1 << 16;

fn main() {
    let srv = thread::spawn(|| {
        let bus = Bus::listen(SOCK, CAP).unwrap();
        let guard = bus.acquire_rx(10_000).unwrap();
        println!("received {} bytes, type_id={}", guard.actual_size, guard.type_id);
        guard.commit().unwrap();
    });

    thread::sleep(std::time::Duration::from_millis(20));

    let bus = Bus::connect(SOCK).unwrap();
    bus.send(b"hello tachyon", 1).unwrap();

    srv.join().unwrap();
}

The acquire_rx timeout and explicit commit() model gives the consumer control over when the ring slot is released.

Advanced Usage & Best Practices

Capacity sizing. The 1 << 16 (64 KiB) default suits small messages. For larger payloads—e.g., 1024-byte video frames—size the ring to absorb burstiness without blocking. The [INTERNAL_LINK: ring buffer capacity planning] guide provides methodology.

CPU isolation for tail latency. The benchmarked p99.99 of 380 ns (SPSC) and 550 ns (RPC) reflects scheduler jitter on untuned kernels. For production trading systems, use isolcpus=8,9 and pin producer/consumer threads. The README notes this converges tail latency toward the p99 band.

Language ABI compatibility. The bootstrap socket validates TACHYON_MSG_ALIGNMENT between endpoints. Mismatched builds are rejected before data transfer—no silent corruption. Self-compile all endpoints from the same release tag.

Zero-copy lifetime management. In Python, memoryview and DLPack tensors hold references to shared memory. Ensure consumers release these before producers overwrite—the SPSC ring does not enforce this. The Rust guard.commit() and C++ commit_rx() APIs make this explicit.

Fan-out patterns. Tachyon is SPSC by design. For multiple consumers, deploy N independent buses. Native MPSC is planned but not yet available.

Comparison with Alternatives

Transport p50 RTT Cross-language Zero-copy RPC Notes
Tachyon 49.9 ns ✓ (8 langs) ✓ ✓ Same-machine only
iceoryx ~150 ns C++ only ✓ ✗ Automotive/ROS2 focus
Aeron IPC ~250 ns Same-lang only ✓ ✓ UDP network transport available
Chronicle Queue ~250 ns Java only ✓ ✗ Disk-persistent by design
Unix domain socket ~2 µs ✓ ✗ ✓ Kernel copies on hot path
ZeroMQ (ipc://) ~10 µs ✓ ✗ ✓ Brokerless but not zero-copy
gRPC (localhost) ~1 ms ✓ ✗ ✓ HTTP/2 overhead unsuited for IPC

Tachyon's trade-off is explicit: it sacrifices network transport and multi-producer support for minimum latency in polyglot same-machine scenarios. Choose iceoryx for C++-only embedded systems, Aeron when UDP bridging matters, or gRPC when operational familiarity outweighs latency requirements.

FAQ

Q: Does Tachyon work on Windows? A: No. memfd and SCM_RIGHTS are POSIX-only. Linux 5.10+ is primary; macOS 13+ is tier-2.

Q: Why is the Python package named tachyon-ipc? A: tachyon on PyPI is an unrelated quantum simulator. Always pip install tachyon-ipc.

Q: Can multiple consumers read from one producer? A: Not directly—Tachyon is SPSC. Use independent buses for fan-out. MPSC is planned.

Q: What's the difference between Bus and RpcBus? A: Bus is unidirectional streaming; RpcBus adds request/reply with correlation_id. RPC adds ~12 ns p50 vs SPSC for larger payloads.

Q: Is the Apache 2.0 license compatible with commercial use? A: Yes. No restrictions on commercial deployment or modification.

Q: Why does my Python consumer hang? A: Ensure the consumer calls listen() before the producer calls connect(). The socket owner must exist first.

Q: How do I avoid memory leaks with DLPack tensors? A: Explicitly del tensor or let it go out of scope. The tensor holds a shared memory reference that blocks ring reclamation.

Conclusion

riyaneel/Tachyon occupies a specific niche: same-machine IPC where cross-language support and sub-100 ns latency are both non-negotiable. It is not a general-purpose messaging system—no network transport, no persistence, no MPSC—but for ML inference pipelines, trading systems, and real-time media processing on single hosts, it eliminates serialization overhead that otherwise dominates latency budgets.

The project is best suited for teams already comfortable with lock-free programming and CPU pinning, willing to trade operational flexibility for performance. With eight language bindings and genuine zero-copy to PyTorch, it solves a problem that faster but monocultural systems ignore.

Explore the repository, run the cross-language examples, and benchmark against your current IPC path: https://github.com/riyaneel/Tachyon

Commentaires 0

Aucun commentaire pour l'instant. Soyez le premier à réagir !

Laisser un commentaire