Skip to content
Permalink
Browse files

Benchmarks

  • Loading branch information
JoeHegarty committed Nov 13, 2019
1 parent 4970fa0 commit 3e0adc53dd14092c9df4b9b8dca8d045bf7cef04
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper

// Shared dependencies
val grpcVersion by extra("1.24.1")
val grpcKotlinVersion by extra("0.1.1")
val grpcKotlinVersion by extra("0.1.2")
val protobufVersion by extra("3.10.0")
val kotlinCoroutinesVersion by extra("1.3.2")
val slf4jVersion by extra("1.7.26")
@@ -15,3 +15,5 @@ include(":src:orbit-server-etcd")
include(":src:orbit-application")

include(":src:orbit-client")

include(":src:orbit-benchmarks")
@@ -0,0 +1,21 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

plugins {
kotlin("jvm")
id("me.champeau.gradle.jmh") version "0.5.0"
}

dependencies {
implementation(project(":src:orbit-server"))
implementation(project(":src:orbit-client"))

}

jmh {
resultFormat = "csv"
resultsFile = file("build/reports/benchmarks.csv")
}
@@ -0,0 +1,122 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

package orbit.benchmark

import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import orbit.client.OrbitClient
import orbit.client.OrbitClientConfig
import orbit.client.actor.AbstractActor
import orbit.client.actor.ActorWithInt32Key
import orbit.client.actor.createProxy
import orbit.client.net.OrbitServiceLocator
import orbit.server.OrbitServer
import orbit.server.OrbitServerConfig
import orbit.server.mesh.LocalServerInfo
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.BenchmarkMode
import org.openjdk.jmh.annotations.Fork
import org.openjdk.jmh.annotations.Measurement
import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.annotations.OperationsPerInvocation
import org.openjdk.jmh.annotations.OutputTimeUnit
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.TearDown
import org.openjdk.jmh.annotations.Threads
import org.openjdk.jmh.annotations.Warmup
import java.net.URI
import java.util.concurrent.TimeUnit

private const val REQUESTS_PER_BATCH = 1
private const val ACTOR_POOL = 1


interface BasicBenchmarkActor : ActorWithInt32Key {
fun echo(string: String): Deferred<String>
}

class BasicBenchmarkActorImpl : BasicBenchmarkActor, AbstractActor() {
override fun echo(string: String): Deferred<String> {
return CompletableDeferred(string)
}
}

@State(Scope.Benchmark)
@Fork(1)
@Warmup(iterations = 5)
@Measurement(iterations = 20)
open class ActorBenchmarks {
private val targetUri = URI.create("orbit://localhost:5899/test")

private lateinit var server: OrbitServer
private lateinit var client: OrbitClient
private val actors = ArrayList<BasicBenchmarkActor>()

@Setup
fun setup() {
val serverConfig = OrbitServerConfig(
LocalServerInfo(
port = targetUri.port,
url = targetUri.toString()
)
)
val clientConfig =
OrbitClientConfig(
serviceLocator = OrbitServiceLocator(targetUri),
packages = listOf("orbit.benchmark")
)

server = OrbitServer(serverConfig)
client = OrbitClient(clientConfig)

runBlocking {
server.start().join()
client.start().join()

repeat(ACTOR_POOL) {
val actor = client.actorFactory.createProxy<BasicBenchmarkActor>(it)
actor.echo("Chevron $it encoded...").await()
actors.add(actor)
}
}
}

@Benchmark
@Threads(8)
@OperationsPerInvocation(REQUESTS_PER_BATCH)
fun echoThroughputBenchmark() = batchIteration()

@Benchmark
@Threads(8)
@OperationsPerInvocation(REQUESTS_PER_BATCH)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
fun echoTimingBenchmark() = batchIteration()

private fun batchIteration() {
val myList = ArrayList<Deferred<String>>(REQUESTS_PER_BATCH)
repeat(REQUESTS_PER_BATCH) {
val actor = actors.random()
myList.add(actor.echo("Chevron $it locked."))
}
runBlocking {
myList.awaitAll()
}
}

@TearDown
fun teardown() {
runBlocking {
client.stop().join()
server.stop().join()
}
}
}

0 comments on commit 3e0adc5

Please sign in to comment.
You can’t perform that action at this time.