Skip to content

Commit

Permalink
Repeat the queries by 10000 times in db to test the overhead of Ver…
Browse files Browse the repository at this point in the history
…t.x Web network protocol processing

The result shows that the number of queries has increased by about 50%, which roughly means Vert.x Web network protocol processing consumes about half the computing power of single db queries.
  • Loading branch information
ShreckYe committed Mar 21, 2024
1 parent 46273db commit 8d76ed2
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import io.vertx.sqlclient.PreparedQuery
import io.vertx.sqlclient.Row
import io.vertx.sqlclient.RowSet
import io.vertx.sqlclient.Tuple
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -125,13 +126,17 @@ class MainVerticle(val hasDb: Boolean) : CoroutineVerticle() {
return rowSets.map { it.single().toWorld() }
}

suspend inline fun selectRandomWorld() =
selectWorldQuery.execute(Tuple.of(randomIntBetween1And10000())).await()

fun Router.routes() {
get("/json").jsonResponseHandler {
jsonSerializationMessage
}

get("/db").jsonResponseHandler {
val rowSet = selectWorldQuery.execute(Tuple.of(randomIntBetween1And10000())).await()
repeat(9999) { selectRandomWorld() }
val rowSet = selectRandomWorld()
rowSet.single().toWorld()
}

Expand Down

0 comments on commit 8d76ed2

Please sign in to comment.