41 lines
1.3 KiB
Kotlin
41 lines
1.3 KiB
Kotlin
package com.kmlabz.k8s
|
|
|
|
import io.ktor.application.*
|
|
import io.ktor.util.*
|
|
import kotlinx.coroutines.*
|
|
import java.time.Duration
|
|
import java.time.Instant
|
|
|
|
fun main(args: Array<String>): Unit = io.ktor.server.tomcat.EngineMain.main(args)
|
|
|
|
@KtorExperimentalAPI
|
|
@Suppress("unused")
|
|
@kotlin.jvm.JvmOverloads
|
|
fun Application.module(testing: Boolean = false) {
|
|
runBlocking {
|
|
var startTime: Instant
|
|
var elapsed = Duration.ofSeconds(0)
|
|
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
|
|
var currIter = 0
|
|
val timestamps = LinkedHashMap<Int, Instant>()
|
|
var currTimeStamp: Instant
|
|
val uploader = Uploader()
|
|
val processResults = ProcessResults()
|
|
environment.monitor.subscribe(ApplicationStarted) {
|
|
println("Starting benchmark")
|
|
startTime = Instant.now()
|
|
while (elapsed < targetTime) {
|
|
currIter += 1
|
|
GlobalScope.launch {
|
|
uploader.uploadData(currIter)
|
|
currTimeStamp = Instant.now()
|
|
timestamps[currIter] = currTimeStamp
|
|
elapsed = Duration.between(startTime, currTimeStamp)
|
|
}
|
|
}
|
|
println("Benchmark ended")
|
|
processResults.mapToProcess = timestamps
|
|
processResults.process()
|
|
}
|
|
}
|
|
} |