Skip to content
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ Notable changes are recorded from 0.5.0 onward.

### Enhancements

- Added `SyncTableReader`, a blocking Arrow IPC stream reader for `std::io::Read` sources. It uses the same decoding implementation and `DecodeLimits` as `TableReader` and returns tables.
- Added `SyncUdsTableReader` and `SyncUdsTableWriter` under the `uds` feature for persistent, high-volume feeds over Unix domain sockets. They run on dedicated threads without an async runtime. Both provide `connect`, `accept` and `from_stream` and share the wire format used by `UdsTableReader` and `UdsTableWriter`, allowing synchronous and asynchronous peers to interoperate.
- Added `SyncTableSink`, a blocking Arrow IPC table sink for `std::io::Write` destinations and the synchronous counterpart to `GTableSink`. It encodes Stream protocol batches using a reusable buffer. Both `SyncTableWriter` and `SyncUdsTableWriter` write through this sink.
- Added `SyncTableReader`, a blocking Arrow IPC reader for `std::io::Read` sources, using the same decoder and `DecodeLimits` as `TableReader`.
- Added `SyncUdsTableReader` and `SyncUdsTableWriter` under the `uds` feature for blocking Unix domain socket feeds. These are compatible with asynchronous peers due to the process boundary.
- Added `SyncTableSink`, a blocking Arrow IPC sink for `std::io::Write` destinations, with reusable encoding buffers.
- Added `SyncWebSocketTableReader` and `SyncWebSocketTableWriter` under the `websocket` feature for blocking plaintext WebSocket feeds, with the same wire format, `DecodeLimits` and `Compression` options as the async types.
- Added `SyncWebSocketTransport`, `SyncWsRead` and `SyncWsWrite` for blocking WebSocket I/O, including complete text and binary message reads.
- Added `WsFrameDecoder` and `WsFrameEncoder` for shared protocol handling across synchronous and asynchronous adapters. Existing `WsRead` and `WsWrite` APIs and behaviour are unchanged.

### Breaking Changes

Expand Down
8 changes: 6 additions & 2 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Other transports (HTTP/2, QUIC, WebSocket, UDS, files, memory maps) expose the s

## Capabilities

**Transports:** TCP, Unix domain sockets, HTTP/2, QUIC, WebSocket, WebTransport, standard I/O, `io_uring`. Unix domain sockets are also available in sync form, with no async runtime.
**Transports:** TCP, Unix domain sockets, HTTP/2, QUIC, WebSocket, WebTransport, standard I/O, `io_uring`. Unix domain sockets and WebSocket are also available in sync form, without an async runtime.

**Formats:** Arrow IPC (file and stream), CSV, JSON, NDJSON, Parquet, TLV framing, memory maps, chunked datasets.

Expand Down Expand Up @@ -124,6 +124,10 @@ Sync forms read and write tables from a dedicated thread with no async runtime,
| `SyncTableWriter` | Any `std::io::Write` (Arrow IPC stream or file) |
| `SyncUdsTableReader` | Unix domain socket, `connect` or `accept` |
| `SyncUdsTableWriter` | Unix domain socket, `connect` or `accept` |
| `SyncWebSocketTableReader` | WebSocket `ws://`, `connect` or `accept` |
| `SyncWebSocketTableWriter` | WebSocket `ws://`, `connect` or `accept` |
| `SyncWebSocketTransport` | WebSocket `ws://` connection setup, `connect`, `bind` or `accept` |
| `SyncWsRead`, `SyncWsWrite` | WebSocket byte streams, and whole text or binary messages through `SyncWsRead::read_message` |

