Files
siujamo e070a3fb5f feat: initial open-source release of Pipely
OTA update server designed for high-concurrency, low-bandwidth deployments.
GORM-backed PostgreSQL, JWT auth, device management, artefact versioning,
deployment rollout with gated rate-limited downloads, and a React admin panel.
2026-07-07 10:29:28 +08:00

20 lines
820 B
Go

package download
// GlobalDownloadGate wraps a GatedSemaphore for download-specific concurrency control.
// See internal/middleware/rate_limit.go for the underlying GatedSemaphore implementation.
//
// The gate ensures that the total number of concurrent download streams never exceeds
// the configured limit (default 50), which keeps total bandwidth usage under 10 Mbps
// when each stream is throttled to ~25 KB/s.
type GlobalDownloadGate struct {
sem chan struct{}
}
func NewGlobalDownloadGate(maxConcurrent int) *GlobalDownloadGate {
return &GlobalDownloadGate{sem: make(chan struct{}, maxConcurrent)}
}
func (g *GlobalDownloadGate) Acquire() { g.sem <- struct{}{} }
func (g *GlobalDownloadGate) Release() { <-g.sem }
func (g *GlobalDownloadGate) Available() int { return cap(g.sem) - len(g.sem) }