Performance: Metrics with Micrometer
MEDIUM IMPACT
This concept affects how efficiently application metrics are collected and reported, impacting monitoring overhead and response time.
MeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); Counter counter = registry.counter("requests"); for (int i = 0; i < 10000; i++) { counter.increment(); } // Metrics are scraped asynchronously by Prometheus
MeterRegistry registry = new SimpleMeterRegistry(); Counter counter = registry.counter("requests"); for (int i = 0; i < 10000; i++) { counter.increment(); }
| Pattern | CPU Usage | Memory Usage | Blocking | Verdict |
|---|---|---|---|---|
| SimpleMeterRegistry with synchronous increments | High CPU during increments | Low memory | Blocks threads on increment | [X] Bad |
| PrometheusMeterRegistry with async scraping | Low CPU spikes | Moderate memory for buffering | Non-blocking increments | [OK] Good |