Alexander af Trolle
07/08/2025, 8:13 PMAlexander af Trolle
07/08/2025, 9:17 PM@Rpc
interface Service {
fun exampleFlow(): Flow<Int>
}
class ServiceImpl : Service {
override fun exampleFlow(): Flow<Int> = flow {
var counter = 0
while (true) {
emit(counter++)
delay(100)
}
}
}
fun main() {
embeddedServer(Netty, 8080) {
server()
client()
}.start(wait = true)
}
private fun Application.server() {
install(Krpc) { serialization { json() } }
routing {
rpc {
log.debug("on route")
registerService<Service> {
log.debug("on service")
ServiceImpl()
}
}
}
}
private fun Application.client() = launch {
val ktorClient = HttpClient { installKrpc { serialization { json() } } }
val rpcClient = ktorClient.rpc("<ws://127.0.0.1:8080>")
val service = rpcClient.withService<Service>()
while (true) {
withTimeoutOrNull(2.seconds) {
service.exampleFlow().collect()
}
log.debug("restart collection")
}
}
Alexander af Trolle
07/08/2025, 9:18 PMConnections ttl opn rt1 rt5 p50 p90
178 100 0.05 0.17 52.06 185.08
HTTP Requests
-------------
23:15:23.178 CEST GET / 101 Switching Protocols
23:15:21.162 CEST GET / 101 Switching Protocols
23:15:19.167 CEST GET / 101 Switching Protocols
...
Alexander af Trolle
07/08/2025, 9:18 PMDEBUG io.ktor.server.Application -- on route
DEBUG io.ktor.server.Application -- on service
DEBUG io.ktor.server.Application -- restart collection
DEBUG io.ktor.server.Application -- on route
DEBUG io.ktor.server.Application -- restart collection
DEBUG io.ktor.server.Application -- on route
DEBUG io.ktor.server.Application -- restart collection
DEBUG io.ktor.server.Application -- on route
DEBUG io.ktor.server.Application -- restart collection
DEBUG io.ktor.server.Application -- on route
DEBUG io.ktor.server.Application -- restart collection
....
Alexander af Trolle
07/08/2025, 9:19 PMAlexander af Trolle
07/08/2025, 10:28 PMAlexander af Trolle
07/09/2025, 7:00 AMAlexander Sysoev
07/09/2025, 8:00 AMAlexander af Trolle
07/09/2025, 8:49 AM