Skip to content

Commit

Permalink
Fixing IAT for empty time slot
Browse files Browse the repository at this point in the history
Signed-off-by: Lazar Cvetković <[email protected]>
  • Loading branch information
cvetkovic committed Nov 25, 2024
1 parent 4887435 commit 6d29c10
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/driver/trace_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func TestDriverCompletely(t *testing.T) {
{
testName: "with_warmup",
withWarmup: true,
expectedInvocations: 9,
expectedInvocations: 10,
},
{
testName: "without_warmup_second_granularity",
Expand Down Expand Up @@ -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.")
}
})
Expand Down
23 changes: 21 additions & 2 deletions pkg/generator/specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

Expand Down
65 changes: 64 additions & 1 deletion pkg/generator/specification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d29c10

Please sign in to comment.