scpd
Heap profiles
Heap profiling is opt-in at build time and at run time:
- Build on Linux with
--features heap-profilingto use jemalloc as the global allocator, withprof:true,prof_active:false,lg_prof_sample:19(512 KiB average sampling interval, inactive until enabled). Default builds, including release builds, keep the system allocator. - Set
THRUPUT_HEAP_PROFILING=1to activate sampling at startup. Only that exact value enables it. On a build without the feature, or off Linux, scpd fails startup rather than ignoring it. - Set
SCPD_PPROF_LISTEN=127.0.0.1:9646to open a separate HTTP listener. Without it no profiling socket or task exists. The listener has no authentication and allows only loopback by default (127.0.0.0/8,::1,localhost). Hostnames are resolved and every result must be loopback.SCPD_PPROF_ALLOW_REMOTE=1permits other addresses (including0.0.0.0inside a container whose published port is restricted) and logs a warning. GET /debug/pprof/heapreturns an uncompressed pprof protobuf converted from jemallocheap_v2;HEADreturns the same headers without a body. Without activation, or for other paths, the listener returns 404; other methods get 405.- The route requires a
Hostoflocalhostor a loopback IP literal.SCPD_PPROF_ALLOW_REMOTE=1also accepts any IP-literal Host, so remote scrapes must use an IP address, not a hostname (DNS-rebinding protection). A missing Host, DNS-name Host, or cross-originOriginheader gets 403. - Profiles are symbolized in process: function names, plus file and line when debuginfo is present, innermost inlined frame first. Mappings carry GNU build IDs.
- One dump runs at a time; a concurrent request gets 429. Dump and conversion run on a blocking worker without a time limit, and the job keeps its permit if the connection is cancelled. Request reads and response writes each have a 10 second timeout.
- Dumps need a writable temporary directory. Dump files are created with random names and mode 0600 and removed afterwards.
Restart scpd after changing these environment variables. Do not set
MALLOC_CONF=prof_active:true when profiling should be off.
Tests: cargo test -p thruput-scp-server covers the converter and HTTP routing on any
platform. On Linux, cargo test -p thruput-scp-server --features heap-profiling also
takes a real jemalloc dump and checks that a retained allocation resolves by
function name and that the test executable's mapping has a build ID.
Logging
RUST_LOGcontrols log output usingEnvFiltersyntax; when unset the default is ERROR.SCPD_LOG_SPAN_EVENTS=1enables span NEW/CLOSE log events for spans selected byRUST_LOG. Unset or any other value disables these events. This does not change OpenTelemetry export.
Restart scpd after changing these environment variables.
Tracing
scpd exports its tracing spans over OTLP when OTEL_EXPORTER_OTLP_ENDPOINT
is set. Restart scpd after changing these variables.
OTEL_EXPORTER_OTLP_ENDPOINT: enables export. OTLP over gRPC only (collector port 4317), plainhttp://only; anhttps://endpoint disables tracing with a logged error.OTEL_EXPORTER_OTLP_PROTOCOL: onlygrpc. Any other value is ignored with a logged error.OTEL_SDK_DISABLED=true: no exporter or provider is built.OTEL_TRACES_SAMPLER/OTEL_TRACES_SAMPLER_ARG: defaultparentbased_traceidratioat0.05. An unknown sampler, or a ratio sampler with a missing or invalid argument, uses that default and logs an error.THRUPUT_NETWORK_HASH: set by the application that launches scpd; 64 hex characters representing the 32-byte network hash. When set, slot spans join the block trace whose ID is derived from the network hash and slot index. Sampling uses that trace ID with the configured ratio so scpd and the application keep or drop the same blocks. Missing or invalid values log one error and leave independent traces.OTEL_SPAN_FILTER: which other spans are exported, inEnvFiltersyntax (for examplewarn,scp_kernel=info). Defaultinfo. It is independent ofRUST_LOG, which only controls the log output. Slot spans (targetscpd::slot) are always exported so correlation holds, subject to sampling.OTEL_SERVICE_NAME(defaultscpd) andOTEL_RESOURCE_ATTRIBUTES. The resource also carriesservice.versionandservice.instance.id(the node's hex ed25519 public key).
An unreachable collector logs one error and scpd carries on without exported spans. On SIGINT or SIGTERM scpd flushes pending spans for up to 5 seconds; a second signal exits immediately.