tur-rs 0.9.2

A relentless, high-concurrency download manager built for speed and efficiency. Tur uses dynamic work-stealing and aligned storage to saturate your bandwidth while maintaining a minuscule memory footprint. Inspired by the legends, built for the modern Rust ecosystem.
Documentation
use super::*;

#[derive(Debug, Default)]
pub(crate) struct SchedulerMetrics {
    pub(super) direct_assignments: Cell<u64>,
    pub(super) borrow_assignments: Cell<u64>,
    pub(super) bytes_borrowed: Cell<u64>,
    pub(super) straggler_splits: Cell<u64>,
    pub(super) tail_splits: Cell<u64>,
    pub(super) work_requests: Cell<u64>,
    pub(super) request_wait_ms: Cell<u64>,
    pub(super) prefetch_requests: Cell<u64>,
    pub(super) prefetch_ready: Cell<u64>,
    pub(super) prefetch_hits: Cell<u64>,
    pub(super) http_requests: Cell<u64>,
    pub(super) http1_requests: Cell<u64>,
    pub(super) http2_requests: Cell<u64>,
    pub(super) http3_requests: Cell<u64>,
    pub(super) http_other_requests: Cell<u64>,
    pub(super) http_setup_ms: Cell<u64>,
    pub(super) http_ttfb_ms: Cell<u64>,
    pub(super) http_stream_ms: Cell<u64>,
    pub(super) file_write_ms: Cell<u64>,
    pub(super) completed_ranges: Cell<u64>,
    pub(super) retry_attempts: Cell<u64>,
    pub(super) retry_wait_ms: Cell<u64>,
    pub(super) startup_workers: Cell<u64>,
    pub(super) startup_open_file_ms: Cell<u64>,
    pub(super) startup_first_assignment_wait_ms: Cell<u64>,
    pub(super) startup_first_request_setup_ms: Cell<u64>,
    pub(super) startup_first_byte_ms: Cell<u64>,
    pub(super) startup_total_to_first_byte_ms: Cell<u64>,
    pub(super) max_active_connections_observed: Cell<u64>,
    pub(super) reused_requests: Cell<u64>,
    pub(super) fresh_requests: Cell<u64>,
    pub(super) http1_reused_requests: Cell<u64>,
    pub(super) http1_fresh_requests: Cell<u64>,
    pub(super) http2_reused_requests: Cell<u64>,
    pub(super) http2_fresh_requests: Cell<u64>,
    pub(super) fresh_handshake_ms: Cell<u64>,
    pub(super) http1_fresh_handshake_ms: Cell<u64>,
    pub(super) http2_fresh_handshake_ms: Cell<u64>,
    pub(super) skipped_growth_samples: Cell<u64>,
    pub(super) http1_scale_adds: Cell<u64>,
    pub(super) http1_scale_drops: Cell<u64>,
    pub(super) http2_scale_adds: Cell<u64>,
    pub(super) http2_scale_drops: Cell<u64>,
    pub(super) http2_stream_adds: Cell<u64>,
    pub(super) http3_scale_adds: Cell<u64>,
    pub(super) http3_scale_drops: Cell<u64>,
    pub(super) http2_conn_adds: Cell<u64>,
    pub(super) h2_stream_saturated_count: Cell<u64>,
    pub(super) adaptive_min_steal_bytes_final: Cell<u64>,
    pub(super) adaptive_heartbeat_ms_final: Cell<u64>,
    pub(super) adaptive_refill_interval_ms_final: Cell<u64>,
    pub(super) max_prefetch_trigger_bytes: Cell<u64>,
    pub(super) max_write_buffer_target_bytes: Cell<u64>,
    pub(super) max_ewma_write_latency_x10: Cell<u64>,
}

impl SchedulerMetrics {
    pub(super) fn summary_line(&self) -> String {
        format!(
            "metrics direct_assignments={} borrow_assignments={} bytes_borrowed={} straggler_splits={} tail_splits={} work_requests={} request_wait_ms={} prefetch_requests={} prefetch_ready={} prefetch_hits={} http_requests={} http1_requests={} http2_requests={} http_other_requests={} http_setup_ms={} http_ttfb_ms={} http_stream_ms={} file_write_ms={} completed_ranges={} retry_attempts={} retry_wait_ms={} startup_workers={} startup_open_file_ms={} startup_first_assignment_wait_ms={} startup_first_request_setup_ms={} startup_first_byte_ms={} startup_total_to_first_byte_ms={} max_active_connections_observed={} reused_requests={} fresh_requests={} http1_reused_requests={} http1_fresh_requests={} http2_reused_requests={} http2_fresh_requests={} fresh_handshake_ms={} http1_fresh_handshake_ms={} http2_fresh_handshake_ms={} skipped_growth_samples={} http1_scale_adds={} http1_scale_drops={} http2_scale_adds={} http2_scale_drops={} http2_stream_adds={} http2_conn_adds={} h2_stream_saturated_count={} adaptive_min_steal_bytes_final={} adaptive_heartbeat_ms_final={} adaptive_refill_interval_ms_final={} max_prefetch_trigger_bytes={} max_write_buffer_target_bytes={} max_ewma_write_latency_ms={:.1}",
            self.direct_assignments.get(),
            self.borrow_assignments.get(),
            self.bytes_borrowed.get(),
            self.straggler_splits.get(),
            self.tail_splits.get(),
            self.work_requests.get(),
            self.request_wait_ms.get(),
            self.prefetch_requests.get(),
            self.prefetch_ready.get(),
            self.prefetch_hits.get(),
            self.http_requests.get(),
            self.http1_requests.get(),
            self.http2_requests.get(),
            self.http_other_requests.get(),
            self.http_setup_ms.get(),
            self.http_ttfb_ms.get(),
            self.http_stream_ms.get(),
            self.file_write_ms.get(),
            self.completed_ranges.get(),
            self.retry_attempts.get(),
            self.retry_wait_ms.get(),
            self.startup_workers.get(),
            self.startup_open_file_ms.get(),
            self.startup_first_assignment_wait_ms.get(),
            self.startup_first_request_setup_ms.get(),
            self.startup_first_byte_ms.get(),
            self.startup_total_to_first_byte_ms.get(),
            self.max_active_connections_observed.get(),
            self.reused_requests.get(),
            self.fresh_requests.get(),
            self.http1_reused_requests.get(),
            self.http1_fresh_requests.get(),
            self.http2_reused_requests.get(),
            self.http2_fresh_requests.get(),
            self.fresh_handshake_ms.get(),
            self.http1_fresh_handshake_ms.get(),
            self.http2_fresh_handshake_ms.get(),
            self.skipped_growth_samples.get(),
            self.http1_scale_adds.get(),
            self.http1_scale_drops.get(),
            self.http2_scale_adds.get(),
            self.http2_scale_drops.get(),
            self.http2_stream_adds.get(),
            self.http2_conn_adds.get(),
            self.h2_stream_saturated_count.get(),
            self.adaptive_min_steal_bytes_final.get(),
            self.adaptive_heartbeat_ms_final.get(),
            self.adaptive_refill_interval_ms_final.get(),
            self.max_prefetch_trigger_bytes.get(),
            self.max_write_buffer_target_bytes.get(),
            self.max_ewma_write_latency_x10.get() as f64 / 10.0,
        )
    }

    pub(super) fn add(cell: &Cell<u64>, value: u64) {
        cell.set(cell.get().saturating_add(value));
    }

    pub(super) fn update_max(cell: &Cell<u64>, value: u64) {
        if value > cell.get() {
            cell.set(value);
        }
    }
}