Skip to content

Commit

Permalink
main: convert job capacity and parallel transcode params into args
Browse files Browse the repository at this point in the history
  • Loading branch information
emranemran committed Oct 31, 2023
1 parent 355a405 commit b35e7b9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MaxSegmentSizeSecs = 20
// Somewhat arbitrary and conservative number of maximum Catalyst VOD jobs in the system
// at one time. We can look at more sophisticated strategies for calculating capacity in
// the future.
const MAX_JOBS_IN_FLIGHT = 8
var MaxInFlightJobs int = 8

// How long to try writing a single segment to storage for before giving up
const SEGMENT_WRITE_TIMEOUT = 5 * time.Minute
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func main() {
fs.Float64Var(&video.MaxBitrateFactor, "max-bitrate-factor", 1.2, "Factor to limit the max video bitrate with relation to the source average bitrate")
fs.StringVar(&cli.C2PAPrivateKeyPath, "c2pa-private-key", "", "Path to the private key used to sign C2PA manifest")
fs.StringVar(&cli.C2PACertsPath, "c2pa-certs", "", "Path to the certs used to sign C2PA manifest")
fs.IntVar(&config.MaxInFlightJobs, "max-inflight-jobs", 8, "Maximum number of concurrent VOD jobs to support in catalyst-api")
fs.IntVar(&config.TranscodingParallelJobs, "parallel-transcode-jobs", 2, "Number of parallel transcode jobs")

// mist-api-connector parameters
fs.IntVar(&cli.MistPort, "mist-port", 4242, "Port to connect to Mist")
Expand Down
2 changes: 1 addition & 1 deletion middleware/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *CapacityMiddleware) HasCapacity(vodEngine *pipeline.Coordinator, next h
requestsInFlight := c.requestsInFlight.Add(1)
defer c.requestsInFlight.Add(-1)

if len(vodEngine.Jobs.GetKeys())+int(requestsInFlight) >= config.MAX_JOBS_IN_FLIGHT {
if len(vodEngine.Jobs.GetKeys())+int(requestsInFlight) >= config.MaxInFlightJobs {
w.WriteHeader(http.StatusTooManyRequests)
return
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ func TestItTakesIntoAccountInFlightHTTPRequests(t *testing.T) {
}

// Confirm the handler didn't let too many requests through
require.Equal(t, rejectedRequestCount, 100-config.MAX_JOBS_IN_FLIGHT+1)
require.Equal(t, rejectedRequestCount, 100-config.MaxInFlightJobs+1)
}

0 comments on commit b35e7b9

Please sign in to comment.