rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

[ISSUE #4654] Use the scheduleWithFixedDelay instead of creating unnecessary DeliverDelayedMessageTimerTask and HandlePutResultTask objects

Open yihleego opened this issue 2 years ago • 4 comments

Make sure set the target branch to develop

What is the purpose of the change

Use the scheduleWithFixedDelay instead of creating unnecessary DeliverDelayedMessageTimerTask and HandlePutResultTask objects to help GC.

Close #4654

Brief changelog

  • Modified org.apache.rocketmq.broker.schedule.ScheduleMessageService

Verifying this change

Follow this checklist to help us incorporate your contribution quickly and easily. Notice, it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.

  • [x] Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • [x] Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • [x] Run mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.
  • [ ] If this contribution is large, please file an Apache Individual Contributor License Agreement.

yihleego avatar Jul 21 '22 12:07 yihleego

IMO, scheduleWithFixedDelay method also create lots of Object.

ni-ze avatar Jul 22 '22 02:07 ni-ze

IMO, scheduleWithFixedDelay method also create lots of Object.

Hi @ni-ze,

Using the scheduleWithFixedDelay method can reuse Runnable objects. So I think it's unnecessary to create DeliverDelayedMessageTimerTask and HandlePutResultTask objects all the time.

If you mean that some objects will be created during the execution, I think it's inevitable.

Please check my commits and let me know if I missed something.

yihleego avatar Jul 22 '22 03:07 yihleego

Coverage Status

Coverage increased (+0.7%) to 49.203% when pulling 2725619623add58b1d32a64cad75ce5656587977 on yihleego:optimization-reduce-unnecessary-object-creation into 8ccffa7e8ad3fcc30c3390591118b86b0f5be897 on apache:develop.

coveralls avatar Aug 05 '22 08:08 coveralls

Codecov Report

Merging #4655 (2725619) into develop (8ccffa7) will increase coverage by 0.69%. The diff coverage is 16.66%.

@@              Coverage Diff              @@
##             develop    #4655      +/-   ##
=============================================
+ Coverage      44.31%   45.01%   +0.69%     
- Complexity      7280     7635     +355     
=============================================
  Files            968      977       +9     
  Lines          65899    67957    +2058     
  Branches        8635     8983     +348     
=============================================
+ Hits           29204    30589    +1385     
- Misses         33086    33581     +495     
- Partials        3609     3787     +178     
Impacted Files Coverage Δ
...cketmq/broker/schedule/ScheduleMessageService.java 55.26% <16.66%> (-2.15%) :arrow_down:
...ntroller/processor/ControllerRequestProcessor.java 26.19% <0.00%> (-21.64%) :arrow_down:
.../apache/rocketmq/controller/ControllerManager.java 60.86% <0.00%> (-17.04%) :arrow_down:
...ava/org/apache/rocketmq/broker/util/HookUtils.java 12.28% <0.00%> (-4.87%) :arrow_down:
...va/org/apache/rocketmq/common/message/Message.java 52.32% <0.00%> (-4.64%) :arrow_down:
...a/org/apache/rocketmq/broker/BrokerController.java 43.89% <0.00%> (-3.37%) :arrow_down:
...ava/org/apache/rocketmq/filter/util/BitsArray.java 59.82% <0.00%> (-2.57%) :arrow_down:
...a/org/apache/rocketmq/filter/util/BloomFilter.java 60.43% <0.00%> (-2.20%) :arrow_down:
...org/apache/rocketmq/store/ha/DefaultHAService.java 67.48% <0.00%> (-1.85%) :arrow_down:
... and 156 more

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

codecov-commenter avatar Aug 05 '22 08:08 codecov-commenter