Skip to content

Commit

Permalink
Fixed some nits. (facebookincubator#47)
Browse files Browse the repository at this point in the history
Summary:
Noticed some nits.

Pull Request resolved: facebookincubator#47

Reviewed By: pmazzini

Differential Revision: D55562918

Pulled By: mimir-d

fbshipit-source-id: 54dd4c792e5528339c6cbdfa0ee50fbe11599b04
  • Loading branch information
16point7 authored and facebook-github-bot committed Apr 2, 2024
1 parent 7710845 commit 6c3c7a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
package dhcplb

import (
"github.com/golang/glog"
"net"
"time"

"github.com/golang/glog"
)

// LogMessage holds the info of a log line.
Expand Down Expand Up @@ -83,7 +84,7 @@ func (h *loggerHelper) LogSuccess(start time.Time, server *DHCPServer, packet []
}
err := h.personalizedLogger.Log(msg)
if err != nil {
glog.Errorf("Failed to log error: %s", err)
glog.Errorf("Failed to log success: %s", err)
}
}
}
20 changes: 10 additions & 10 deletions lib/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,41 @@ func (c *Throttle) setRate(MaxRatePerItem int) {

// NewThrottle returns a Throttle struct
//
// Capacity:
// capacity:
// Maximum capacity of the LRU cache
//
// CacheRate (per second):
// cacheRate (per second):
// Maximum allowed rate for adding new items to the cache. By that way it
// prevents the cache invalidation to happen too soon for the existing rate
// items in the cache. Cache rate will be infinite for 0 or negative values.
//
// MaxRatePerItem (per second):
// maxRatePerItem (per second):
// Maximum allowed requests rate for each key in the cache. Throttling will
// be disabled for 0 or negative values. No cache will be created in that case.
func NewThrottle(Capacity int, CacheRate int, MaxRatePerItem int) (*Throttle, error) {
if MaxRatePerItem <= 0 {
func NewThrottle(capacity int, cacheRate int, maxRatePerItem int) (*Throttle, error) {
if maxRatePerItem <= 0 {
glog.Info("No throttling will be done")
}

cache, err := lru.New[string, *rate.Limiter](Capacity)
cache, err := lru.New[string, *rate.Limiter](capacity)
if err != nil {
return nil, err
}

// Keep track of the item creation rate.
var cacheLimiter *rate.Limiter
if CacheRate <= 0 {
if cacheRate <= 0 {
glog.Info("No cache rate limiting will be done")
cacheLimiter = rate.NewLimiter(rate.Inf, 1) // bucket size is ignored
} else {
cacheLimiter = rate.NewLimiter(rate.Limit(CacheRate), CacheRate)
cacheLimiter = rate.NewLimiter(rate.Limit(cacheRate), cacheRate)
}

throttle := &Throttle{
lru: cache,
maxRatePerItem: MaxRatePerItem,
maxRatePerItem: maxRatePerItem,
cacheLimiter: cacheLimiter,
cacheRate: CacheRate,
cacheRate: cacheRate,
}

return throttle, nil
Expand Down

0 comments on commit 6c3c7a1

Please sign in to comment.