apache / rocketmq

Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications.
https://rocketmq.apache.org/
Apache License 2.0
21.14k stars 11.65k forks source link

[Enhancement] NettyRemotingClient class uses the Timer task scheduler problem #6857

Closed Maijh97 closed 1 year ago

Maijh97 commented 1 year ago

Before Creating the Enhancement Request

Summary

NettyRemotingClient uses the Timer task scheduler to close and clear client-related connections, because the timer #scheduleAtFixedRate(java.util.TimerTask, long, long) method is used. When the server time changes, the tasks of the scheduler will be executed together. For example, the startup time of the service is 2022. After the startup is completed, the server synchronizes the latest time through the network to 2023, and the tasks that should be executed separately in 2022 and 2023 will be executed together. When they will also start to relevant ClientHouseKeepingService thread CPU usage will be very high.

Motivation

I want to know why timer#scheduleAtFixedRate() is used as a task instead of timer#schedule (). Timer#schedule() postpones the delayed task by the set time. Rather than the scheduleAtFixedRate method directly together execution.

Describe the Solution You'd Like

Hopefully, when the service starts, even if the time changes, it shouldn't cause cpu spikes.

Describe Alternatives You've Considered

Can use timer#schedule () instead of timer#scheduleAtFixedRate() or another task scheduler.

Additional Context

No response

Maijh97 commented 1 year ago

Finding that #6116 has replaced java.util.Timer with netty's HashedWheelTimer, using HashedWheelTimer to execute the delayed task, there is no problem described above.