refactor(server): rate-limit the chunk streaming logging

This commit is contained in:
Serkyo 2026-08-02 03:07:33 +02:00
parent 7e5fae7e44
commit 4153a0e9a0

View file

@ -28,7 +28,7 @@ use glam::Vec3;
use shared::generator::{VoxelGenerator, WorldGenConfig}; use shared::generator::{VoxelGenerator, WorldGenConfig};
use shared::protocol::authority::ServerStats; use shared::protocol::authority::ServerStats;
use shared::world::{Chunk, ChunkPos, EntityPos}; use shared::world::{Chunk, ChunkPos, EntityPos};
use tracing::{debug, info, warn}; use tracing::{debug, info, trace, warn};
use client_stream::ClientStream; use client_stream::ClientStream;
use net::{NetworkServer, ServerEvent}; use net::{NetworkServer, ServerEvent};
@ -54,14 +54,7 @@ fn stream_chunks(
cylinder_chunks(position.0.chunk, view.0, &mut desired); cylinder_chunks(position.0.chunk, view.0, &mut desired);
} }
let stats = world.reconcile(&desired); world.reconcile(&desired);
info!(
loaded = stats.loaded,
unloaded = stats.unloaded,
resident = stats.resident,
in_flight = stats.in_flight,
"streaming reconcile"
);
} }
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
@ -116,15 +109,20 @@ fn main() -> anyhow::Result<()> {
// Loading phase: dispatch the initial region and wait for the worker pool to finish before granting control. // Loading phase: dispatch the initial region and wait for the worker pool to finish before granting control.
info!("Streaming initial region"); info!("Streaming initial region");
// The loop below spins as fast as the worker pool is polled, so progress is reported only when the resident count actually advances. Logging every iteration would emit thousands of identical lines before the endpoint is even bound.
let mut last_reported = usize::MAX;
loop { loop {
schedule.run(&mut world); schedule.run(&mut world);
let server_world = world.resource::<ServerWorld>(); let server_world = world.resource::<ServerWorld>();
let resident = server_world.loaded_count(); let resident = server_world.loaded_count();
let in_flight = server_world.in_flight_count(); let in_flight = server_world.in_flight_count();
// Loading progress is simply the resident fraction of all known chunks. if resident != last_reported {
let total = resident + in_flight; // Loading progress is simply the resident fraction of all known chunks.
debug!(resident, in_flight, total, "loading progress"); let total = resident + in_flight;
debug!(resident, in_flight, total, "loading progress");
last_reported = resident;
}
// The region is ready once at least one chunk has been generated and none remain in flight. // The region is ready once at least one chunk has been generated and none remain in flight.
if server_world.streaming_idle() && resident > 0 { if server_world.streaming_idle() && resident > 0 {
@ -251,7 +249,8 @@ fn run_simulation(world: &mut World, network: &NetworkServer) -> ! {
for (id, client) in &mut clients { for (id, client) in &mut clients {
let delivered = client.flush(server_world, &empty_baseline); let delivered = client.flush(server_world, &empty_baseline);
if delivered > 0 { if delivered > 0 {
debug!(id, delivered, "delivered resident chunks"); // Per-tick and per-client, so it sits below the default filter: the aggregate chunk figures in the status line cover routine operation, and this level is for tracing an individual client's deliveries.
trace!(id, delivered, "delivered resident chunks");
} }
} }