cache: Per-client fair-share bandwidth on table uplink
This commit is contained in:
+14
-1
@@ -38,10 +38,14 @@ type Options struct {
|
||||
// NegativeTTL is a Go duration string for 404/410 negative cache entries.
|
||||
// Empty defaults to 5m. "0" / "0s" disables storing negatives.
|
||||
NegativeTTL string
|
||||
|
||||
// Table-tier uplink bandwidth shaping (bytes/sec). Empty/0 = disabled.
|
||||
UplinkBandwidth string
|
||||
MaxBytesPerClientPerSec int64
|
||||
}
|
||||
|
||||
func NewWithOptions(o Options) (*SteamCache, error) {
|
||||
return New(o.Address, o.MemorySize, o.DiskSize, o.DiskPath, o.Upstream, o.MemoryGC, o.DiskGC, o.MaxConcurrentRequests, o.MaxRequestsPerClient, o.MaxObjectSize, o.TrustedProxies, o.NegativeTTL)
|
||||
return New(o.Address, o.MemorySize, o.DiskSize, o.DiskPath, o.Upstream, o.MemoryGC, o.DiskGC, o.MaxConcurrentRequests, o.MaxRequestsPerClient, o.MaxObjectSize, o.TrustedProxies, o.NegativeTTL, o.UplinkBandwidth, o.MaxBytesPerClientPerSec)
|
||||
}
|
||||
|
||||
// handleSpecialEndpoints handles non-content paths (health, heartbeat, metrics) and
|
||||
@@ -413,6 +417,15 @@ func (sc *SteamCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Per-client uplink bandwidth shaping (table-tier). Distinct from concurrency limits above.
|
||||
if sc.bandwidth != nil && sc.bandwidth.enabled() {
|
||||
lim, release := sc.bandwidth.acquire(clientIP)
|
||||
defer release()
|
||||
if lim != nil {
|
||||
w = &limitedResponseWriter{ResponseWriter: w, lim: lim, ctx: r.Context()}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this is a request from a supported service
|
||||
if service, isSupported := sc.detectService(r); isSupported {
|
||||
// Cache key is the path only, never the Host: Steam rotates CDN hostnames
|
||||
|
||||
Reference in New Issue
Block a user