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:35:18 +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 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) {
|
|
|
|
val job = GlobalScope.launch {
|
2020-10-22 02:29:39 +02:00
|
|
|
delay(3000L)
|
|
|
|
println("Starting benchmark")
|
2020-10-22 02:35:18 +02:00
|
|
|
startTime = Instant.now()
|
|
|
|
while(elapsed < targetTime){
|
2020-10-22 02:24:36 +02:00
|
|
|
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
|
|
|
}
|