Performance Tab
Relevant source files
The following files were used as context for generating this wiki page:
The Performance Tab is a specialized diagnostic module within the LogUtil TUI (Terminal User Interface) designed to monitor and analyze Nginx response times and request throughput in real-time. Its primary purpose is to help administrators identify slow-performing endpoints and track server responsiveness under varying loads.
The tab aggregates data from the global in-memory database to display high-level metrics such as average, minimum, and maximum response times, alongside a real-time Requests Per Second (RPS) calculation. Additionally, it provides a detailed list of "Slow Requests"—specifically those exceeding a 1-second threshold—mapping them to the originating IP address for targeted troubleshooting.
Sources: src/tabs/performance.rs:24-42, README.md:167-175
Architecture and Data Flow
The Performance Tab operates as a reactive component within the application's tab management system. It relies on a background thread that continuously monitors the log file, parses entries via regex, and populates the GLOBAL_DB.
Data Acquisition Flow
The following diagram illustrates how performance data flows from the raw log file to the TUI display:
The PerformanceTab struct implements the Tab trait, allowing it to be managed by the TabManager. During every draw cycle, it queries the GLOBAL_DB for the latest statistics.
Sources: src/main.rs:271-300, src/tabs/performance.rs:30-34, src/app.rs:60-75
Component Breakdown
Performance Metrics Summary
The top portion of the tab displays a summary paragraph containing real-time health indicators. These metrics are calculated based on the response_time field within the LogRecord structure stored in memory.
| Metric | Source Function | Description |
|---|---|---|
| Avg Response | db.get_response_time_stats() | Arithmetic mean of response times from the current sample set. |
| Max Response | db.get_response_time_stats() | The longest response time recorded in the sample. |
| Min Response | db.get_response_time_stats() | The shortest response time recorded in the sample. |
| RPS | db.get_requests_per_second() | Current requests per second based on the total request count over a 60-second window. |
Sources: src/tabs/performance.rs:37-41, src/memory_db.rs:260-282
Slow Requests Table
The primary interactive element is a table that lists requests taking longer than 1.0 second. This table is stateful, allowing users to scroll through the most recent slow events.
- Logic: The database scans the most recent records (up to a limit of 25,000 for optimization) and filters for entries where
response_time > 1.0. - Columns:
- IP: The client IP address that made the slow request (rendered in Bold Yellow).
- Time: The specific duration of that request in seconds (rendered in Cyan).
Sources: src/tabs/performance.rs:56-110, src/memory_db.rs:285-303
Configuration and Activation
The Performance Tab is optional and must be enabled either through command-line arguments or the interactive settings menu.
CLI Configuration
Users can activate the tab using the --enable-performance flag.
// src/main.rs:77-78
/// Enable Performance tab (monitor response times, slow requests)
#[structopt(long)]
enable_performance: bool,
Interactive Settings
In the FileSettings selector, the "Enable Performance" option allows users to toggle the feature. When set to true, the App constructor includes the PerformanceTab in its list of active tabs.
| Setting Name | Input Type | Default | Description |
|---|---|---|---|
| Enable Performance | Boolean | false | Toggles the visibility and data processing for the Performance tab. |
Sources: src/file_settings.rs:113-117, src/app.rs:70-73, src/main.rs:163-180
Implementation Details
Data Retrieval Implementation
The performance statistics are derived from the records DashMap in MemoryDB. To maintain high performance, the database uses a limited sample size for calculations.
// src/memory_db.rs:260-262
pub fn get_response_time_stats(&self) -> (f64, f64, f64) {
let mut times: Vec<f64> = Vec::new();
let max_samples = 5000; // Optimization limit
// ... logic to calculate avg, max, min
}
Sources: src/memory_db.rs:260-275
Input Handling
The tab handles keyboard navigation to allow users to inspect the list of slow requests.
Sources: src/tabs/performance.rs:125-148
Summary
The Performance Tab serves as a critical monitoring tool within LogUtil, providing an immediate overview of Nginx latency and throughput. By integrating directly with the optimized MemoryDB, it offers real-time insights into server performance and identifies specific "bottleneck" requests without significant CPU overhead. Its presence in the UI is highly configurable, ensuring that users only consume resources for performance monitoring when explicitly required.