Change stats interval from 5s to 1s for better real-time monitoring#1195
Change stats interval from 5s to 1s for better real-time monitoring#1195carlhoerberg wants to merge 1 commit intomainfrom
Conversation
a9013af to
24a6f9e
Compare
|
Claude finished @carlhoerberg's task —— View job PR Review: Change stats interval from 5s to 1sI've conducted a comprehensive review of this PR focusing on code quality, potential issues, performance, security, and test coverage. Todo List:
Code Quality & Best Practices ✅Configuration Changes (
Server Logic (
Data Type Optimization (
Frontend Consistency (all JS files):
Performance Considerations
|
5d38006 to
0eb0e43
Compare
|
Claude finished @carlhoerberg's task —— View job PR Review: Stats Interval Change from 5s to 1sTodo List:
Code Quality & Best Practices ✅Configuration Changes (
Server Logic (
Data Type Optimization (
Frontend Consistency:
Performance Considerations
|
|
Claude finished @carlhoerberg's task —— View job PR Review: Stats Interval Change from 5s to 1sTodo List:
Code Quality & Best Practices ✅Configuration Changes (
Server Logic (
Data Type Optimization (
Frontend Consistency (
Performance Considerations
|
|
Claude finished @carlhoerberg's task —— View job PR Review: Change stats interval from 5s to 1sI've conducted a comprehensive review of this PR focusing on code quality, potential issues, performance, security, and test coverage. Todo List:
Code Quality & Best Practices ✅Configuration Changes (
Server Logic (
Data Type Optimization (
Frontend Consistency (
Performance Considerations
|
Updates stats collection frequency across server and web UI: - Remove configurable stats_interval, hardcode to 1s in server stats loop - Change JavaScript polling intervals from 5000ms to 1000ms - Update stats log size from 120 to 600 (maintains 10min history) - Fix CPU time metrics to use counter type in Prometheus - Improve stats collection timing and logging - Update flow control tests to work with new timing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2d551a9 to
8b72c19
Compare
|
Claude finished @carlhoerberg's task —— View job PR Review: Change stats interval from 5s to 1sI've conducted a comprehensive review of this PR focusing on code quality, potential issues, performance, security, and test coverage. Todo List:
Code Quality & Best Practices ✅Configuration Changes (
Server Logic (
Data Type Optimization (
Frontend Consistency (
Performance Considerations
|
A ring buffer should be faster for our use case. While not the most common operation, for a broker with a lot of objects (queues, exchanges etc) we want to minimize any CPU time spent on just keeping track of the stats. Improvements to the `to_a` method that's used in the UI/API, i.e. any time we refresh the web page with new stats (proposed to be once per second in #1195) should help a bit, even though the full JSON serialization is probably much more expensive. Getting around 9% improvements in the simulated http_benchmark.cr See benchmark/ directory for all micro benchmarks (should be cleaned up before we merge this). Also kept the old Deque based code until we're ready to say this is good. ``` RingBuffer (steady-state) 355.76M ( 2.81ns) (± 5.70%) 0.0B/op fastest Deque (steady-state) 177.83M ( 5.62ns) (± 2.41%) 0.0B/op 2.00× slower RingBuffer (fill from empty) 285.64k ( 3.50µs) (± 0.76%) 12.1kB/op fastest Deque (fill from empty) 202.75k ( 4.93µs) (± 1.55%) 12.1kB/op 1.41× slower RingBuffer (to_a) 872.70k ( 1.15µs) (± 0.84%) 12.1kB/op fastest Deque (to_a) 146.77k ( 6.81µs) (± 0.94%) 12.1kB/op 5.95× slower ``` Why RingBuffer is faster: Bitwise Modulo Operations - RingBuffer uses & @Mask for wrap-around (single CPU instruction) - Deque uses conditional branches (if index >= @capacity) - Bitwise AND avoids branch misprediction penalties No Memory Shifting - RingBuffer: Simply overwrites oldest value when full - Deque: Calls shift to remove first element, causing memory movement Simpler Push Logic - RingBuffer: Direct write to calculated position - Deque: Check size → shift if needed → then push (3 operations vs 1) CPU Cache Optimization - RingBuffer: Predictable circular access pattern - Deque: Shift operations invalidate cache lines No Dynamic Memory Management - RingBuffer: Fixed allocation, never grows - Deque: Resize checks and potential reallocation overhead
By changing from 5s to 1s stats interval the charts looks a lot better, and we can decrease resolution to integers (from 1 decimal floats), as you can't publish less than 1 msg per second (before we showed 0.2 msgs/s per 5s period).
Before the stats interval was configuratable, but it didn't update the UI side, so it wasn't really possible to use.