Throughput Optimization
Producer Configuration
For maximum throughput, tune the producer’s batching and backpressure settings:Append Session Configuration
For direct session control:Higher
max_unacked_bytes allows more data in flight but uses more memory. Balance this with your available resources.Parallel Submissions
Submit multiple batches concurrently:Latency Optimization
Low-Latency Producer
Minimize batching delays for low-latency scenarios:Direct Append
For single-record appends with minimal overhead:Direct
append() calls have higher per-record overhead. Use only when latency is critical and throughput is low.Connection Management
Connection Pooling
The SDK automatically pools HTTP connections:- Up to 90 concurrent requests per client
- Connections idle for 90 seconds are reaped
- Automatic reconnection on connection failure
Reuse Clients
ShareS2 instances across threads:
Memory Management
Backpressure Control
Prevent unbounded memory growth with backpressure:Streaming Large Reads
Process read batches incrementally to avoid loading entire streams into memory:Compression
Enable Compression
Reduce network bandwidth with compression:Compression::None- No compression (default)Compression::Gzip- Good balance, widely supportedCompression::Zstd- Better compression ratio, faster
When to Use Compression
Enable compression when:- Network bandwidth is limited
- Records are highly compressible (text, JSON, logs)
- Network cost is a concern
- Records are already compressed (images, video)
- CPU is constrained
- Records are very small (< 100 bytes)
Batching Strategies
Adaptive Batching
Adjust batching based on load:Size-Based Batching
For variable-sized records:Read Performance
Batch Size Tuning
Control read batch sizes for optimal memory/latency balance:Parallel Reads
Read from multiple streams concurrently:Following the Tail
Optimize for real-time consumption:Retry Configuration
Aggressive Retries
For high-availability scenarios:Fast Failure
For latency-sensitive scenarios:Monitoring and Metrics
Track Batch Sizes
Monitor Backpressure
Best Practices Summary
The S2 SDK uses
tokio for async runtime. Ensure your application uses an appropriately sized thread pool for your workload.Performance Checklist
- Batching configured appropriately for workload
- Backpressure limits set based on available memory
- Compression enabled for compressible data
- Clients reused across operations
- Sessions reused for multiple appends/reads
- Retry configuration matches availability requirements
- Monitoring in place for batch sizes and latency
- Testing completed at production scale