From 6d29c101488f90ffdb08adcbda36cb7d06987ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lazar=20Cvetkovi=C4=87?= Date: Mon, 25 Nov 2024 22:04:12 +0100 Subject: [PATCH] Fixing IAT for empty time slot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lazar Cvetković --- pkg/driver/trace_driver_test.go | 4 +- pkg/generator/specification.go | 23 +++++++++- pkg/generator/specification_test.go | 65 ++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/pkg/driver/trace_driver_test.go b/pkg/driver/trace_driver_test.go index 763f59702..1e98d1be9 100644 --- a/pkg/driver/trace_driver_test.go +++ b/pkg/driver/trace_driver_test.go @@ -346,7 +346,7 @@ func TestDriverCompletely(t *testing.T) { { testName: "with_warmup", withWarmup: true, - expectedInvocations: 9, + expectedInvocations: 10, }, { testName: "without_warmup_second_granularity", @@ -420,7 +420,7 @@ func TestDriverCompletely(t *testing.T) { } expectedInvocations := test.expectedInvocations - if !(successfulInvocation >= expectedInvocations && failedInvocations == 0) { + if !(successfulInvocation == expectedInvocations && failedInvocations == 0) { t.Error("Number of successful and failed invocations do not match.") } }) diff --git a/pkg/generator/specification.go b/pkg/generator/specification.go index c97336c24..b29950b36 100644 --- a/pkg/generator/specification.go +++ b/pkg/generator/specification.go @@ -131,6 +131,14 @@ func (s *SpecificationGenerator) generateIATPerGranularity(minuteIndex int, numb return iatResult, totalDuration } +func getBlankTimeUnit(granularity common.TraceGranularity) float64 { + if granularity == common.MinuteGranularity { + return 60_000_000 + } else { + return 1_000_000 + } +} + // GenerateIAT generates IAT according to the given distribution. Number of minutes is the length of invocationsPerMinute array func (s *SpecificationGenerator) generateIAT(invocationsPerMinute []int, iatDistribution common.IatDistribution, shiftIAT bool, granularity common.TraceGranularity) (common.IATArray, []int, common.ProbabilisticDuration) { @@ -139,12 +147,23 @@ func (s *SpecificationGenerator) generateIAT(invocationsPerMinute []int, iatDist var perMinuteCount []int var nonScaledDuration []float64 + accumulatedIdle := 0.0 + numberOfMinutes := len(invocationsPerMinute) for i := 0; i < numberOfMinutes; i++ { minuteIAT, duration := s.generateIATPerGranularity(i, invocationsPerMinute[i], iatDistribution, shiftIAT, granularity) + if len(minuteIAT) == 0 { + accumulatedIdle += getBlankTimeUnit(granularity) + continue + } else if accumulatedIdle != 0 { + IAT = append(IAT, accumulatedIdle) + IAT = append(IAT, minuteIAT[1:]...) + accumulatedIdle = 0.0 + } else { + IAT = append(IAT, minuteIAT...) + } - IAT = append(IAT, minuteIAT...) - perMinuteCount = append(perMinuteCount, len(minuteIAT)) + perMinuteCount = append(perMinuteCount, len(minuteIAT)-1) nonScaledDuration = append(nonScaledDuration, duration) } diff --git a/pkg/generator/specification_test.go b/pkg/generator/specification_test.go index 72784619e..1def5122b 100644 --- a/pkg/generator/specification_test.go +++ b/pkg/generator/specification_test.go @@ -103,7 +103,7 @@ func TestSerialGenerateIAT(t *testing.T) { testName: "no_invocations_exponential_shift", invocations: []int{5}, iatDistribution: common.Exponential, - shiftIAT: false, + shiftIAT: true, granularity: common.MinuteGranularity, expectedPoints: []float64{}, testDistribution: false, @@ -223,6 +223,69 @@ func TestSerialGenerateIAT(t *testing.T) { }, testDistribution: false, }, + { + testName: "2min_5ipm_with_zero__equidistant", + invocations: []int{0, 5}, + iatDistribution: common.Equidistant, + shiftIAT: false, + granularity: common.MinuteGranularity, + expectedPoints: []float64{ + 60_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + }, + testDistribution: false, + }, + { + testName: "6min_5ipm_with_zero__equidistant", + invocations: []int{0, 5, 0, 5, 0, 5}, + iatDistribution: common.Equidistant, + shiftIAT: false, + granularity: common.MinuteGranularity, + expectedPoints: []float64{ + 60_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + 60_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + 60_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + 12_000_000, + }, + testDistribution: false, + }, + { + testName: "2min_5ipm_with_zero_equidistant", + invocations: []int{0, 1, 0, 1}, + iatDistribution: common.Equidistant, + shiftIAT: false, + granularity: common.SecondGranularity, + expectedPoints: []float64{ + 1_000_000, + 1_000_000, + }, + testDistribution: false, + }, + { + testName: "five_empty_minutes", + invocations: []int{0, 0, 0, 0, 0, 1}, + iatDistribution: common.Equidistant, + shiftIAT: false, + granularity: common.MinuteGranularity, + expectedPoints: []float64{ + 300_000_000, + }, + testDistribution: false, + }, } var seed int64 = 123456789