Understand the GoScrapy Telemetry Architecture
mainGoScrapy uses a decoupled, three-layer telemetry architecture designed to collect high-performance metrics without blocking the crawler's execution path (the 'hot-path'). The system separates the high-speed recording of metrics from the periodic broadcasting of those metrics.
The Three Layers:
- Collection Layer (Non-Blocking): Engine components like the
Scheduler,Worker Pool,Pipeline Manager, andStats Middlewaremaintain their own local metrics usingsync/atomiccounters. This prevents a central bottleneck during high-speed scraping. - Aggregation Layer (Periodic): The
TelemetryHubacts as an orchestrator. It uses a background loop with a Gotime.Tickerto periodically poll registered components. - Exhibition Layer (Broadcast):
Observers(such as a TUI dashboard or loggers) consume the aggregatedGlobalSnapshotto visualize or export data.
Telemetry Flow:
- Collection Phase: Components update internal atomic counters asynchronously during execution.
- Broadcast Phase: At a set interval (e.g., every 500ms), the
TelemetryHubcallsSnapshot()on all components to collectComponentSnapshotdata, builds aGlobalSnapshot, and sends it to observers viaOnSnapshot(GlobalSnapshot).