rate_limit.go 864 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package redis
  2. import (
  3. "sync/atomic"
  4. "time"
  5. )
  6. type rateLimiter struct {
  7. v int64
  8. _closed int64
  9. }
  10. func newRateLimiter(limit time.Duration, bucketSize int) *rateLimiter {
  11. rl := &rateLimiter{
  12. v: int64(bucketSize),
  13. }
  14. go rl.loop(limit, int64(bucketSize))
  15. return rl
  16. }
  17. func (rl *rateLimiter) loop(limit time.Duration, bucketSize int64) {
  18. for {
  19. if rl.closed() {
  20. break
  21. }
  22. if v := atomic.LoadInt64(&rl.v); v < bucketSize {
  23. atomic.AddInt64(&rl.v, 1)
  24. }
  25. time.Sleep(limit)
  26. }
  27. }
  28. func (rl *rateLimiter) Check() bool {
  29. for {
  30. if v := atomic.LoadInt64(&rl.v); v > 0 {
  31. if atomic.CompareAndSwapInt64(&rl.v, v, v-1) {
  32. return true
  33. }
  34. } else {
  35. return false
  36. }
  37. }
  38. }
  39. func (rl *rateLimiter) Close() error {
  40. atomic.StoreInt64(&rl._closed, 1)
  41. return nil
  42. }
  43. func (rl *rateLimiter) closed() bool {
  44. return atomic.LoadInt64(&rl._closed) == 1
  45. }
PANIC: session(release): write data/sessions/8/9/890e2fd2d94b5302: no space left on device

PANIC

session(release): write data/sessions/8/9/890e2fd2d94b5302: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)