fix(activitypub): fixes #4372 where excessive AP resource use disrupts video delivery (#4552)

This commit is contained in:
Gabe Kangas
2025-09-24 17:53:05 -07:00
committed by GitHub
parent 9a80b73747
commit 0b781eb716
3 changed files with 263 additions and 8 deletions
+21 -5
View File
@@ -1,8 +1,6 @@
package activitypub
import (
"math"
"github.com/owncast/owncast/activitypub/crypto"
"github.com/owncast/owncast/activitypub/inbox"
"github.com/owncast/owncast/activitypub/outbox"
@@ -36,14 +34,32 @@ func Start(datastore *data.Datastore) {
}
func getOutboundWorkerPoolSize() int {
// Use a reasonable fixed worker pool size instead of scaling with followers
// This prevents excessive resource usage when streamers have many followers
const (
minWorkers = 10 // Minimum workers for small instances
maxWorkers = 50 // Maximum workers to prevent resource exhaustion
defaultWorkers = 20 // Default for most instances
)
var followerCount int64
fc, err := persistence.GetFollowerCount()
if err != nil {
log.Errorln("Unable to get follower count", err)
fc = 50 // Arbitrary fallback value.
return defaultWorkers
}
followerCount = int64(math.Max(float64(fc), 50))
return int(followerCount * 5)
followerCount = fc
// Scale more conservatively: start with base workers, add 1 worker per 100 followers
// This gives a much more reasonable scaling than the previous followerCount * 5
workers := minWorkers + int(followerCount/100)
if workers > maxWorkers {
workers = maxWorkers
}
log.Infof("Initializing ActivityPub outbound worker pool with %d workers for %d followers", workers, followerCount)
return workers
}
// SendLive will send a "Go Live" message to followers.