```rust
use lightstream::models::readers::sync_uds::SyncUdsTableReader;
Expand Down Expand Up @@ -216,7 +220,7 @@ cargo run --example uds_arrow --features uds
| `tcp` | TCP transport |
| `http` | HTTP/2 transport |
| `quic` | QUIC transport |
| `websocket` | WebSocket transport |
| `websocket` | WebSocket transport, in async and sync forms |
| `uds` | Unix domain sockets, in async and sync forms |
| `stdio` | Standard I/O |
| `webtransport` | WebTransport (experimental) |
Expand Down
73 changes: 68 additions & 5 deletions rust/benches/transport/transport_bench_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//! `transport_<shape>_<scale>`. Enabled transport and compression combinations
//! are registered as separate benchmarks within the group.
//!
//! Supported benchmarks include TCP, Unix domain sockets in async and sync
//! forms, WebSocket, QUIC, WebTransport, HTTP/2 and the Lightstream protocol
//! Supported benchmarks include TCP, Unix domain sockets and WebSocket in
//! async and sync forms, QUIC, WebTransport, HTTP/2 and the Lightstream protocol
//! over TCP. The `io_uring`
//! feature adds TCP and UDS variants. The `zstd` and `tls` features add their
//! respective compression and TLS variants.
Expand Down Expand Up @@ -162,6 +162,17 @@ fn bench_transport(c: &mut Criterion) {
"websocket_zstd",
Some(Compression::Zstd),
);
#[cfg(feature = "websocket")]
bench_websocket_sync(&mut group, &table, &schema, &dict_regs, "websocket_sync", None);
#[cfg(all(feature = "websocket", feature = "zstd"))]
bench_websocket_sync(
&mut group,
&table,
&schema,
&dict_regs,
"websocket_sync_zstd",
Some(Compression::Zstd),
);

// ---- TCP TLS ---------------------------------------------------
#[cfg(all(feature = "tcp", feature = "tls"))]
Expand Down Expand Up @@ -372,9 +383,6 @@ fn bench_uds(
}

/// Sync UDS throughput through `SyncUdsTableWriter` and `SyncUdsTableReader`.
///
/// The writer and reader each run on their own thread with no async runtime,
/// matching the deployment of sync sources and sinks.
#[cfg(feature = "uds")]
fn bench_uds_sync(
group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>,
Expand Down Expand Up @@ -510,6 +518,61 @@ fn bench_websocket(
});
}

/// Sync WebSocket throughput through `SyncWebSocketTableWriter` and
/// `SyncWebSocketTableReader`.
#[cfg(feature = "websocket")]
fn bench_websocket_sync(
group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>,
table: &Arc<Table>,
schema: &[Field],
dict_regs: &[(i64, Vec<String>)],
name: &str,
compression: Option<lightstream::compression::Compression>,
) {
use lightstream::models::readers::sync_websocket::SyncWebSocketTableReader;
use lightstream::models::transports::sync_websocket::SyncWebSocketTransport;
use lightstream::models::writers::sync_websocket::SyncWebSocketTableWriter;

group.bench_function(name, |b| {
b.iter_custom(|iters| {
let listener = SyncWebSocketTransport::bind("ws://127.0.0.1:0").unwrap();
let url = format!("ws://{}", listener.local_addr().unwrap());

let write_table = Arc::clone(table);
let write_schema = schema.to_vec();
let write_dicts = dict_regs.to_vec();
let n = iters;

let writer = std::thread::spawn(move || {
let mut writer =
SyncWebSocketTableWriter::connect(&url, write_schema, compression).unwrap();
for (id, values) in write_dicts {
writer.register_dictionary(id, values);
}
for _ in 0..n {
writer.write_table((*write_table).clone()).unwrap();
}
writer.finish().unwrap();
});

let mut reader = SyncWebSocketTableReader::accept(&listener, None).unwrap();

let start = std::time::Instant::now();
let mut count = 0u64;
while let Some(batch) = reader.read_next().unwrap() {
assert!(batch.n_rows > 0);
std::hint::black_box(&batch.cols);
count += 1;
}
let elapsed = start.elapsed();
assert_eq!(count, n);

writer.join().unwrap();
elapsed
});
});
}

// ---------------------------------------------------------------------------
// Lightstream protocol over TCP
// ---------------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ pub mod models {
/// TLV wire format encoders
pub mod tlv;

/// WebSocket frame encoder
#[cfg(feature = "websocket")]
pub mod websocket;

/// CSV encoder for tables and supertables
#[cfg(feature = "csv")]
pub mod csv;
Expand Down Expand Up @@ -189,6 +193,10 @@ pub mod models {
/// TLV stream decoder
pub mod tlv;

/// WebSocket frame decoder
#[cfg(feature = "websocket")]
pub mod websocket;

/// ASCII-to-integer parser used by the CSV decoder.
#[cfg(feature = "csv")]
mod int_ascii;
Expand Down Expand Up @@ -279,6 +287,10 @@ pub mod models {
#[cfg(feature = "websocket")]
pub mod websocket;

/// Sync WebSocket table reader over `std::net`.
#[cfg(feature = "websocket")]
pub mod sync_websocket;

/// QUIC table reader
#[cfg(feature = "quic")]
pub mod quic;
Expand Down Expand Up @@ -384,6 +396,10 @@ pub mod models {
#[cfg(feature = "websocket")]
pub mod websocket;

/// Sync WebSocket table writer over `std::net`.
#[cfg(feature = "websocket")]
pub mod sync_websocket;

/// QUIC table writer
#[cfg(feature = "quic")]
pub mod quic;
Expand Down Expand Up @@ -448,6 +464,10 @@ pub mod models {
#[cfg(feature = "websocket")]
pub mod websocket;

/// Sync WebSocket Transport over `std::net`.
#[cfg(feature = "websocket")]
pub mod sync_websocket;

/// HTTP/2 Transport.
#[cfg(feature = "http")]
pub mod http;
Expand Down Expand Up @@ -484,6 +504,10 @@ pub mod models {
#[cfg(feature = "websocket")]
pub mod websocket;

/// Sync WebSocket byte stream adapters over `std::io`.
#[cfg(feature = "websocket")]
pub mod sync_websocket;

/// QUIC byte stream adapter.
#[cfg(feature = "quic")]
pub mod quic;
Expand Down
Loading
Loading