Spring RSocket high CPU usage after client disconnect

129 Views Asked by At

I've created a simple RSocket endpoint with Spring RSocket support:

@Controller
class SampleController {

    @MessageMapping("sample")
    fun sample(): Flux<ByteArray> {
        return Flux
            .fromIterable(generateSequence(1) { it + 1 }.asIterable())
            .delayElements(Duration.ofSeconds(2))
            .doOnNext { println(it) }
            .map { it.toString().toByteArray() }
    }
}

This works fine as long as a client is connected and pulling data:

rsc tcp://localhost:8888 --stream --route sample

Once I cancel this, CPU usage gets to 20%. If I run more rsc clients in parallel, CPU usage will be >50% when I cancel all of them.

I was trying to look for some samples where there is a clean-up on the server side, but didn't manage to find anything. Also, I've enabled global DEBUG logging level (logging.level.root=DEBUG), but there are is nothing in the logs after clients are canceled. I was thinking maybe there's some sort of automatic reconnection mechanism that kicks in and starts spamming requests.

So, am I missing something, and is there a way such behavior?

0

There are 0 best solutions below