From 59a7470853957d6055c120e9bf8658b4b7b48879 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 13 Mar 2020 15:50:58 +0100 Subject: feat: Add infrastructure for failures --- .../atlarge/opendc/core/failure/FailureDomain.kt | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt new file mode 100644 index 00000000..b1c7ccd3 --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2020 atlarge-research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.atlarge.opendc.core.failure + +/** + * A logical or physical component in a computing environment which may fail. + */ +public interface FailureDomain { + /** + * Fail the domain externally. + */ + public suspend fun fail() +} -- cgit v1.2.3 From 95c9ae8a7c4efae57caba9863dfc3e10df23c2fd Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 13 Mar 2020 20:55:55 +0100 Subject: [ci skip] feat: Prototype design for FailureInjector --- .../atlarge/opendc/core/failure/FailureInjector.kt | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt new file mode 100644 index 00000000..456e18bb --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2020 atlarge-research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.atlarge.opendc.core.failure + +import kotlinx.coroutines.delay +import kotlinx.coroutines.isActive +import java.util.Random +import kotlin.coroutines.coroutineContext +import kotlin.math.ln +import kotlin.random.asKotlinRandom + +/** + * An entity that injects failures into a system. + * + * @param failureDomains The failure domains to be included. + */ +public class FailureInjector(private val failureDomains: List) { + /** + * The [Random] instance to generate the failures. + */ + private val random = Random() + + /** + * Start the failure injector process. + */ + public suspend operator fun invoke() { + val targets = HashSet(failureDomains) + val mu = 20.0 + while (targets.isNotEmpty() && coroutineContext.isActive) { + delay(random.expovariate(mu)) + val target = targets.random(random.asKotlinRandom()) + targets -= target + target.fail() + } + } + + private fun Random.expovariate(mu: Double) = (-mu * ln(1 - nextDouble())).toLong() +} -- cgit v1.2.3 From c9cd6bb12eee73562ed9078f01aa041c7f5ed8ae Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sun, 15 Mar 2020 17:20:08 +0100 Subject: feat: Make FaultInjector more generic --- .../atlarge/opendc/core/failure/FailureDomain.kt | 7 +++ .../atlarge/opendc/core/failure/FailureInjector.kt | 60 ---------------------- .../atlarge/opendc/core/failure/FaultInjector.kt | 35 +++++++++++++ .../core/failure/UncorrelatedFaultInjector.kt | 48 +++++++++++++++++ 4 files changed, 90 insertions(+), 60 deletions(-) delete mode 100644 opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt create mode 100644 opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FaultInjector.kt create mode 100644 opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt index b1c7ccd3..91ca9b83 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureDomain.kt @@ -24,10 +24,17 @@ package com.atlarge.opendc.core.failure +import kotlinx.coroutines.CoroutineScope + /** * A logical or physical component in a computing environment which may fail. */ public interface FailureDomain { + /** + * The lifecycle of the failure domain to which a [FaultInjector] will attach. + */ + public val scope: CoroutineScope + /** * Fail the domain externally. */ diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt deleted file mode 100644 index 456e18bb..00000000 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FailureInjector.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020 atlarge-research - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.atlarge.opendc.core.failure - -import kotlinx.coroutines.delay -import kotlinx.coroutines.isActive -import java.util.Random -import kotlin.coroutines.coroutineContext -import kotlin.math.ln -import kotlin.random.asKotlinRandom - -/** - * An entity that injects failures into a system. - * - * @param failureDomains The failure domains to be included. - */ -public class FailureInjector(private val failureDomains: List) { - /** - * The [Random] instance to generate the failures. - */ - private val random = Random() - - /** - * Start the failure injector process. - */ - public suspend operator fun invoke() { - val targets = HashSet(failureDomains) - val mu = 20.0 - while (targets.isNotEmpty() && coroutineContext.isActive) { - delay(random.expovariate(mu)) - val target = targets.random(random.asKotlinRandom()) - targets -= target - target.fail() - } - } - - private fun Random.expovariate(mu: Double) = (-mu * ln(1 - nextDouble())).toLong() -} diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FaultInjector.kt new file mode 100644 index 00000000..ac7a08de --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/FaultInjector.kt @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (c) 2020 atlarge-research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.atlarge.opendc.core.failure + +/** + * An interface for stochastically injecting faults into a running system. + */ +public interface FaultInjector { + /** + * Enqueue the specified [FailureDomain] into the queue as candidate for failure injection in the future. + */ + public fun enqueue(domain: FailureDomain) +} diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt new file mode 100644 index 00000000..95127deb --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt @@ -0,0 +1,48 @@ +/* + * MIT License + * + * Copyright (c) 2020 atlarge-research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.atlarge.opendc.core.failure + +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlin.math.ln +import kotlin.random.Random + +/** + * A [FaultInjector] that injects uncorrelated faults into the system, meaning that failures of the subsystems are + * independent. + */ +public class UncorrelatedFaultInjector(private val mu: Double = 256.0, private val random: Random = Random.Default) : FaultInjector { + /** + * Enqueue the specified [FailureDomain] to fail some time in the future. + */ + override fun enqueue(domain: FailureDomain) { + domain.scope.launch { + delay(random.expovariate(mu)) + domain.fail() + } + } + + private fun Random.expovariate(mu: Double) = (-mu * ln(1 - nextDouble())).toLong() +} -- cgit v1.2.3 From 5ff443c799322836d532fffb3ff8f720806c32b6 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 16 Mar 2020 23:07:22 +0100 Subject: feat: Add failures to SC20 experiment --- .../com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt index 95127deb..5155a25a 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt @@ -33,13 +33,14 @@ import kotlin.random.Random * A [FaultInjector] that injects uncorrelated faults into the system, meaning that failures of the subsystems are * independent. */ -public class UncorrelatedFaultInjector(private val mu: Double = 256.0, private val random: Random = Random.Default) : FaultInjector { +public class UncorrelatedFaultInjector(private val mu: Double = 1024.0, private val random: Random = Random.Default) : FaultInjector { /** * Enqueue the specified [FailureDomain] to fail some time in the future. */ override fun enqueue(domain: FailureDomain) { domain.scope.launch { - delay(random.expovariate(mu)) + val d = random.expovariate(mu) + delay(d) domain.fail() } } -- cgit v1.2.3 From b3e8e3d196de8b8c1bb904bfb3c6641415cf72bb Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 17 Mar 2020 15:52:10 +0100 Subject: feat: Use Weilbull distribution for failures --- .../opendc/core/failure/UncorrelatedFaultInjector.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt index 5155a25a..56706824 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt @@ -24,26 +24,35 @@ package com.atlarge.opendc.core.failure +import com.atlarge.odcsim.simulationContext import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlin.math.ln +import kotlin.math.ln1p +import kotlin.math.pow import kotlin.random.Random /** * A [FaultInjector] that injects uncorrelated faults into the system, meaning that failures of the subsystems are * independent. */ -public class UncorrelatedFaultInjector(private val mu: Double = 1024.0, private val random: Random = Random.Default) : FaultInjector { +public class UncorrelatedFaultInjector(private val alpha: Double, private val beta: Double, private val random: Random = Random) : FaultInjector { /** * Enqueue the specified [FailureDomain] to fail some time in the future. */ override fun enqueue(domain: FailureDomain) { domain.scope.launch { - val d = random.expovariate(mu) - delay(d) + val d = random.weibull(alpha, beta) * 1e3 // Make sure to convert delay to milliseconds + + // Handle long overflow + if (simulationContext.clock.millis() + d <= 0) { + return@launch + } + + delay(d.toLong()) domain.fail() } } - private fun Random.expovariate(mu: Double) = (-mu * ln(1 - nextDouble())).toLong() + // XXX We should extract this in some common package later on. + private fun Random.weibull(alpha: Double, beta: Double) = (beta * (-ln1p(-nextDouble())).pow(1.0 / alpha)) } -- cgit v1.2.3 From 6b10881f123f5e6a8e7bce1045d02eba5e48c3a2 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 17 Mar 2020 17:37:41 +0100 Subject: [ci skip] feat: Add support for correlated failures --- .../opendc/core/failure/CorrelatedFaultInjector.kt | 111 +++++++++++++++++++++ .../core/failure/UncorrelatedFaultInjector.kt | 2 +- .../opendc/core/services/ServiceRegistry.kt | 2 +- .../opendc/core/services/ServiceRegistryImpl.kt | 2 + 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt new file mode 100644 index 00000000..41412195 --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt @@ -0,0 +1,111 @@ +/* + * MIT License + * + * Copyright (c) 2020 atlarge-research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.atlarge.opendc.core.failure + +import com.atlarge.odcsim.Domain +import com.atlarge.odcsim.simulationContext +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay +import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.launch +import kotlin.math.exp +import kotlin.random.Random +import kotlin.random.asJavaRandom + +/** + * A [FaultInjector] that injects fault in the system which are correlated to each other. Failures do not occur in + * isolation, but will trigger other faults. + */ +public class CorrelatedFaultInjector( + private val domain: Domain, + private val iatScale: Double, + private val iatShape: Double, + private val sizeScale: Double, + private val sizeShape: Double, + random: Random = Random +) : FaultInjector { + /** + * The active failure domains that have been registered. + */ + private val active = mutableSetOf() + + /** + * The [Job] that awaits the nearest fault in the system. + */ + private var job: Job? = null + + /** + * The [Random] instance to use. + */ + private val random: java.util.Random = random.asJavaRandom() + + /** + * Enqueue the specified [FailureDomain] to fail some time in the future. + */ + override fun enqueue(domain: FailureDomain) { + active += domain + + // Clean up the domain if it finishes + domain.scope.coroutineContext[Job]!!.invokeOnCompletion { + this@CorrelatedFaultInjector.domain.launch { + println("CANCELLED") + active -= domain + + if (active.isEmpty()) { + job?.cancel() + job = null + } + } + } + + if (job != null) { + return + } + + job = this.domain.launch { + while (true) { + ensureActive() + + val d = lognvariate(iatScale, iatShape) * 1e3 // Make sure to convert delay to milliseconds + + // Handle long overflow + if (simulationContext.clock.millis() + d <= 0) { + return@launch + } + + delay(d.toLong()) + + val n = lognvariate(sizeScale, sizeShape).toInt() + + for (failureDomain in active.shuffled(random).take(n)) { + failureDomain.fail() + } + } + } + } + + // XXX We should extract this in some common package later on. + private fun lognvariate(scale: Double, shape: Double) = exp(scale + shape * random.nextGaussian()) +} diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt index 56706824..3883eb11 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/UncorrelatedFaultInjector.kt @@ -42,7 +42,7 @@ public class UncorrelatedFaultInjector(private val alpha: Double, private val be override fun enqueue(domain: FailureDomain) { domain.scope.launch { val d = random.weibull(alpha, beta) * 1e3 // Make sure to convert delay to milliseconds - + // Handle long overflow if (simulationContext.clock.millis() + d <= 0) { return@launch diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt index d9a85231..a036a705 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt @@ -48,5 +48,5 @@ public interface ServiceRegistry { /** * Register the specified [ServiceKey] in this registry. */ - public operator fun set(key: ServiceKey, service: T) + public operator fun set(key: ServiceKey, service: T): ServiceRegistry } diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt index 91147839..e3fa171d 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt @@ -43,4 +43,6 @@ public class ServiceRegistryImpl : ServiceRegistry { @Suppress("UNCHECKED_CAST") return services[key] as T } + + override fun toString(): String = services.toString() } -- cgit v1.2.3 From b1cf9b2bd9559328c3c9d26e73123e67d2bfea05 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 17 Mar 2020 22:26:15 +0100 Subject: refactor: Rework monitor interfaces --- .../atlarge/opendc/core/services/ServiceRegistry.kt | 19 +++++++++++++++---- .../opendc/core/services/ServiceRegistryImpl.kt | 20 ++++++++------------ 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt index a036a705..75aa778f 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistry.kt @@ -25,9 +25,14 @@ package com.atlarge.opendc.core.services /** - * A service registry for a datacenter zone. + * An immutable service registry interface. */ public interface ServiceRegistry { + /** + * The keys in this registry. + */ + public val keys: Collection> + /** * Determine if this map contains the service with the specified [ServiceKey]. * @@ -41,12 +46,18 @@ public interface ServiceRegistry { * * @param key The key of the service to obtain. * @return The references to the service. - * @throws IllegalArgumentException if the key does not exists in the map. + * @throws IllegalArgumentException if the key does not exist in the map. */ public operator fun get(key: ServiceKey): T /** - * Register the specified [ServiceKey] in this registry. + * Return the result of associating the specified [service] with the given [key] in this registry. */ - public operator fun set(key: ServiceKey, service: T): ServiceRegistry + public fun put(key: ServiceKey, service: T): ServiceRegistry } + +/** + * Construct an empty [ServiceRegistry]. + */ +@Suppress("FunctionName") +public fun ServiceRegistry(): ServiceRegistry = ServiceRegistryImpl(emptyMap()) diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt index e3fa171d..0686ebaf 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/services/ServiceRegistryImpl.kt @@ -27,22 +27,18 @@ package com.atlarge.opendc.core.services /** * Default implementation of the [ServiceRegistry] interface. */ -public class ServiceRegistryImpl : ServiceRegistry { - /** - * The map containing the registered services. - */ - private val services: MutableMap, Any> = mutableMapOf() +internal class ServiceRegistryImpl(private val map: Map, Any>) : ServiceRegistry { + override val keys: Collection> + get() = map.keys - override fun set(key: ServiceKey, service: T) { - services[key] = service - } - - override fun contains(key: ServiceKey<*>): Boolean = key in services + override fun contains(key: ServiceKey<*>): Boolean = key in map override fun get(key: ServiceKey): T { @Suppress("UNCHECKED_CAST") - return services[key] as T + return map[key] as T } - override fun toString(): String = services.toString() + override fun put(key: ServiceKey, service: T): ServiceRegistry = ServiceRegistryImpl(map.plus(key to service)) + + override fun toString(): String = map.toString() } -- cgit v1.2.3 From 7eb8177e2278bde2c0f4fad00af6fdd2d632cb5b Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 26 Mar 2020 12:37:54 +0100 Subject: feat: Implement correlated failures for individual clusters --- .../com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'opendc/opendc-core/src/main') diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt index 41412195..da4dee12 100644 --- a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/failure/CorrelatedFaultInjector.kt @@ -70,7 +70,6 @@ public class CorrelatedFaultInjector( // Clean up the domain if it finishes domain.scope.coroutineContext[Job]!!.invokeOnCompletion { this@CorrelatedFaultInjector.domain.launch { - println("CANCELLED") active -= domain if (active.isEmpty()) { @@ -88,7 +87,8 @@ public class CorrelatedFaultInjector( while (true) { ensureActive() - val d = lognvariate(iatScale, iatShape) * 1e3 // Make sure to convert delay to milliseconds + // Make sure to convert delay from hours to milliseconds + val d = lognvariate(iatScale, iatShape) * 3600 * 1e6 // Handle long overflow if (simulationContext.clock.millis() + d <= 0) { @@ -98,7 +98,6 @@ public class CorrelatedFaultInjector( delay(d.toLong()) val n = lognvariate(sizeScale, sizeShape).toInt() - for (failureDomain in active.shuffled(random).take(n)) { failureDomain.fail() } -- cgit v1.2.3