Skip to main content

Module streaming

Module streaming 

Source
Expand description

Streaming compression / decompression helpers。

s4_codec::Codec の bytes-in / bytes-out API は memory cap (5 GiB) を持つため 大規模オブジェクトで OOM 危険。本 module は async-compression 経由で zstd を AsyncRead/AsyncWrite に差し込み、StreamingBlob (= futures::Stream<Bytes>) ↔ AsyncRead を tokio_util::io で橋渡しする。

§対応 codec

  • CpuZstd: async_compression::tokio::bufread::ZstdDecoder で完全 streaming
  • Passthrough: 入力 stream をそのまま返す (ゼロコスト streaming)
  • NvcompZstd / NvcompBitcomp: nvCOMP は batch API のため per-chunk batch 処理 (Phase 2.1 で追加予定、現状は default の bytes-based に fallback)

§整合性検証

Streaming GET では bytes 全体の CRC32C をオンザフライで計算しつつ stream を 流す Crc32cVerifier adapter を被せる。最後の chunk が yield された時点で manifest.crc32c と比較し、不一致なら error として伝播 (= client 側で body parse 失敗として現れる)。

Structs§

Crc32cVerifyingReader
v0.8.4 #73 H-1: streaming GET integrity guard. Wraps an inner AsyncRead (typically the output of cpu_zstd_decompress_stream) and computes a rolling CRC32C as bytes flow through. On EOF the rolling CRC and the observed byte count are compared against the manifest-declared values; a mismatch surfaces as io::ErrorKind::InvalidData so the HTTP body stream fails — the client sees a truncated / aborted response rather than silent corruption.

Constants§

DEFAULT_S4F2_CHUNK_SIZE
streaming_compress_to_frames の default chunk size。
DEFAULT_S4F2_INFLIGHT
streaming_compress_to_frames の default in-flight depth (v0.3 #12)。

Functions§

async_read_to_blob
AsyncRead を 1 chunk = 64 KiB の StreamingBlob に変換 (size 不明の chunked stream)。
blob_to_async_read
StreamingBlob を AsyncRead として扱えるラッパ。
cpu_zstd_decompress_stream
CpuZstd で bodystreaming に decompress した StreamingBlob を返す。
pick_chunk_size
v0.4 #16: pick a chunk size for streaming_compress_to_frames based on the request’s Content-Length (when known). Smaller objects get smaller chunks (avoids carrying multi-MiB framing infrastructure on a 64 KiB upload); large objects get larger chunks (amortises GPU launch overhead and keeps the sidecar small).
streaming_compress_cpu_zstd
body を CPU zstd で input-streaming 圧縮し、(compressed bytes, manifest) を返す。memory peak は zstd window + 64 KiB read buffer + 圧縮済 output ≈ compressed_size + ~100 MB入力 5 GB を 100 MB に圧縮するケースで peak は ~200 MB (vs. naive bytes-buffered だと peak 5 GB)。
streaming_compress_to_frames
入力 bodychunked + framed + pipelined に圧縮した output を返す (v0.2 #4 + v0.3 #12)。
streaming_compress_to_frames_with
Like streaming_compress_to_frames but lets callers tune the in-flight depth — useful in the bench harness, and as the building block any streaming_compress_to_frames callers extend if their workload needs a non-default pipelining depth.
streaming_passthrough
body を passthrough で集めるだけ。CRC32C も計算する。
supports_streaming_compress
supports_streaming_decompress
codec が streaming-aware かを判定 (S4Service 側で fast path 分岐に使う)。