cache: Per-client fair-share bandwidth on table uplink
This commit is contained in:
@@ -55,6 +55,9 @@ type SteamCache struct {
|
||||
clientRateLimiter *clientRateLimiter
|
||||
maxRequestsPerClient int64
|
||||
|
||||
// Per-client uplink bandwidth shaping (see bandwidth.go); nil/disabled = unlimited
|
||||
bandwidth *clientBandwidthLimiter
|
||||
|
||||
// Hardening config fields (plumbed)
|
||||
maxObjectSize int64
|
||||
trustedProxies []string
|
||||
@@ -85,7 +88,7 @@ const DefaultNegativeTTL = 5 * time.Minute
|
||||
// negativeTTL is a Go duration string for 404/410 negative cache entries; empty means 5m.
|
||||
// Callers must check the returned error.
|
||||
// Prefer NewWithOptions (or config file) for forward compatibility. See README migration notes.
|
||||
func New(address string, memorySize string, diskSize string, diskPath, upstream, memoryGC, diskGC string, maxConcurrentRequests int64, maxRequestsPerClient int64, maxObjectSize string, trustedProxies []string, negativeTTL string) (*SteamCache, error) {
|
||||
func New(address string, memorySize string, diskSize string, diskPath, upstream, memoryGC, diskGC string, maxConcurrentRequests int64, maxRequestsPerClient int64, maxObjectSize string, trustedProxies []string, negativeTTL string, uplinkBandwidth string, maxBytesPerClientPerSec int64) (*SteamCache, error) {
|
||||
memorysize, err := units.FromHumanSize(memorySize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid memory size: %w", err)
|
||||
@@ -114,6 +117,17 @@ func New(address string, memorySize string, diskSize string, diskPath, upstream,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var uplinkBytes int64
|
||||
if uplinkBandwidth != "" && uplinkBandwidth != "0" {
|
||||
uplinkBytes, err = units.FromHumanSize(uplinkBandwidth)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid uplink bandwidth: %w", err)
|
||||
}
|
||||
}
|
||||
if maxBytesPerClientPerSec < 0 {
|
||||
return nil, fmt.Errorf("negative max_bytes_per_client_per_sec not allowed")
|
||||
}
|
||||
|
||||
c := cache.New()
|
||||
|
||||
var m *memory.MemoryFS
|
||||
@@ -178,6 +192,7 @@ func New(address string, memorySize string, diskSize string, diskPath, upstream,
|
||||
requestSemaphore: semaphore.NewWeighted(maxConcurrentRequests),
|
||||
clientRateLimiter: newClientRateLimiter(maxRequestsPerClient),
|
||||
maxRequestsPerClient: maxRequestsPerClient,
|
||||
bandwidth: newClientBandwidthLimiter(uplinkBytes, maxBytesPerClientPerSec),
|
||||
shutdownCh: make(chan struct{}),
|
||||
|
||||
// Hardening config plumbed
|
||||
|
||||
Reference in New Issue
Block a user