longshore
longshore is an object storage client in Rust that moves a lot of data with
little CPU. It runs one thread per core on Linux io_uring, allocates all its
memory at start-up, and never copies an upload's body: it hands large sends to
the kernel as zero-copy sends. The same code runs on a portable backend,
kqueue on macOS and epoll on Linux hosts without io_uring, for
development, tests and hosts without the ring.
Its object store 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
On the same thread and backend, longshore also carries protocols that run
straight over TCP (longshore::tcp) and does file I/O
for programs that keep their own data on disk (longshore::file).
The design follows the TigerBeetle talk The Fastest Object Storage Client in the World.
longshore is published on crates.io and still under development; 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 come from the Linux io_uring backend, not the portable one:
one client thread against Amazon S3, 8 MiB objects, instances in the bucket's
region, medians of five runs. GB means 10^9 bytes.
| Request | Graviton4, 300 Gbit/s card | AMD Zen 5, 200 Gbit/s card |
|---|---|---|
| PUT, plain HTTP | 36.4 GB/s | 23.9 GB/s |
| PUT with a CRC-64 checksum on every body | 16.7 GB/s | 14.1 GB/s |
| GET | 4.6 GB/s | 7.9 GB/s |
| HTTPS PUT | 5.1 GB/s | 7.6 GB/s |
| HTTPS GET | 2.8 GB/s | 5.2 GB/s |
Plain PUT fills the 300 Gbit/s card and leaves half the client's thread idle. The client's one core bounds every row below it, and each grows with more I/O threads: on the Graviton4 instance, eight threads store 31.1 GB/s over HTTPS with a checksum on every body.
The 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. bench/results/ holds every measurement
with its conditions.
Using it
[]
= "0.3"
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 client = new
.tls
.port
.threads // four independent I/O threads
.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 Future that also has a blocking wait, so the
same calls work under any async executor and from plain threads.
Beyond that round trip, the client copies from and into the caller's own
slices (store_from, fetch_into), streams objects of any size
(upload, download), and asks about objects (stat, list). Each has
a complete program in
crates/longshore_s3/examples/, run
against a store the environment names:
S3_ENDPOINT=s3.us-east-1.amazonaws.com S3_REGION=us-east-1 S3_BUCKET=my-bucket \
S3_ACCESS_KEY=... S3_SECRET_KEY=... S3_TLS=1 \
The shareable client covers multipart uploads, the calls that report exactly what the store answered, the settings, and how the client is tested. The store's own API is lower level: Building, testing and running against a store shows how to drive it.
Crates
longshore is twelve crates. longshore gathers ten of the others under one
name, and most programs depend on it alone. The crates are released
together: depend on all of them at the same version.
| Crate | In longshore as |
What it does |
|---|---|---|
longshore |
Re-exports every crate below; this README | |
longshore_s3 |
store, client, crypto |
The object store, and the client any thread can share |
longshore_tcp |
tcp |
Connections and listeners for protocols over TCP: framing, frames lent in place |
longshore_file |
file |
File I/O: a fixed set of files and operations, ordered sequences, direct I/O |
longshore_common |
io, sim |
The Io trait, the io_uring and portable backends, and the simulator |
longshore_http_client |
http |
HTTP/1.1: a connection pool, and an object server for tests |
longshore_stream |
stream |
One connection's byte stream, plain or TLS |
longshore_tls |
tls |
TLS 1.3: the record layer, and the handshake from rustls |
longshore_mailbox |
mailbox |
Lock-free mailboxes between threads and I/O cores |
longshore_dns |
dns |
DNS for a fixed set of names, read from a cache |
longshore_crc |
checksum |
CRC-64/NVME and CRC-32C |
longshore_s3_cache, a transparent cache for S3 with its program
longshore-cached, is being built (openspec/changes/add-s3-cache). Until
it is done it is not in longshore and not published. longshore-bench,
in the same workspace and not published either, holds the benchmarks and
the real-kernel checks.
The I/O layer
longshore::io is a single-threaded operation queue. The client is built
on it, and other storage code can use it directly. It gives direct file
I/O with linked chains, server-side networking with armed accept and
receive over a buffer ring, lock-free mailboxes between cores, and a
simulated disk with power loss and fault injection.
The I/O layer describes each part.
TCP connections
longshore::tcp carries protocols that run straight over TCP or
Unix-domain sockets: replication, messaging, a database's own wire
protocol. The caller's loop drives a fixed set of connections and
listeners on the same backend and thread as file I/O and the object
storage client. Frames arrive whole and are lent where they were received:
a frame can be written to a direct-I/O log and sent on to other peers from
that same memory, so its bytes move once. TLS works with every provider,
and nothing allocates after the set is built.
TCP connections describes the API, the receive modes and sizing.
Files
longshore::file does file I/O for programs that keep their own data on
disk. The caller's loop drives a fixed set of files and operations on the
same backend and thread as connections and the object storage client. The
set resumes reads and writes until they are whole, sends operations that
must happen in order to the kernel as one chain, and checks direct-I/O
alignment before it submits anything. Every backend reports the same
errors, a failed sync among them. Logs, pages, records and checksums are
left to the program that uses the crate.
Files describes the API, sizing and durability.
TLS and crypto providers
HTTPS is TLS 1.3 with AES-GCM. rustls always runs the handshake. The crypto provider, a Cargo feature, decides who seals and opens the records and which crypto library rustls uses for the handshake.
| Provider | Feature flag | Records sealed and opened by | Handshake crypto | Use it when |
|---|---|---|---|---|
| AWS-LC | aws-lc (default; tls is the same) |
AWS-LC, with no copy of the body | AWS-LC | Throughput matters most: the fastest |
| ring | ring |
ring, copying each body once | ring | You want ring as the only crypto library, with no AWS-LC (and none of its C build) |
| rustls | rustls |
rustls's own record layer | ring | You want all of TLS from rustls; it allocates a buffer for every record it sends |
| none | no provider feature | — | — | Plain HTTP, for networks where everything is internal |
Performance
One client core, AES-128-GCM, 16 KiB records, in a Linux container on an Apple M3 Max. GB = 10^9 bytes. HTTPS runs over loopback with 8 connections and 8 MiB bodies; CPU is the client thread's per GB moved.
| Provider | Seal | Open | HTTPS PUT | CPU per GB | HTTPS GET | CPU per GB |
|---|---|---|---|---|---|---|
| none (plain HTTP) | — | — | 12.1 GB/s | 82 ms | 4.08 GB/s | 245 ms |
| AWS-LC | 10.2 GB/s | 11.1 GB/s | 7.20 GB/s | 139 ms | 2.99 GB/s | 333 ms |
| ring | 6.8 GB/s | 6.6 GB/s | 5.14 GB/s | 195 ms | 2.59 GB/s | 385 ms |
| rustls | 6.2 GB/s | 6.7 GB/s | 4.61 GB/s | 217 ms | 2.49 GB/s | 402 ms |
Seal and open measure the record layer alone (cargo bench -p longshore-bench --bench tls_providers); PUT and GET come from http_uring --provider. With ring, TLS adds about twice as much CPU to an upload as
with AWS-LC. bench/results/m29-tls-providers.md has the
conditions and ranges; x86-64 and cloud hosts are still to be measured.
Switching a provider on
AWS-LC, the default:
[]
= "0.3"
ring only, with no AWS-LC in the build:
[]
= { = "0.3", = false, = ["ring"] }
rustls for everything:
[]
= { = "0.3", = false, = ["rustls"] }
No TLS at all (plain HTTP; ring stays in the build for request signing):
[]
= { = "0.3", = false }
Then turn HTTPS on in the client with .tls(true), as in Using it.
Asking for TLS in a build without a provider makes build() fail with an
error that names the feature to enable.
Choosing at run time
Features add up, so a build can hold several providers, for example
features = ["aws-lc", "ring"], or because two dependencies ask for
different ones. The client then uses the first compiled in of AWS-LC, ring
and rustls, unless told otherwise:
use ;
use Credentials;
let credentials = new.unwrap;
let client = new
.tls
.port
.tls_provider
.build
.unwrap;
Choosing a provider that is not compiled in makes build() fail with an
error that names its feature. TlsProvider::compiled() says which are
available.
Requirements
- Linux 6.1 or later (x86-64 or AArch64) for
io_uring(andepollwhenBuilder::portable(true)is set), or macOS for the portablekqueuebackend (without core pinning). Other targets build the crate and run the simulator, whileclient::Builder::buildreturnsBuildError::Unsupported. - Rust 1.89 or later, the
rust-versionevery crate states. - A C compiler (GCC or Clang; on macOS, the Xcode command-line tools).
ring, which signs every request, compiles some C and assembly with it in
every build. AWS-LC, the default
aws-lcprovider (aws-lc-sys0.47), compiles a larger C library with it. On x86-64 and AArch64 Linux (glibc or musl) and on macOS that is all it needs: the crate ships the bindings, so no CMake, Go, Perl or NASM. CMake andbindgen-cli(libclang) are needed only on a target without shipped bindings, or whenAWS_LC_SYS_CMAKE_BUILDER=1orAWS_LC_SYS_NO_ASM=1asks for the CMake build; Go and Perl only for a FIPS build, which longshore does not ask for; NASM only on Windows x86-64. To leave AWS-LC out, build withdefault-features = falseand theringorrustlsfeature, or no provider for plain HTTP (see Switching a provider on).
Building, testing and running against a store has the test commands and how to run the real-kernel checks on a Linux host. The I/O layer lists the resource limits and the platform notes.
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 I/O layer | File operations, serving, the buffer ring, mailboxes, the simulated disk |
| TCP connections | longshore::tcp: connections, framing, frame memory, TLS, sizing |
| Files | longshore::file: files, sequences, direct I/O, durability, sizing |
| 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.