MyraTransport Guide
📝 This documentation is maintained in the myra-transport repository. View source | Last synced: 2025-12-05
MyraTransport Usage Guide
This document reflects the current APIs in myra-transport as of November 2025. Older snippets (single-argument TransportFactory.create, TLS builders, custom batching configs, etc.) no longer match the codebase and have been removed or updated.
Quick Start
Dependencies
dependencies
Minimal TCP Client
;
;
;
;
;
;
TransportConfig config ;
SocketAddress address ;
Transport transport ;
CompletableFuture connected ;
connected.;
try
transport.;
Key takeaways:
- Always supply the remote
SocketAddresswhen callingTransportFactory.create. - Acquire buffers via
transport.acquireBuffer()and close them (or use try-with-resources) to return them to the pool. send,receive, andrequestreturnCompletableFutures.
Configuration Essentials
TransportConfig currently exposes three knobs:
TransportConfig config ;
- backendType: selects
IO_URING(default) orNIO.XDPandDPDKenums exist for future work but currently throwUnsupportedOperationException. - registeredBuffers: controls pool size and per-buffer capacity. Disabling registered buffers throws during factory creation because every backend expects them today.
- connectionTimeout: passed through to backends when establishing new connections.
Factory & Connection Pooling
TransportFactory centralizes object creation:
SocketAddress remote ;
Transport transport ;
ConnectionPool pool ;
Transport pooled ;
// ... use pooled transport ...
pool.;
pool.;
TransportFactory.create(config, remote)wires up aTcpTransport, backend, and registered buffer pool for a single endpoint.TransportFactory.createPool(config)returnsConnectionPoolImpl, which lazily spins up transports per address and reuses them. Pool limits default to 16 connections per host.
Core Interfaces Snapshot
Transport
RegisteredBuffer & Pool
RegisteredBufferbehaves like a fixed-size byte buffer backed by aMemorySegment.RegisteredBufferPoolImplpre-allocates aligned off-heap segments and hands outRegisteredBufferviews. Callingclose()on a buffer returns it to the pool.
TransportBackend
Backends abstract system-specific I/O. The stock implementations are:
express.mvp.myra.transport.iouring.IoUringBackendexpress.mvp.myra.transport.nio.NioBackend
Both expose send, receive, connect, batching hooks, and reporting via BackendStats.
Working with Registered Buffers
try
Tips:
- Call
buffer.clear()before reusing manually. - Check
transport.availableBufferSpace()before starting bursty workloads to avoid pool exhaustion. - Never stash
MemorySegmentreferences after closing the buffer; the underlying memory is recycled.
Connection Pool Example
SocketAddress marketData ;
ConnectionPool pool ;
pool.;
Internally the pool maintains a semaphore per endpoint and automatically spins up new transports (with their own buffer pools) when capacity allows.
Backend Selection
| Backend | Status | Notes |
|---|---|---|
IO_URING | ✅ | Requires Linux 5.1+, fastest path, registered buffers mandatory |
NIO | ✅ | Works everywhere, lower throughput, ignores registered buffers |
XDP / DPDK | planned | Enum values exist but TransportFactory throws UnsupportedOperationException |
Switch backends via TransportConfig.Builder.backendType.
Monitoring & Health
TcpTransport.getHealth() returns a TransportHealth snapshot:
TransportHealth health ;
if
Backends also expose BackendStats (operation counts, errors) and methods such as submitBatch() / poll() for event-loop integrations.
Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
IllegalArgumentException: Registered buffers must be enabled | RegisteredBuffersConfig.enabled(false) | Leave buffers enabled (current backends assume them) |
| Connection hangs indefinitely with NIO backend | Network connectivity issue or backend bug (fixed in latest version) | Ensure you’re using the latest version; connection should timeout within 5-7 seconds |
Connection timeout after 5000ms | Remote server not reachable or not listening | Verify server is running and accessible; check firewall rules |
Connection pool exhausted | More concurrent borrows than maxConnectionsPerHost | Release transports promptly or raise the permit count inside ConnectionPoolImpl |
UnsupportedOperationException: IO_URING backend not yet implemented | Using XDP/DPDK types | Stick to IO_URING or NIO for now |
UnsatisfiedLinkError during IoUringBackend init | Missing liburing | Install liburing or let factory fall back to NIO |
Complete Echo Example
;
For additional API docs, generate Javadoc (./gradlew :lib:javadoc) and open lib/build/docs/javadoc/index.html.