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.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
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) }
|
||||
Reference in New Issue
Block a user