Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RIP-64] Heartbeat Optimization #6724

Merged
merged 15 commits into from
Jun 14, 2023

Conversation

zk-drizzle
Copy link
Contributor

Which Issue(s) This PR Fixes

Fixes #6720

Brief Description

How Did You Test This Change?

@@ -64,6 +65,7 @@ public class ClientConfig {
private boolean decodeReadBody = Boolean.parseBoolean(System.getProperty(DECODE_READ_BODY, "true"));
private boolean decodeDecompressBody = Boolean.parseBoolean(System.getProperty(DECODE_DECOMPRESS_BODY, "true"));
private boolean vipChannelEnabled = Boolean.parseBoolean(System.getProperty(SEND_MESSAGE_WITH_VIP_CHANNEL_PROPERTY, "false"));
private boolean useHeartbeatV2 = Boolean.parseBoolean(System.getProperty(HEART_BEAT_V2, "true"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HEART_BEAT_V2 default values false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get

@fuyou001
Copy link
Contributor

fuyou001 commented May 30, 2023

Could you add unit and compatibility test

@zk-drizzle
Copy link
Contributor Author

Could you add unit and compatibility test

Thanks very much for your review . No problem,I will add this part .

@zk-drizzle
Copy link
Contributor Author

The test report on heartbeat optimization is as follows link
https://docs.google.com/document/d/1aA159aIitPZLqaCoZ-FCCbacN1BiTN1c4q5C0gmMHbk/edit?usp=sharing

@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2023

Codecov Report

Merging #6724 (667a2b5) into develop (eef581b) will decrease coverage by 0.28%.
The diff coverage is 25.78%.

@@              Coverage Diff              @@
##             develop    #6724      +/-   ##
=============================================
- Coverage      42.93%   42.65%   -0.28%     
- Complexity      8995     9124     +129     
=============================================
  Files           1104     1126      +22     
  Lines          78380    80062    +1682     
  Branches       10207    10423     +216     
=============================================
+ Hits           33654    34153     +499     
- Misses         40512    41629    +1117     
- Partials        4214     4280      +66     
Impacted Files Coverage Δ
...g/apache/rocketmq/client/impl/MQClientAPIImpl.java 22.56% <0.00%> (-0.82%) ⬇️
...c/main/java/org/apache/rocketmq/common/MixAll.java 38.98% <ø> (-2.46%) ⬇️
...he/rocketmq/remoting/common/HeartbeatV2Result.java 0.00% <0.00%> (ø)
...tmq/remoting/protocol/heartbeat/HeartbeatData.java 0.00% <0.00%> (ø)
...rocketmq/client/impl/factory/MQClientInstance.java 44.72% <12.65%> (-3.23%) ⬇️
...apache/rocketmq/broker/client/ConsumerManager.java 79.21% <41.66%> (-1.51%) ⬇️
...cketmq/broker/processor/ClientManageProcessor.java 44.21% <61.70%> (+17.21%) ⬆️
.../java/org/apache/rocketmq/client/ClientConfig.java 63.48% <66.66%> (+0.11%) ⬆️
...cketmq/client/impl/consumer/RebalancePushImpl.java 49.18% <100.00%> (ø)

... and 136 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Override
public String toString() {
return "HeartbeatData [clientID=" + clientID + ", producerDataSet=" + producerDataSet
+ ", consumerDataSet=" + consumerDataSet + "]";
}

public int computeHeartbeatFingerprint() {
HeartbeatData heartbeatDataCopy = JSON.parseObject(JSON.toJSONString(this), HeartbeatData.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the performance issues in the code, especially when there is a large MQ cluster and many subscribed topics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Thank for your review at first,when a cid subscribe 500 topics, the computeHeartbeatFingerprint cost 70ms(In a 30s heartbeat cycle, it's not very much, but our broker can free up a lot of computation and reduce network bandwidth pressure).

boolean isBrokerSupportV2 = brokerSupportV2HeartbeatSet.contains(addr);
HeartbeatV2Result heartbeatV2Result = null;
if (isBrokerSupportV2 && null != brokerAddrHeartbeatFingerprintTable.get(addr) && brokerAddrHeartbeatFingerprintTable.get(addr) == currentHeartbeatFingerprint) {
heartbeatV2Result = this.mQClientAPIImpl.sendHeartbeatV2(addr, heartbeatDataWithoutSub, 3000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to replace 3000 with clientConfig.getMqClientApiTimeout()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your review, take it ~

}
log.info("sendHeartbeatToAllBrokerV2 simple brokerName: {} subChange: {} brokerAddrHeartbeatFingerprintTable: {}", brokerName, heartbeatV2Result.isSubChange(), JSON.toJSONString(brokerAddrHeartbeatFingerprintTable));
} else {
heartbeatV2Result = this.mQClientAPIImpl.sendHeartbeatV2(addr, heartbeatDataWithSub, 3000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your review, take it ~

continue;
}
}
if (null != consumerGroupHeartbeatTable.get(consumerData.getGroupName()) && consumerGroupHeartbeatTable.get(consumerData.getGroupName()) != heartbeatData.getHeartbeatFingerprint()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest line breaks for better codestyle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review, one line is also a kind of beauty~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use StringUtils.equals()

this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, subscriptionGroupConfig.getRetryQueueNums(), PermName.PERM_WRITE | PermName.PERM_READ, hasOrderTopicSub, topicSysFlag);
boolean changed = false;
if (heartbeatData.isWithoutSub()) {
changed = this.brokerController.getConsumerManager().registerConsumerWithoutSub(consumerData.getGroupName(), clientChannelInfo, consumerData.getConsumeType(), consumerData.getMessageModel(), consumerData.getConsumeFromWhere(), isNotifyConsumerIdsChangedEnable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

Copy link
Contributor

@fuyou001 fuyou001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RongtongJin
Copy link
Contributor

LGTM

@RongtongJin RongtongJin merged commit 3dda55e into apache:develop Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RIP-64] Heartbeat Optimization
6 participants