Duc
11/20/2024, 10:26 AMExposed
to connect to a MySQL database.
As stated in the documentation, suspendTransaction
is designed to offload blocking jobs.
However, during load testing, I found that newSuspendedTransaction
is significantly slower than transaction
.
Am I missing something?
Here’s the source I’m referring to:
https://ktor.io/docs/server-integrate-database.html
route
get<TestBlockingRoute> {
call.respond(UserLetterController().getOkWordsNotSuspend())
}
get<TestNonBlockingRoute> {
call.respond(UserLetterController().getOkWordsSuspend())
}
fun getOkWordsNotSuspend(): List<OkWordEntity> {
val okWords = transaction(UserDbReplicaDatabaseConnection.db) {
okWordRepository.get()
}
return okWords
}
suspend fun getOkWordsSuspend(): List<OkWordEntity> {
val okWords = UserDbReplicaDatabaseConnection.suspendTransaction {
okWordRepository.get()
}
return okWords
}