Skip to content
Golang implementation of Sliding Window Algorithm for distributed rate limiting.
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Fix lint errors Nov 26, 2019
docs Update design diagram Nov 30, 2019
testutil Refactor SyncWindow for the best coordination with the synchronizer Dec 3, 2019
README.md
example_localwindow_test.go Remove the built-in RedisDatastore Nov 28, 2019
example_syncwindow_test.go Refactor SyncWindow for the best coordination with the synchronizer Dec 3, 2019
go.mod Remove the built-in RedisDatastore Nov 28, 2019
slidingwindow.go Refactor SyncWindow for the best coordination with the synchronizer Dec 3, 2019
slidingwindow_test.go Fix tests Dec 3, 2019
windows.go Refactor SyncWindow for the best coordination with the synchronizer Dec 3, 2019

README.md

slidingwindow

Golang implementation of Sliding Window Algorithm for distributed rate limiting.

Installation

$ go get -u github.com/RussellLuo/slidingwindow

Design

slidingwindow is an implementation of the scalable rate limiting algorithm used by Kong.

Suppose we have a limiter that permits 100 events per minute, and now the time comes at the "75s" point, then the internal windows will be as below:

slidingwindow

In this situation, the limiter has permitted 12 events during the current window, which started 15 seconds ago, and 86 events during the entire previous window. Then the count approximation during the sliding window can be calculated like this:

count = 86 * ((60-15)/60) + 12
      = 86 * 0.75 + 12
      = 76.5 events

Test Utility

prom_reports

For details, see testutil.

Documentation

For usage and examples see the Godoc.

License

MIT

You can’t perform that action at this time.