• Stars
    star
    250
  • Rank 157,137 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Thread-Safe RateCounter implementation in Golang

ratecounter

CircleCI Go Report Card GoDoc codecov

A Thread-Safe RateCounter implementation in Golang

Usage

import "github.com/paulbellamy/ratecounter"

Package ratecounter provides a thread-safe rate-counter, for tracking counts in an interval

Useful for implementing counters and stats of 'requests-per-second' (for example):

// We're recording marks-per-1second
counter := ratecounter.NewRateCounter(1 * time.Second)
// Record an event happening
counter.Incr(1)
// get the current requests-per-second
counter.Rate()

To record an average over a longer period, you can:

// Record requests-per-minute
counter := ratecounter.NewRateCounter(60 * time.Second)
// Calculate the average requests-per-second for the last minute
counter.Rate() / 60

Also you can track average value of some metric in an interval.

Useful for implementing counters and stats of 'average-execution-time' (for example):

// We're recording average execution time of some heavy operation in the last minute.
counter := ratecounter.NewAvgRateCounter(60 * time.Second)
// Start timer.
startTime := time.Now()
// Execute heavy operation.
heavyOperation()
// Record elapsed time.
counter.Incr(time.Since(startTime).Nanoseconds())
// Get the current average execution time.
counter.Rate()

Documentation

Check latest documentation on go doc.

More Repositories

1

mango

Mango is a modular web-application framework for Go, inspired by Rack, and PEP333.
Go
372
star
2

livecomments.go

A live commenting system built in Go, Socket.io, Redis, and Backbone.js
JavaScript
26
star
3

pipe

Concurrent, sequential, functional transformations along Golang channels.
Go
23
star
4

docker-urbit

Dockerfile for Urbit
12
star
5

cconf

Easy configuration for Clojure apps
Clojure
10
star
6

base65536

Human-friendly encoding for binary data
Go
9
star
7

golanguk2017

Slides and Examples from "Building Go With Bazel" at Golang UK 2017
JavaScript
6
star
8

zcash-light

Lightweight Zcash API-wallet library in Go
Go
5
star
9

dfinity-ip-checker

Checks your IP
Modelica
3
star
10

hook.io-postgres

Hook.io hook for talking to Postgres
JavaScript
3
star
11

gossip

Learning about gossip protocols
Go
3
star
12

nodemap

Experimental AMQP to js client mapping app
JavaScript
2
star
13

docker-asciinema

Dockerfile for asciinema. An easy way to record screen-casts.
2
star
14

paulbellamy.github.com

HTML
2
star
15

name

Super-simple golang library for generating friendly names
Go
2
star
16

golanguk2016

Talk for Golang UK 2016 - Advanced Patterns with io.ReadWriter
2
star
17

ROFLock

A lock with extra rofls
2
star
18

Senior-Project

A Morse-Code interface for Twitter
C
2
star
19

Rhythmbox-iPod-Plugin

My Project for GSoC 2009, Adding the "Sync" functionality to the existing plugin.
C
2
star
20

infinite_multi_reader

An InfiniteMultiReader function for Golang
Go
1
star
21

selecta.nvim

Simple neovim selecta bindings for searching through files and buffers
Vim Script
1
star
22

hist

Pipe-able Command-line Histograms
Ruby
1
star
23

go-stellar-wasm-rpc

Proof of concept calling rust wasm runtime from golang
Go
1
star
24

kubewatch

Auto-deploy new docker images to a kubernetes server for development
Go
1
star