birb-integrated-bench/src/Application.kt

40 lines
1.3 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)
val targetTime = Duration.ofSeconds(10)
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()
println("Starting benchmark")
2020-10-22 02:00:45 +02:00
while(elapsed > targetTime){
2020-10-22 02:11:14 +02:00
println(currIter)
uploader.uploadData(currIter, gson, cachedFile)
2020-10-22 02:00:45 +02:00
currIter+=1
currTimeStamp = Instant.now()
timestamps[currIter] = currTimeStamp
elapsed = Duration.between(startTime, currTimeStamp)
}
2020-10-22 02:11:14 +02:00
println("Benchmark ended")
processResults.process()
2020-10-21 23:24:29 +02:00
}
2020-10-22 02:11:14 +02:00
}