birb-integrated-bench/src/Application.kt

44 lines
1.5 KiB
Kotlin
Raw Normal View History

2020-10-21 23:24:29 +02:00
package com.kmlabz.k8s
import com.google.gson.GsonBuilder
import io.ktor.application.*
import io.ktor.util.*
import kotlinx.coroutines.*
import java.io.File
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 {
val cachedFile = File("/app/wave.wav").readBytes()
val gson = GsonBuilder().setPrettyPrinting().create()
2020-10-22 02:00:45 +02:00
val startTime = Instant.now()
var elapsed = Duration.ofSeconds(0)
2020-10-22 02:24:36 +02:00
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
2020-10-22 02:00:45 +02:00
var currIter = 1
val timestamps = LinkedHashMap<Int,Instant>()
2020-10-22 02:11:14 +02:00
var currTimeStamp : Instant
val uploader = Uploader()
val processResults = ProcessResults()
2020-10-22 02:24:36 +02:00
environment.monitor.subscribe(ApplicationStarted) {
println("Starting benchmark")
val job = GlobalScope.launch {
while(elapsed > targetTime){
println(currIter)
uploader.uploadData(currIter, gson, cachedFile)
currIter+=1
currTimeStamp = Instant.now()
timestamps[currIter] = currTimeStamp
elapsed = Duration.between(startTime, currTimeStamp)
}
println("Benchmark ended")
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
}