longshore
longshore is an object storage client written in Rust. It is built to move a
lot of data with little CPU: one thread per core on Linux io_uring, all memory
allocated at start-up, and no copy of an upload's body made by the client,
which hands large sends to the kernel as zero-copy sends. On macOS (kqueue)
and on Linux hosts without io_uring (epoll), it also runs on a portable
POSIX readiness backend for development, tests, and non-ring environments.
It talks to:
- Amazon S3
- S3-compatible stores, with the bucket in the host name or in the path. Run against Linode Object Storage and versitygw
- Google Cloud Storage, with a bearer token
The design follows the TigerBeetle talk The Fastest Object Storage Client in the World.
This is a library under development. It is published on crates.io, and its API will change between releases. Status lists what works and against which stores, and Limits lists what has not been done, measured or proven.
Performance
These figures are for the Linux io_uring backend (not the portable POSIX
backend). One client thread against Amazon S3, 8 MiB objects, from instances in
the same region as the bucket. Medians of five runs, and of eight for HTTPS PUT.
GB means 10^9 bytes.
| Request | Graviton4, 300 Gbit/s card | AMD Zen 5, 200 Gbit/s card |
|---|---|---|
| PUT, plain HTTP | 36.7 GB/s | 22.4 GB/s |
| PUT with a CRC-64 checksum on every body | 16.4 GB/s | 13.3 GB/s |
| GET | 4.4 GB/s | 7.9 GB/s |
| HTTPS PUT, 3 MiB send batch | 5.2 GB/s | 7.3 GB/s |
| HTTPS GET | 2.7 GB/s | 5.1 GB/s |
Plain PUT fills the 300 Gbit/s card with half of the client's thread idle. Every row below it is bound by the one core the client runs on, and grows with more I/O threads: eight of them store 31.1 GB/s over HTTPS on the Graviton4 instance, with a checksum on every body.
These figures need the preference for large-segment addresses, which is off
by default. Measurements has the conditions, the
figures for several threads, the comparison with s5cmd and the AWS CLI, and
runs between two machines. Every measurement is in
bench/results/ with the conditions it was taken under.
Using it
[]
= "0.2"
The API documentation is on docs.rs, and for
the main branch at https://carverauto.github.io/longshore/.
longshore::client puts the store behind a handle that any thread can
share, over one or more I/O threads that share nothing.
use Builder;
use Credentials;
let credentials = new.unwrap;
let mut settings = new;
settings.tls = true;
settings.port = 443;
settings.threads = 4; // four independent I/O threads
let client = settings.build.unwrap;
// A body lives in a registered buffer borrowed from the client, so the
// client never copies it. The operation takes the buffer and hands it back.
let mut body = client.buffer_blocking;
body.as_mut_slice.copy_from_slice;
let = client.store.wait;
stored.unwrap;
let = client.fetch.wait;
assert_eq!;
assert_eq!;
Every operation returns a value that is a Future and also has a blocking
wait, so the same calls work under any async executor and from plain
threads. The shareable client covers multipart uploads,
the calls that report exactly what the store answered, the settings, and
how it is tested. The store's own API is lower level:
Building, testing and running against a store shows how
to drive it.
File operations
longshore::io also supports local file I/O through fixed FileSlots on the
same single-threaded Io queue (UringIo, PosixIo, and SimIo):
- 11 file operations:
FileOpen(withread,write,create,exclusive,empty,direct, anddirectoryflags),FileClose,FileRead,FileWrite(64-bit offsets into registered buffers),FileSync(datasyncor full sync),FileReserve(extend or keep size),FilePunch(block-aligned hole punching),FileStatus(256-byte Linuxstatxlayout withfiles::file_size),FileRename,FileUnlink, andFileMkdir. - No truncate or directory listing: reopen with
OpenFlags::emptyto reset a file from its start, and probe fixed names or keep an index file rather than listing a directory. - Linked chains (
Io::submit_chain): submits file operations atomically (IOSQE_IO_LINKonio_uring), such as write-then-sync in one submission. A chain stops at the first failure or short read/write, completing later members with-ECANCELED. - Aligned pool: set
Limits::aligned_buffers,Limits::aligned_buffer_size, andLimits::block_size(a power of two>= 4096matching the storage device's sector/block size forO_DIRECTandFilePunch). Pools are registered with the kernel as<= 1 GiBcontiguous ranges of whole buffers, removing the 16,384-buffer limit.
Simulated disk
longshore::sim::SimIo includes a preallocated deterministic virtual disk for
testing file and WAL recovery alongside virtual sockets under one PRNG seed and
one virtual clock (zero heap allocation after setup):
- Setup (
SimIo::setup_disk): takes aDiskConfigfixingmax_files,max_dirs,max_bytes_per_file,max_name_len,write_log_entries,write_log_bytes,read_error_sectors, andsector_size(512or4096). - Durable vs. unsynced state: files hold durable bytes plus an ordered
write log overlaid on
FileRead.FileSyncfolds clean log entries into durable state; when the log is full, the oldest clean entry is written back automatically. Directories track durable names separately from unsynced create, mkdir, rename, and unlink changes until a directoryFileSync, and openFileSlots survive rename or unlink of their paths. - Whole-machine
SimIo::power_loss: drops every in-flight socket and file operation with no completion, frees all socket and file slots, clears timers and the waker flag, settles each unsynced write in order by the seed (whole, dropped, or cut at an interior sector boundary for multi-sector writes), and settles each unsynced directory change while preserving persistent sector read errors and the placed-fault operation counter. - Fault injection (
DiskFaults,PlacedFault,SimIo::corrupt_medium_bit):SimIo::set_disk_faultssets 11 independent parts-per-million rates (all0by default, drawing zero PRNG values so traces without disk faults stay unchanged):short_write(aborts chains with-ECANCELED),torn_reported,torn_silent,lost_reported,lost_silent,misdirected_write,read_error(persistent per sector until covered by a full-sector write orFilePunch),bit_flip(read buffer only),sync_fail(-EIOwith LinuxAS_EIOwrite poisoning so covered writes never become durable),reserve_refused(-ENOSPC), andpunch_refused(-EOPNOTSUPP).SimIo::place_disk_faulttargets a 1-based submitted file operation withFail,FailAfter, or any write fault, andSimIo::disk_fault_countersexposes zero-allocation per-fault counts.
Serving with longshore
longshore::io and longshore::stream provide single-threaded server primitives
across UringIo, PosixIo, and SimIo:
- TCP and Unix-domain listeners:
Io::listenbinds a TCP listener, andIo::listen_unixbinds a Unix-domain stream socket by path.Op::ConnectUnixcopies a NUL-terminated path from a pool buffer at submission time into slot storage. - Armed accept (
Op::ArmedAccept): accepts connections on a listener with one submission, placing each accepted socket into a free slot inside the reserved rangeLimits::accept_range_start..accept_range_start + accept_range_lenand reporting the slot index withCompletion::more == true. When the range is full, the incoming connection is dropped and the armed accept ends with-ENFILE(or-EMFILE). - Socket options & shutdown-before-close:
Io::no_delay(TCP_NODELAY) andIo::keep_alive(SO_KEEPALIVE) apply to TCP listeners and descriptor-created TCP connects (failing the connect rather than falling back if options cannot be set; ignored for UDP and Unix-domain sockets).Op::Closecancels in-flight operations on the socket and submitsshutdownbeforecloseon connected stream sockets so peers observe the end. - Byte stream (
longshore::stream::Stream): plain-or-TLS stream wrapper overIowith zero HTTP dependency, usable on both connecting and accepting sides.
Buffer ring
- Configuration (
Limits): setLimits::ring_buffers(up to32_768) andLimits::ring_buffer_sizeto add a fourth buffer class in the pool backed on Linuxio_uringby page-aligned index memory (IORING_REGISTER_PBUF_RING). IfUringIocannot quiesce cleanly on drop, buffer-ring index memory is leaked alongside the pool. - Armed receive (
Op::ArmedRecv): takes a buffer from the ring only when bytes arrive, so idle plain connections hold no buffer. Completions carrying bytes setCompletion::buftoSome(id)andCompletion::more; callers read bytes in place and return the buffer viaIo::give_back(id)with no system call. Empty completions (result <= 0) return their buffer internally (buf == None), peer EOF ends with0, and an empty ring ends with-ENOBUFSleaving unread bytes in the socket. Armed operations count towardLimits::ops_maxuntil their final (more == false) completion.
TLS feature
tlsis a default-on Cargo feature acrosslongshore,longshore_s3,longshore_http_client, andlongshore_stream.- Building
longshorewith--no-default-featuresexcludeslongshore_tlsandaws-lc-sysfrom its resolved dependencies (Builder::buildreturnsBuildError::Settingnamingtlsif TLS is requested). - What it does not remove:
longshore_s3still compiles C viaringfor request signing, an active TLSStreamstill keeps two TLS record buffers per connection, and default workspace test runs andlongshore-benchstill enabletls(non-TLS workspace tests run with--exclude longshore-bench --no-default-features).
Passing messages between cores
longshore::mailbox(longshore_mailbox): bounded lock-free MPSC queue forCopymessages into a thread owning anIo(Io::waker()andOp::AwaitWake, with zero timers), plus a thread-parking receiver mode for threads without anIo.- Back pressure,
stop, and atomicclose:TrySendError::Fullreturns the message without allocating;stopuses a+ 1reserved slot so prior messages are delivered first while later sends are refused; receivercloseis atomic withsend, keeping answers already written and answering sent-and-unanswered slots with the closed outcome. - Slot pools and futures: generic
Poolwith a preallocated waiter queue (Builder::waiterson the S3 client; grows dynamically if exceeded), single- and multi-pool waiting (SlotWaiter),detachreturning the caller's attachedu32tag strictly after freeing the slot,CallFuture, and sharedblock_on. - Verification: tested under
loom(scripts/test-model.sh),alloc_guard::sealed, and deterministic multi-coreEngine<Virtual>simulation.
Requirements
- Linux 6.1 or later (x86-64 or AArch64) for
io_uring(andepollwhenBuilder::portableis set), or macOS for the portablekqueuebackend (without core pinning). Other targets build the crate and run the simulator, whileclient::Builder::buildreturnsBuildError::Unsupported. - A recent stable Rust toolchain.
RLIMIT_MEMLOCKandRLIMIT_NOFILE:UringIoregisters its buffer pool as locked memory (charged againstRLIMIT_MEMLOCK, summed across all rings owned by the user; processes withCAP_IPC_LOCKare exempt) and sizes the fixed file table tosockets_max + files_max(which must not exceedRLIMIT_NOFILE).- Platform notes:
- On Linux 6.1
io_uring,FileSync,FileReserve,FilePunch,FileRename,FileUnlink,FileMkdir, and creating/emptyingFileOpenexecute on kernelio-wqworker threads and still report through the ring's completion queue. - On macOS (
PosixIo), file operations block the calling thread:OpenFlags::directusesF_NOCACHE(with alignment enforced byio::files), bothFileSyncmodes useF_FULLFSYNC,FileReserveusesF_PREALLOCATE(which may set aside less space than requested), andFilePunchusesF_PUNCHHOLE(returning-EOPNOTSUPPon filesystems without support).
- On Linux 6.1
The simulator, unit, property, and portable kqueue backend and client tests
run directly on macOS. Anything that uses io_uring (and Linux epoll) has to
run on a Linux host.
To run the real-kernel checks (scripts/test-linux.sh) from a Mac or local
workstation, configure ~/.config/longshore/test-hosts (or set
LONGSHORE_TEST_HOSTS_FILE) with one <rust-target> <ssh-destination> per
line, for example:
aarch64-unknown-linux-musl user@arm-host
x86_64-unknown-linux-musl user@x86-host
scripts/test-linux.sh fails if no host is configured so the io_uring checks
are never silently skipped.
In a container, io_uring needs a seccomp profile that allows it and a
locked-memory limit large enough for the client's buffers. Both are set on
the node. See Running in containers.
Documentation
| Document | Contents |
|---|---|
| Status | What works, and against which stores |
| How it works | The design, and the crates in this repository |
| The shareable client | The handle other threads use: operations, settings, failure behaviour |
| Building, testing and running against a store | The test scripts, and s3_uring against a real bucket |
| Running in containers | The seccomp profile and the locked-memory limit |
| Measurements | Every benchmark table, with what bounds each figure |
| Limits | What has not been done, measured or proven |
bench/README.md |
How to run the benchmarks |
License
Apache License 2.0. See LICENSE.