Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/connor4312/rpt
Helper to measure how often things happen.
https://github.com/connor4312/rpt
Last synced: 1 day ago
JSON representation
Helper to measure how often things happen.
- Host: GitHub
- URL: https://github.com/connor4312/rpt
- Owner: connor4312
- Created: 2015-06-02T03:18:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-02T03:49:45.000Z (over 9 years ago)
- Last Synced: 2024-10-25T22:17:40.885Z (18 days ago)
- Language: Go
- Size: 97.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# rpt [![Build Status](https://travis-ci.org/connor4312/rpt.svg?branch=master)](https://travis-ci.org/connor4312/rpt) [![Coverage Status](https://coveralls.io/repos/connor4312/rpt/badge.svg?branch=master)](https://coveralls.io/r/connor4312/rpt?branch=master) [![godoc reference](https://godoc.org/github.com/connor4312/rpt?status.png)](https://godoc.org/github.com/connor4312/rpt)
RPT ("requests per time") is a general-purpose library for monitoring events over time interval. For example, it can be used to easily and quickly calculate the number of requests your app is hit by per minute.
See the godoc for further details.
## Quick Example
```go
package mainimport (
"fmt"
"github.com/connor4312/rpt"
"net/http"
"time"
)func main() {
rp := rpt.New(60, time.Second)http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
rp.AddRequest()
fmt.Fprintf(w, "Requests per minute: %d", rp.GetRPT())
})http.ListenAndServe(":8080", nil)
}
```## Benchmarks
* The call to record a request takes under 30 nanoseconds.
* The call to sum all requests in the interval takes about 175 nanoseconds.
* The call to get a range of data, suitable for building histograms, takes about 900 nanoseconds.```
➜ rpt go test -benchmem -bench=.
PASS
BenchmarkAddRequest 50000000 28.8 ns/op 0 B/op 0 allocs/op
BenchmarkGetRtp 10000000 170 ns/op 0 B/op 0 allocs/op
BenchmarkGetRange 2000000 879 ns/op 704 B/op 1 allocs/op
ok github.com/connor4312/worker/rpt 5.949s
```## License
Copyright 2015 by Connor Peet. Distributed under the MIT license.