package com.kmlabz.k8s import com.google.gson.GsonBuilder import io.ktor.application.* import io.ktor.util.* import kotlinx.coroutines.* import java.io.File import java.time.Duration import java.time.Instant fun main(args: Array): Unit = io.ktor.server.tomcat.EngineMain.main(args) @KtorExperimentalAPI @Suppress("unused") @kotlin.jvm.JvmOverloads fun Application.module(testing: Boolean = false) { runBlocking { val cachedFile = File("/app/wave.wav").readBytes() val gson = GsonBuilder().setPrettyPrinting().create() val startTime = Instant.now() var elapsed = Duration.ofSeconds(0) val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong()) var currIter = 1 val timestamps = LinkedHashMap() var currTimeStamp : Instant val uploader = Uploader() val processResults = ProcessResults() 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() } } } }