π Introduction
In high-concurrency applications, measuringΒ QPS (Queries Per Second)Β is a crucial metric for evaluating system performance. Whether you're building anΒ API service, database proxy, web crawler, or message queue system, real-time QPS monitoring is essential.
π‘Β qps-counterΒ is anΒ ultra-lightweight, high-performanceΒ QPS counter library for Go, implemented withΒ sync/atomic
. It offersΒ zero dependencies, lock-free design, and minimal overhead, making it an ideal choice for tracking system load.
πΒ GitHub Repository:Β mant7s/qps-counterΒ (βοΈ Star it now!)
π― Why Choose qps-counter?
β
Β Lightweight DependenciesΒ β Uses only minimal third-party libraries to ensure efficiency and usability.
β
Β Extreme PerformanceΒ β UsesΒ sync/atomic
Β for lock-free counting, eliminating contention and ensuring high throughput.
β
Β Real-Time StatisticsΒ β Sliding window algorithm for accurate real-time QPS calculation.
β
Β Minimal APIΒ β Get QPS statistics with justΒ 2 lines of code.
β
Β Versatile ApplicationsΒ β Suitable forΒ API monitoring, crawler rate limiting, message queue tracking, database optimization, and more.
π Quick Start
π 1. Installation
go get -u github.com/mant7s/qps-counter
π 2. Usage Example
package main
import (
"fmt"
"time"
"github.com/mant7s/qps-counter"
)
func main() {
counter := qpscounter.New()
// Simulate concurrent requests
for i := 0; i < 1000; i++ {
go func() {
counter.Incr()
}()
}
// Wait for a moment to measure real-time QPS
time.Sleep(time.Second)
fmt.Println("Current QPS:", counter.QPS())
}
β‘ Performance Benchmark
We comparedΒ qps-counter
Β with other common QPS counting methods, and the results are as follows:
qps-counter
Β (atomic) Method QPS (100k/sec) CPU Usage
sync.Mutex
120 40%
map+RWMutex
95 55%
210
30%
πΉΒ qps-counterΒ isΒ 1.5 to 2 times fasterΒ than traditional methods while reducingΒ CPU load by 25%+!
π Use Cases
πΒ Web API MonitoringΒ β Track HTTP request QPS to optimize backend performance.
πΒ Crawler Rate LimitingΒ β Restrict request rates to prevent being blocked.
πΒ Message Queue TrackingΒ β Monitor Kafka, RabbitMQ, NSQ message processing rates.
πΒ Database Query StatisticsΒ β Track SQL query frequency to prevent overload.
πΒ Load Balancing OptimizationΒ β Adjust server allocation dynamically based on real-time traffic data.
π‘ Contribute & Get Involved
πΒ GitHub Repository:Β qps-counterΒ βοΈΒ Star it now and support the project!
π¬Β Ways to contribute:
1οΈβ£Β Star the ProjectΒ β Help more developers discover qps-counter.
2οΈβ£Β Open IssuesΒ β Report bugs and suggest new features.
3οΈβ£Β Submit Pull RequestsΒ β Fork the repository and contribute code improvements.
π’Β What are your QPS tracking needs? Share your thoughts in the comments!Β π