From 33220cdd4fabf77c42b2f5c74ea929d95cc3fb38 Mon Sep 17 00:00:00 2001 From: lih666 Date: Wed, 10 Jun 2020 01:57:38 -0700 Subject: [PATCH] Merge branch 'master' into launcher # Conflicts: # src/phoenix/frontend/proto/main.go --- .../prototype/g_emulation_generator.go | 51 +++++++++++++++++++ src/phoenix/frontend/prototype/main.go | 26 ++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 src/phoenix/frontend/prototype/g_emulation_generator.go diff --git a/src/phoenix/frontend/prototype/g_emulation_generator.go b/src/phoenix/frontend/prototype/g_emulation_generator.go new file mode 100644 index 0000000..8eabee0 --- /dev/null +++ b/src/phoenix/frontend/prototype/g_emulation_generator.go @@ -0,0 +1,51 @@ +package main + +import "math/rand" + +type GoogleClusterTaskGenerator struct { + TaskDuration float64 + RandSeed int64 + TaskCount int +} + +var googleTimeFactors = []int{ + 51182, + 61100, + 76970, + 96318, + 102699, + 106596, + 110659, + 111951, + 112349, + 114887, + 123163, + 129392, + 129573, + 129698, + 129844, + 129954} + +const GOOGLE_TIME_MAX_RANGE = 129954 + +func NewGoogleClusterTaskGenerator(taskDuration float64, randSeed int64, taskCount int) GoogleClusterTaskGenerator { + ret := GoogleClusterTaskGenerator{ + TaskDuration: taskDuration, + RandSeed: randSeed, + TaskCount: taskCount, + } + + rand.Seed(randSeed) + return ret +} + +func (g GoogleClusterTaskGenerator) GetTaskDuration() float64 { + targetRange := rand.Int() % GOOGLE_TIME_MAX_RANGE + + for i := 0; i < len(googleTimeFactors); i++ { + if googleTimeFactors[i] >= targetRange { + return g.TaskDuration * (float64(i) + 1.0) + } + } + +} diff --git a/src/phoenix/frontend/prototype/main.go b/src/phoenix/frontend/prototype/main.go index 844d3ff..07ef041 100644 --- a/src/phoenix/frontend/prototype/main.go +++ b/src/phoenix/frontend/prototype/main.go @@ -14,12 +14,16 @@ import ( "time" ) +const DefaultRandSeed int64 = -13131313 + var ( frc = flag.String("conf", config.DefaultConfigPath, "config file") useRand = flag.Bool("useRand", false, "use random seed to generate job, default to hash based on address") jobCount = flag.Int("jobCount", 10, "number of job to generate") taskCount = flag.Int("taskCount", 10, "number of task in a job") meanDuration = flag.Float64("jobDuration", 3.0, "job duration in second") + randSeed = flag.Int64("randSeed", DefaultRandSeed, "task generation seed") + gEmulation = flag.Bool("gEmu", false, "use google cluster workload pattern") ) func noError(e error) { @@ -54,11 +58,21 @@ func main() { <-feConfig.Ready if *useRand { - rand.Seed(time.Now().UnixNano()) + // The case where we did not pass in a seed but still want to be rand + if *randSeed == DefaultRandSeed { + rand.Seed(time.Now().UnixNano()) + } else { + rand.Seed(*randSeed) + } } else { - // just some random number here - var randSeed int64 = 1111 - rand.Seed(randSeed) + // just some random number here for the purpose of predictable workload emulation + var localRandSeed int64 = 1111 + rand.Seed(localRandSeed) + } + + var gGenerator GoogleClusterTaskGenerator + if *gEmulation { + gGenerator = NewGoogleClusterTaskGenerator(*meanDuration, *randSeed, *taskCount) } numTasks := *taskCount @@ -78,6 +92,10 @@ func main() { currTaskDuration *= rand.ExpFloat64() } + if *gEmulation { + currTaskDuration = gGenerator.GetTaskDuration() + } + for j := 0; j < numTasks; j++ { taskid := jobid + "-task" + strconv.Itoa(j)