Skip to content

Conversation

@Outspending
Copy link
Contributor

@Outspending Outspending commented Dec 15, 2025

ServerPerformance (TPS / Memory Monitoring)

Summary

This pull request adds the ServerPerformance ECS resource, a centralized place for collecting and exposing server performance metrics. The resource is updated once per tick by the main scheduler loop and can be queried by commands, debug tooling, or plugins.

image

Details

ServerPerformance currently tracks the following metrics:

  • Tick durations
  • Rolling TPS over multiple windows (1s / 5s / 15s)
  • Memory usage, including current and peak values

The resource is designed to be lightweight and safe to query from read-only systems, while allowing mutable access when required (e.g. for memory statistics).

Usage Examples

Reading TPS

fn test(performance: Res<ServerPerformance>) {
    let tps = &performance.tps;

    // tps
    tps.tps_1s(); // tps over the last 1 second
    tps.tps_5s(); // tps over the last 5 seconds
    tps.tps_15s(); // tps over the last 15 seconds

    // tick durations
    tps.avg_tick_ms(); // Avg
    tps.p50_ms(); // 50 percentile
    tps.p95_ms(); // 95 percentile
    tps.p99_ms(); // 99 percentile
}

Reading Memory Usage

fn test(performance: ResMut<ServerPerformance>) {
    let (current, peak) = performance.memory.get_memory(MemoryUnit::Megabytes);
}

Motivation

Server performance metrics are key for server development, even our case in debugging the core components of the server. This resource consolidates them all into a single, well-defined ECS resource which can easily be accessed. This makes debugging, monitoring, and performance tuning significantly easier and more consistant.

Future Work

I'm not done with this! I still have multiple more features i wanna add before pushing. Such as

  • Lag spike detection
  • Scheduler overrun (already in the master branch but will be expanded and put into here)
  • Sampler-based Profiling (this ones intensive and still under consideration but key for debugging)

Replaces fixed-window TPS and percentile methods with parameterized versions using Duration and percentile arguments. Updates command and resource registration code to use new APIs, and adds system support checks for performance statistics. Also adds Kilobytes to MemoryUnit and updates dependencies.
Changed ServerPerformance::new to always return a ServerPerformance instance instead of an Option. Updated resource registration to match the new signature, simplifying resource insertion and removing unnecessary conditional logic.
@ReCore-sys ReCore-sys merged commit dbbd06a into ferrumc-rs:master Dec 22, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants