From 483823637cabecf30e56e0f9fe957531b9ddb3eb Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Fri, 15 Apr 2016 17:48:50 +0100 Subject: [PATCH 1/2] ciao-launcher: Send stats every 6 seconds Previously stats were sent every 30 seconds by launcher. This commit changes the period to 6 seconds. Instance resources are still computed every 30 seconds and so will only update every 30 seconds in the UI. Instance state, however, should now get updated every 6 seconds. Fixes #282 Signed-off-by: Mark Ryan --- ciao-launcher/instance.go | 4 ++-- ciao-launcher/main.go | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ciao-launcher/instance.go b/ciao-launcher/instance.go index 49ea10f25..b8c36c5e1 100644 --- a/ciao-launcher/instance.go +++ b/ciao-launcher/instance.go @@ -270,7 +270,7 @@ DONE: case <-id.statsTimer: d, m, c := id.vm.stats() id.ovsCh <- &ovsStatsUpdateCmd{id.instance, m, d, c} - id.statsTimer = time.After(time.Second * statsPeriod) + id.statsTimer = time.After(time.Second * resourcePeriod) case cmd := <-id.cmdCh: if !id.instanceCommand(cmd) { break DONE @@ -296,7 +296,7 @@ DONE: id.ovsCh <- &ovsStateChange{id.instance, ovsRunning} d, m, c := id.vm.stats() id.ovsCh <- &ovsStatsUpdateCmd{id.instance, m, d, c} - id.statsTimer = time.After(time.Second * statsPeriod) + id.statsTimer = time.After(time.Second * resourcePeriod) } } diff --git a/ciao-launcher/main.go b/ciao-launcher/main.go index bc45e03d6..894660a9f 100644 --- a/ciao-launcher/main.go +++ b/ciao-launcher/main.go @@ -75,12 +75,13 @@ func init() { } const ( - lockDir = "/tmp/lock/ciao" - instancesDir = "/var/lib/ciao/instances" - logDir = "/var/lib/ciao/logs/launcher" - instanceState = "state" - lockFile = "client-agent.lock" - statsPeriod = 30 + lockDir = "/tmp/lock/ciao" + instancesDir = "/var/lib/ciao/instances" + logDir = "/var/lib/ciao/logs/launcher" + instanceState = "state" + lockFile = "client-agent.lock" + statsPeriod = 6 + resourcePeriod = 30 ) type cmdWrapper struct { From 31a968834f685963432b71f189eaafd086be2eb6 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Tue, 12 Jul 2016 13:54:23 +0100 Subject: [PATCH 2/2] ciao-launcher: Ensure cpu profile and logs are flushed Launcher was mistakenly using defer to flush logs and to stop the CPU profiling when shutting down. However, as launcher is quit by calling os.Exit, deferred functions do not get called. This was leading to incomplete CPU profiles being generated. Fixes: #163 Signed-off-by: Mark Ryan --- ciao-launcher/main.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ciao-launcher/main.go b/ciao-launcher/main.go index 894660a9f..1ec59a950 100644 --- a/ciao-launcher/main.go +++ b/ciao-launcher/main.go @@ -528,32 +528,34 @@ func main() { log.Fatalf("Unable to initialise logs: %v", err) } + glog.Info("Starting Launcher") + + exitCode := 0 + var stopProfile func() if profileFN != nil { - stopProfile := profileFN() - if stopProfile != nil { - defer stopProfile() - } + stopProfile = profileFN() } - defer func() { - glog.Flush() - glog.Info("Exit") - }() - - glog.Info("Starting Launcher") - if hardReset { purgeLauncherState() - os.Exit(0) - } + } else { + setLimits() + + glog.Infof("Launcher will allow a maximum of %d instances", maxInstances) - setLimits() + if err := createMandatoryDirs(); err != nil { + glog.Fatalf("Unable to create mandatory dirs: %v", err) + } - glog.Infof("Launcher will allow a maximum of %d instances", maxInstances) + exitCode = startLauncher() + } - if err := createMandatoryDirs(); err != nil { - glog.Fatalf("Unable to create mandatory dirs: %v", err) + if stopProfile != nil { + stopProfile() } - os.Exit(startLauncher()) + glog.Flush() + glog.Info("Exit") + + os.Exit(exitCode) }