From b7b94b6b3916a2f3819d1c69c7c7373c30ca23da Mon Sep 17 00:00:00 2001 From: sanposhiho Date: Sat, 8 May 2021 22:27:01 +0900 Subject: [PATCH] scheduler_perf: create sleep operation --- .../scheduler_perf/scheduler_perf_test.go | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/integration/scheduler_perf/scheduler_perf_test.go b/test/integration/scheduler_perf/scheduler_perf_test.go index 265823ae526..b16db2a5093 100644 --- a/test/integration/scheduler_perf/scheduler_perf_test.go +++ b/test/integration/scheduler_perf/scheduler_perf_test.go @@ -60,6 +60,7 @@ const ( createPodSetsOpcode = "createPodSets" churnOpcode = "churn" barrierOpcode = "barrier" + sleepOpcode = "sleep" extensionPointsLabelName = "extension_point" // Two modes supported in "churn" operator. @@ -208,7 +209,7 @@ func (op *op) UnmarshalJSON(b []byte) error { &createPodSetsOp{}, &churnOp{}, &barrierOp{}, - // TODO(#93793): add a sleep timer op to simulate waiting? + &sleepOp{}, // TODO(#94601): add a delete nodes op to simulate scaling behaviour? } var firstError error @@ -511,6 +512,44 @@ func (bo barrierOp) patchParams(w *workload) (realOp, error) { return &bo, nil } +// sleepOp defines an op that can be used to sleep for a specified amount of time. +// This is useful in simulating workloads that require some sort of time-based synchronisation. +type sleepOp struct { + // Must be "sleep". + Opcode string + // duration of sleep. + Duration time.Duration +} + +func (so *sleepOp) UnmarshalJSON(data []byte) (err error) { + var tmp struct { + Opcode string + Duration string + } + if err = json.Unmarshal(data, &tmp); err != nil { + return err + } + + so.Opcode = tmp.Opcode + so.Duration, err = time.ParseDuration(tmp.Duration) + return err +} + +func (so *sleepOp) isValid(_ bool) error { + if so.Opcode != sleepOpcode { + return fmt.Errorf("invalid opcode %q; expected %q", so.Opcode, sleepOpcode) + } + return nil +} + +func (so *sleepOp) collectsMetrics() bool { + return false +} + +func (so sleepOp) patchParams(_ *workload) (realOp, error) { + return &so, nil +} + func BenchmarkPerfScheduling(b *testing.B) { testCases, err := getTestCases(configFile) if err != nil { @@ -809,6 +848,11 @@ func runWorkload(b *testing.B, tc *testCase, w *workload) []DataItem { } } + case *sleepOp: + select { + case <-ctx.Done(): + case <-time.After(concreteOp.Duration): + } default: b.Fatalf("op %d: invalid op %v", opIndex, concreteOp) }