birb-integrated-bench/src/Application.kt

41 lines
1.3 KiB
Kotlin
Raw Normal View History

2020-10-21 23:24:29 +02:00
package com.kmlabz.k8s
import io.ktor.application.*
import io.ktor.util.*
import kotlinx.coroutines.*
2020-10-22 02:00:45 +02:00
import java.time.Duration
import java.time.Instant
2020-10-21 23:24:29 +02:00
2020-10-22 00:21:19 +02:00
fun main(args: Array<String>): Unit = io.ktor.server.tomcat.EngineMain.main(args)
2020-10-21 23:24:29 +02:00
@KtorExperimentalAPI
2020-10-22 02:00:45 +02:00
@Suppress("unused")
2020-10-21 23:24:29 +02:00
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
runBlocking {
2020-10-22 19:28:27 +02:00
var startTime: Instant
2020-10-22 02:00:45 +02:00
var elapsed = Duration.ofSeconds(0)
2020-10-22 02:24:36 +02:00
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
2020-10-22 19:35:01 +02:00
var currIter = 0
2020-10-22 19:28:27 +02:00
val timestamps = LinkedHashMap<Int, Instant>()
var currTimeStamp: Instant
2020-10-22 02:11:14 +02:00
val uploader = Uploader()
val processResults = ProcessResults()
2020-10-22 02:24:36 +02:00
environment.monitor.subscribe(ApplicationStarted) {
2020-10-22 19:28:27 +02:00
println("Starting benchmark")
startTime = Instant.now()
while (elapsed < targetTime) {
2020-10-22 19:35:01 +02:00
currIter += 1
GlobalScope.launch {
2020-10-22 19:17:58 +02:00
uploader.uploadData(currIter)
2020-10-22 02:55:31 +02:00
currTimeStamp = Instant.now()
timestamps[currIter] = currTimeStamp
elapsed = Duration.between(startTime, currTimeStamp)
2020-10-22 02:24:36 +02:00
}
}
2020-10-22 19:35:01 +02:00
println("Benchmark ended")
processResults.mapToProcess = timestamps
processResults.process()
2020-10-22 02:00:45 +02:00
}
2020-10-21 23:24:29 +02:00
}
2020-10-22 02:11:14 +02:00
}