This commit is contained in:
parent
5962a477f4
commit
c05aabf185
@ -1,14 +1,7 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import io.ktor.application.*
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.apache.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
@ -29,44 +22,19 @@ fun Application.module(testing: Boolean = false) {
|
||||
val targetTime = Duration.ofSeconds(10)
|
||||
var currIter = 1
|
||||
val timestamps = LinkedHashMap<Int,Instant>()
|
||||
var currTimeStamp = Instant.now()
|
||||
var currTimeStamp : Instant
|
||||
val uploader = Uploader()
|
||||
val processResults = ProcessResults()
|
||||
println("Starting benchmark")
|
||||
while(elapsed > targetTime){
|
||||
uploadData(currIter, gson, cachedFile)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@KtorExperimentalAPI
|
||||
suspend fun uploadData(currIteration: Int, gson: Gson, inputSound: ByteArray) {
|
||||
HttpClient(Apache).use { client ->
|
||||
|
||||
val parts: List<PartData> = formData {
|
||||
val headersBuilder = HeadersBuilder()
|
||||
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
|
||||
headersBuilder[HttpHeaders.ContentDisposition] = "filename=csirip.wav"
|
||||
this.append(
|
||||
"file",
|
||||
inputSound,
|
||||
headersBuilder.build()
|
||||
)
|
||||
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", currIteration)
|
||||
val jsonHeadersBuilder = HeadersBuilder()
|
||||
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
||||
this.append(
|
||||
"description",
|
||||
gson.toJson(inputSvcApi),
|
||||
jsonHeadersBuilder.build()
|
||||
)
|
||||
}
|
||||
|
||||
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
||||
url("https://birb.k8s.kmlabz.com/benchmark")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class InputSvcApi(val date: String, val device_id: Int)
|
||||
}
|
3
src/InputSvcApi.kt
Normal file
3
src/InputSvcApi.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
data class InputSvcApi(val date: String, val device_id: Int)
|
20
src/ProcessResults.kt
Normal file
20
src/ProcessResults.kt
Normal file
@ -0,0 +1,20 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class ProcessResults {
|
||||
var mapToProcess = LinkedHashMap<Int, Instant>()
|
||||
private var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss_SSS")
|
||||
.withZone(ZoneId.systemDefault())
|
||||
|
||||
|
||||
fun process() {
|
||||
println("Start processing results")
|
||||
for ((id, instant) in this.mapToProcess) {
|
||||
val currInstantString = formatter.format(instant)
|
||||
println("$id, $currInstantString")
|
||||
}
|
||||
}
|
||||
}
|
41
src/Uploader.kt
Normal file
41
src/Uploader.kt
Normal file
@ -0,0 +1,41 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
import com.google.gson.Gson
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.apache.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
|
||||
class Uploader(){
|
||||
@KtorExperimentalAPI
|
||||
suspend fun uploadData(currIteration: Int, gson: Gson, inputSound: ByteArray) {
|
||||
HttpClient(Apache).use { client ->
|
||||
|
||||
val parts: List<PartData> = formData {
|
||||
val headersBuilder = HeadersBuilder()
|
||||
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
|
||||
headersBuilder[HttpHeaders.ContentDisposition] = "filename=csirip.wav"
|
||||
this.append(
|
||||
"file",
|
||||
inputSound,
|
||||
headersBuilder.build()
|
||||
)
|
||||
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", currIteration)
|
||||
val jsonHeadersBuilder = HeadersBuilder()
|
||||
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
||||
this.append(
|
||||
"description",
|
||||
gson.toJson(inputSvcApi),
|
||||
jsonHeadersBuilder.build()
|
||||
)
|
||||
}
|
||||
|
||||
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
||||
url("https://birb.k8s.kmlabz.com/benchmark")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user