Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Feature #247: adds new command-line flags for work manager queue and …
Browse files Browse the repository at this point in the history
…pool sizes
  • Loading branch information
Tom McSweeney committed Mar 16, 2016
1 parent fcab2fc commit 4537157
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scheduler/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Copyright 2015 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package scheduler

import "github.com/codegangsta/cli"

var (
flSchedulerQueueSize = cli.IntFlag{
Name: "work-manager-queue-size",
Usage: "Size of the work manager queue (default: 25)",
EnvVar: "WORK_MANAGER_QUEUE_SIZE",
}

flSchedulerPoolSize = cli.IntFlag{
Name: "work-manager-pool-size",
Usage: "Size of the work manager pool (default 4)",
EnvVar: "WORK_MANAGER_POOL_SIZE",
}

// Flags consumed by snapd
Flags = []cli.Flag{flSchedulerQueueSize, flSchedulerPoolSize}
)
8 changes: 8 additions & 0 deletions scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ type managesWork interface {
// The MetricManager must be set before the scheduler can be started.
// The MetricManager must be started before it can be used.
func New(cfg *Config) *scheduler {
schedulerLogger.WithFields(log.Fields{
"_block": "New",
"value": cfg.WorkManagerQueueSize,
}).Info("Setting work manager queue size")
schedulerLogger.WithFields(log.Fields{
"_block": "New",
"value": cfg.WorkManagerPoolSize,
}).Info("Setting work manager pool size")
opts := []workManagerOption{
CollectQSizeOption(cfg.WorkManagerQueueSize),
CollectWkrSizeOption(cfg.WorkManagerPoolSize),
Expand Down
11 changes: 11 additions & 0 deletions snapd.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func main() {
flRestKey,
flRestAuth,
}
app.Flags = append(app.Flags, scheduler.Flags...)
app.Flags = append(app.Flags, tribe.Flags...)

app.Action = action
Expand Down Expand Up @@ -585,6 +586,13 @@ func setIntVal(field int, ctx *cli.Context, flagName string) int {
return field
}

func setUIntVal(field uint, ctx *cli.Context, flagName string) uint {
if ctx.IsSet(flagName) {
field = uint(ctx.Int(flagName))
}
return field
}

func setDurationVal(field time.Duration, ctx *cli.Context, flagName string) time.Duration {
if ctx.IsSet(flagName) {
field = ctx.Duration(flagName)
Expand Down Expand Up @@ -615,6 +623,9 @@ func applyCmdLineFlags(cfg *Config, ctx *cli.Context) {
cfg.RestAPI.RestKey = setStringVal(cfg.RestAPI.RestKey, ctx, "rest-key")
cfg.RestAPI.RestAuth = setBoolVal(cfg.RestAPI.RestAuth, ctx, "rest-auth")
cfg.RestAPI.RestAuthPassword = setStringVal(cfg.RestAPI.RestAuthPassword, ctx, "rest-auth-pwd")
// next for the scheduler related flags
cfg.Scheduler.WorkManagerQueueSize = setUIntVal(cfg.Scheduler.WorkManagerQueueSize, ctx, "work-manager-queue-size")
cfg.Scheduler.WorkManagerPoolSize = setUIntVal(cfg.Scheduler.WorkManagerPoolSize, ctx, "work-manager-pool-size")
// and finally for the tribe-related flags
cfg.Tribe.Name = setStringVal(cfg.Tribe.Name, ctx, "tribe-node-name")
cfg.Tribe.Enable = setBoolVal(cfg.Tribe.Enable, ctx, "tribe")
Expand Down

0 comments on commit 4537157

Please sign in to comment.