- In-Memory or Redis based storage
- Concurrency-safe
- Put, Take, Count, DynamicFill, and many more primitives
- Designed for distributed systems
- Well tested
- Well documented
go get github.com/b3ntly/bucket
Can be found here
- Test coverage badge is stuck in some cache and is out of date, click the badge to see the actual current coverage
- Abstracted storage to its own interface, see storage.go and redis.go for examples
- Added in-memory storage option
- Replaced storageOptions parameter with IStorage, allowing a single storage option to be shared between multiple buckets. This should make it much more efficient to have a large number of buckets, i.e. per logged in user.
- Renamed the repository from distributed-token-bucket to bucket
- Moved storage interface and providers to the /storage subpackage
- Added unit testing to the /storage subpackage
- Added watchable.go and changed signatures of all async functions to return a watchable
- Fixed examples
- Added more documentation and comments
- Shortened "constructor" names
- Default options
- Better "constructor" signatures
- bucket.DynamicFill()
- bucket.TakeAll()
- Added full documentation via Hugo
go test -bench .
Benchmarks were done on a 2.2GHz quad-core Intel Core i7 with 16GB of RAM.
Version 0.4
Memory
Benchmark | Operations | ns/op |
---|---|---|
BenchmarkBucket_Create-8 | 10000 | 715 ns/op |
BenchmarkBucket_Take-8 | 30000 | 132 ns/op |
BenchmarkBucket_Put-8 | 50000 | 142 ns/op |
Redis
Benchmark | Operations | ns/op |
---|---|---|
BenchmarkBucket_Create-8 | 10000 | 98582 ns/op |
BenchmarkBucket_Take-8 | 30000 | 47716 ns/op |
BenchmarkBucket_Put-8 | 50000 | 31350 ns/op |