LoranceChen
LoranceChen

Reputation: 2574

jdk21 virtual thread ArrayBlockingQueue.take() occupy many of CPU

I'm using netty websocket dispatch message to custom virtual thread executor.

Network layer as this:

  1. receive message: Client -> netty websocket channel -> disruptor ringbuff -> ArrayBlockingQueue -> virtual thread logic handler loop
  2. reponse message: virtual thread -> disruptor ringbuff -> netty websocket channel

The scenario is send echo benchmark from client <-> server

ArrayBlockingQueue work like this snippet in server:

 def routing(queue: ArrayBlockingQueue[InputMsg]): Unit = {
    var inputMsg: InputMsg = null
    while (true) {
      inputMsg = queue.take()
      // just simple response echo.
    }
  }

Besides, every websocket connection will new itself ArrayBlockingQueue. There no many concurrrecy racing on take method.

I'm profiling there with JProfiler are a lot CPU time cost on queue.take(). But doesn't it should be unmounted when block? and why not show the time cost on virtual thread underlying switch rather then take method.

enter image description here enter image description here

Upvotes: 0

Views: 92

Answers (0)

Related Questions