diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-04-12 14:31:22 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-04-12 14:31:22 +0200 |
| commit | aa37f425959af99d22ee199f65e543c1711826ff (patch) | |
| tree | ea6ba771102d122ad24b64110a3c349a5be306e2 | |
| parent | 878c22867424c3d361bf2b3d30b0af9e222829fa (diff) | |
perf: Improve performance interference model performance
| -rw-r--r-- | opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/workload/PerformanceInterferenceModel.kt | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/workload/PerformanceInterferenceModel.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/workload/PerformanceInterferenceModel.kt index 1efe7588..04056394 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/workload/PerformanceInterferenceModel.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/workload/PerformanceInterferenceModel.kt @@ -14,15 +14,29 @@ const val IMAGE_PERF_INTERFERENCE_MODEL = "image:performance-interference" * @param items The [PerformanceInterferenceModelItem]s that make up this model. */ data class PerformanceInterferenceModel( - val items: Set<PerformanceInterferenceModelItem> + val items: Set<PerformanceInterferenceModelItem>, + val random: Random = Random(0) ) { private var intersectingItems: List<PerformanceInterferenceModelItem> = emptyList() + private var comparator = Comparator<PerformanceInterferenceModelItem> { lhs, rhs -> + var cmp = lhs.performanceScore.compareTo(rhs.performanceScore) + if (cmp != 0) { + return@Comparator cmp + } + + cmp = lhs.minServerLoad.compareTo(rhs.minServerLoad) + if (cmp != 0) { + return@Comparator cmp + } + + 0 + } fun computeIntersectingItems(colocatedWorkloads: Set<Resource>) { val colocatedWorkloadIds = colocatedWorkloads.map { it.name } intersectingItems = items.filter { item -> colocatedWorkloadIds.intersect(item.workloadNames).size > 1 - } + }.sortedWith(comparator) } fun apply(currentServerLoad: Double): Double { @@ -30,11 +44,10 @@ data class PerformanceInterferenceModel( return 1.0 } val score = intersectingItems - .filter { it.minServerLoad <= currentServerLoad } - .minBy { it.performanceScore } + .firstOrNull { it.minServerLoad <= currentServerLoad } // Apply performance penalty to (on average) only one of the VMs - return if (score != null && Random.nextInt(score.workloadNames.size) == 0) { + return if (score != null && random.nextInt(score.workloadNames.size) == 0) { score.performanceScore } else { 1.0 @@ -66,7 +79,5 @@ data class PerformanceInterferenceModelItem( return true } - override fun hashCode(): Int { - return workloadNames.hashCode() - } + override fun hashCode(): Int = workloadNames.hashCode() } |
