This commit is contained in:
parent
215bb0ed13
commit
c0066bb414
@ -23,14 +23,15 @@ fun Application.module(testing: Boolean = false) {
|
||||
val timestamps = LinkedHashMap<Int, Instant>()
|
||||
val uploaders = LinkedList<Uploader>()
|
||||
val processResults = ProcessResults()
|
||||
var currUploader : Uploader
|
||||
var currUploader: Uploader
|
||||
environment.monitor.subscribe(ApplicationStarted) {
|
||||
GlobalScope.launch {
|
||||
println("Starting benchmark")
|
||||
startTime = Instant.now()
|
||||
while (elapsed < targetTime) {
|
||||
currIter += 1
|
||||
currUploader = Uploader(currIter)
|
||||
currUploader = Uploader()
|
||||
currUploader.currIteration = currIter
|
||||
currUploader.buildRequest()
|
||||
uploaders.add(currUploader)
|
||||
currTimeStamp = Instant.now()
|
||||
@ -39,7 +40,7 @@ fun Application.module(testing: Boolean = false) {
|
||||
for (uploader in uploaders) {
|
||||
uploader.sendRequest()
|
||||
}
|
||||
for (uploader in uploaders){
|
||||
for (uploader in uploaders) {
|
||||
timestamps[uploader.currIteration] = uploader.respInstant
|
||||
}
|
||||
println("Benchmark ended")
|
||||
|
@ -1,24 +1,22 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.apache.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
class Uploader(currIteration: Int) {
|
||||
class Uploader{
|
||||
private val gson = GsonBuilder().setPrettyPrinting().create()
|
||||
private val inputSound = File("/app/wave.wav").readBytes()
|
||||
private lateinit var parts: List<PartData>
|
||||
var respInstant : Instant = Instant.now()
|
||||
var currIteration : Int = 0
|
||||
var respInstant: Instant = Instant.now()
|
||||
var currIteration: Int = 0
|
||||
fun buildRequest() {
|
||||
parts = formData {
|
||||
val headersBuilder = HeadersBuilder()
|
||||
@ -42,9 +40,11 @@ class Uploader(currIteration: Int) {
|
||||
|
||||
@KtorExperimentalAPI
|
||||
suspend fun sendRequest() {
|
||||
HttpClient(Apache).post<HttpResponse>(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark") {
|
||||
body = parts
|
||||
HttpClient(Apache).use { client ->
|
||||
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
||||
url(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark")
|
||||
}
|
||||
respInstant = Instant.now()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user