This commit is contained in:
@@ -5,6 +5,8 @@ import io.ktor.util.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import kotlin.collections.LinkedHashMap
|
||||
|
||||
fun main(args: Array<String>): Unit = io.ktor.server.tomcat.EngineMain.main(args)
|
||||
|
||||
@@ -14,28 +16,30 @@ fun main(args: Array<String>): Unit = io.ktor.server.tomcat.EngineMain.main(args
|
||||
fun Application.module(testing: Boolean = false) {
|
||||
runBlocking {
|
||||
var startTime: Instant
|
||||
var elapsed = Duration.ofSeconds(0)
|
||||
var elapsed = Duration.ZERO
|
||||
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
|
||||
var currIter = 0
|
||||
val timestamps = LinkedHashMap<Int, Instant>()
|
||||
var currTimeStamp: Instant
|
||||
val uploader = Uploader()
|
||||
val uploaders = LinkedList<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)
|
||||
GlobalScope.launch {
|
||||
println("Starting benchmark")
|
||||
startTime = Instant.now()
|
||||
while (elapsed < targetTime) {
|
||||
currIter += 1
|
||||
uploaders.add(Uploader(currIter))
|
||||
}
|
||||
for (uploader in uploaders) {
|
||||
uploader.sendRequest()
|
||||
}
|
||||
for (uploader in uploaders){
|
||||
timestamps[uploader.currIteration] = uploader.respInstant
|
||||
}
|
||||
println("Benchmark ended")
|
||||
processResults.mapToProcess = timestamps
|
||||
processResults.process()
|
||||
}
|
||||
println("Benchmark ended")
|
||||
processResults.mapToProcess = timestamps
|
||||
processResults.process()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user