Compare commits
21 Commits
0106b94e8f
...
master
Author | SHA1 | Date | |
---|---|---|---|
ff98587aeb | |||
2eaa6de91f
|
|||
c0066bb414
|
|||
215bb0ed13
|
|||
567f8a8d24
|
|||
9663660519
|
|||
f3d339a4a6
|
|||
a212aa300c
|
|||
a4c9bd854e
|
|||
701412d7c2
|
|||
b285769cfd
|
|||
233b706d29
|
|||
afdd1ee4eb
|
|||
d81339b851
|
|||
89504a99ca
|
|||
4d0920c40f
|
|||
c05aabf185
|
|||
5962a477f4
|
|||
144452a768
|
|||
0638b7a116
|
|||
f6a8ac9aaf
|
20
.drone.yml
20
.drone.yml
@ -3,14 +3,6 @@ type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: code-analysis
|
||||
image: aosapps/drone-sonar-plugin
|
||||
settings:
|
||||
sonar_host:
|
||||
from_secret: SONAR_HOST
|
||||
sonar_token:
|
||||
from_secret: SONAR_CODE
|
||||
|
||||
- name: build_application
|
||||
image: openjdk:11-jdk
|
||||
commands:
|
||||
@ -30,6 +22,18 @@ steps:
|
||||
- latest
|
||||
- ${DRONE_BUILD_NUMBER}
|
||||
|
||||
- name: dockerhub
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: birbnetes/${DRONE_REPO_NAME}
|
||||
username:
|
||||
from_secret: DOCKERHUB_USER
|
||||
password:
|
||||
from_secret: DOCKERHUB_PASSWORD
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_BUILD_NUMBER}
|
||||
|
||||
- name: ms-teams
|
||||
image: kuperiu/drone-teams
|
||||
settings:
|
||||
|
@ -9,7 +9,7 @@ RUN chown -R $APPLICATION_USER /app
|
||||
USER $APPLICATION_USER
|
||||
|
||||
WORKDIR /app
|
||||
COPY ./build/libs/birb-integrated-bench-0.0.1.jar /app/birb-integrated-bench.jar
|
||||
COPY ./wave.wav /app/wave.wav
|
||||
COPY ./build/libs/birb-integrated-bench.jar /app/birb-integrated-bench.jar
|
||||
|
||||
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "birb-integrated-bench.jar"]
|
39
build.gradle
39
build.gradle
@ -1,25 +1,38 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri("https://repo.eclipse.org/content/repositories/paho-releases/")
|
||||
}
|
||||
maven {
|
||||
url = uri("https://plugins.gradle.org/m2/")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
apply plugin: 'application'
|
||||
|
||||
group 'com.kmlabz.k8s'
|
||||
version '0.0.1'
|
||||
mainClassName = "io.ktor.server.jetty.EngineMain"
|
||||
mainClassName = "io.ktor.server.tomcat.EngineMain"
|
||||
|
||||
sourceSets {
|
||||
main.kotlin.srcDirs = main.java.srcDirs = ['src']
|
||||
test.kotlin.srcDirs = test.java.srcDirs = ['test']
|
||||
main.resources.srcDirs = ['resources']
|
||||
test.resources.srcDirs = ['testresources']
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -31,12 +44,26 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "io.ktor:ktor-server-jetty:$ktor_version"
|
||||
implementation "io.ktor:ktor-server-tomcat:$ktor_version"
|
||||
implementation "ch.qos.logback:logback-classic:$logback_version"
|
||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-jetty:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-apache:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
|
||||
implementation "io.ktor:ktor-client-gson:$ktor_version"
|
||||
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
|
||||
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
|
||||
}
|
||||
|
||||
kotlin.experimental.coroutines = 'enable'
|
||||
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
baseName = 'birb-integrated-bench'
|
||||
classifier = null
|
||||
version = null
|
||||
}
|
@ -1,70 +1,54 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.internal.GsonBuildConfig
|
||||
import io.ktor.application.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.request.*
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.jetty.*
|
||||
import io.ktor.client.features.json.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.ContentDisposition.Companion.File
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import io.ktor.utils.io.streams.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.File
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import kotlin.collections.LinkedHashMap
|
||||
|
||||
fun main(args: Array<String>): Unit = io.ktor.server.jetty.EngineMain.main(args)
|
||||
fun main(args: Array<String>): Unit = io.ktor.server.tomcat.EngineMain.main(args)
|
||||
|
||||
@KtorExperimentalAPI
|
||||
@Suppress("unused") // Referenced in application.conf
|
||||
@Suppress("unused")
|
||||
@kotlin.jvm.JvmOverloads
|
||||
fun Application.module(testing: Boolean = false) {
|
||||
val client = HttpClient(Jetty) {
|
||||
install(JsonFeature) {
|
||||
serializer = GsonSerializer()
|
||||
}
|
||||
}
|
||||
runBlocking {
|
||||
val cachedFile = File("/app/wave.wav").readBytes()
|
||||
val gson = GsonBuilder().setPrettyPrinting().create()
|
||||
uploadData(1, gson, cachedFile)
|
||||
var startTime: Instant
|
||||
var currTimeStamp: Instant
|
||||
var elapsed = Duration.ZERO
|
||||
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
|
||||
var currIter = 0
|
||||
val timestamps = LinkedHashMap<Int, Instant>()
|
||||
val uploaders = LinkedList<Uploader>()
|
||||
val processResults = ProcessResults()
|
||||
var currUploader: Uploader
|
||||
environment.monitor.subscribe(ApplicationStarted) {
|
||||
GlobalScope.launch {
|
||||
println("Starting benchmark setup")
|
||||
startTime = Instant.now()
|
||||
while (elapsed < targetTime) {
|
||||
currIter += 1
|
||||
currUploader = Uploader()
|
||||
currUploader.currIteration = currIter
|
||||
currUploader.buildRequest()
|
||||
uploaders.add(currUploader)
|
||||
currTimeStamp = Instant.now()
|
||||
elapsed = Duration.between(startTime, currTimeStamp)
|
||||
}
|
||||
|
||||
println("Starting benchmark")
|
||||
for (uploader in uploaders) {
|
||||
uploader.sendRequest()
|
||||
}
|
||||
|
||||
@KtorExperimentalAPI
|
||||
suspend fun uploadData(currIteration: Int, gson: Gson, inputSound: ByteArray) {
|
||||
HttpClient(Jetty).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()
|
||||
)
|
||||
println("Data scrubbing")
|
||||
for (uploader in uploaders) {
|
||||
timestamps[uploader.currIteration] = uploader.respInstant
|
||||
}
|
||||
println("Benchmark ended")
|
||||
processResults.mapToProcess = timestamps
|
||||
processResults.process()
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
50
src/Uploader.kt
Normal file
50
src/Uploader.kt
Normal file
@ -0,0 +1,50 @@
|
||||
package com.kmlabz.k8s
|
||||
|
||||
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.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
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
|
||||
fun buildRequest() {
|
||||
parts = 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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@KtorExperimentalAPI
|
||||
suspend fun sendRequest() {
|
||||
HttpClient(Apache).use { client ->
|
||||
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
||||
url(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark")
|
||||
}
|
||||
respInstant = Instant.now()
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user