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

Heartbeat skip serialize and deserialize #7077

Merged
merged 4 commits into from
Feb 2, 2021
Merged

Heartbeat skip serialize and deserialize #7077

merged 4 commits into from
Feb 2, 2021

Conversation

zhangyz-hd
Copy link
Contributor

What is the purpose of the change

提供者和消费者之间的心跳,Request和Response的Data都为null:

//org.apache.dubbo.remoting.exchange.support.header.HeartbeatTimerTask#doTask
Request req = new Request();
req.setVersion(Version.getProtocolVersion());
req.setTwoWay(true);
req.setEvent(HEARTBEAT_EVENT);//HEARTBEAT_EVENT = null
//org.apache.dubbo.remoting.exchange.support.header.HeartbeatHandler#received
Response res = new Response(req.getId(), req.getVersion());
res.setEvent(HEARTBEAT_EVENT);//HEARTBEAT_EVENT = null

当提供者和消费者数量非常大时,每个节点都需要发送/接受大量的心跳Requet和Response,这些Requet、Response也会和服务调用一样经过serialize+encode、decode+deserialize,而其中的serialize/deserialize需要消耗过多的CPU资源。
这个优化的目的是对于心跳Requet/Response跳过serialize/deserialize处理,serialize改为赋值为null对象的序列化后字节,deserialize改为直接赋值null。

Brief changelog

在CodecSupport中增加getNullBytesOf(Serialization s)方法,首次访问时根据serialization获得null对象的字节数组并缓存到ID_NULLBYTES_MAP
DubboCodec、ExchangeCodec中在调整encodeRequest、encodeResponse、decodeBody逻辑,实现上述目标。

备注:目前DUBBO的Serialization的实现中,以下三个实现其实尚不支持null对象的序列化,在CodecSupport.getNullBytesOf中降级为返回空字符串。

  1. KryoSerialization2
  2. GenericProtobufSerialization
  3. GenericProtobufJsonSerialization

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GITHUB_issue field 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.
  • Format the pull request title like [Dubbo-XXX] Fix UnknownException when host config not exist #XXX. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test 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 sample in dubbo samples project.
  • Run mvn clean install -DskipTests=false & mvn clean test-compile failsafe:integration-test to make sure unit-test and integration-test pass.
  • If this contribution is large, please follow the Software Donation Guide.

@codecov-io
Copy link

codecov-io commented Jan 28, 2021

Codecov Report

Merging #7077 (fdc767a) into master (70b6fb3) will increase coverage by 0.38%.
The diff coverage is 63.07%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #7077      +/-   ##
============================================
+ Coverage     59.22%   59.61%   +0.38%     
+ Complexity      508      288     -220     
============================================
  Files          1028     1001      -27     
  Lines         41525    39994    -1531     
  Branches       6038     5941      -97     
============================================
- Hits          24593    23841     -752     
+ Misses        14169    13440     -729     
+ Partials       2763     2713      -50     
Impacted Files Coverage Δ Complexity Δ
...rg/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java 61.32% <30.00%> (-2.68%) 0.00 <0.00> (ø)
...e/dubbo/remoting/exchange/codec/ExchangeCodec.java 73.33% <57.14%> (-0.97%) 0.00 <0.00> (ø)
.../apache/dubbo/remoting/transport/CodecSupport.java 82.00% <90.00%> (+5.33%) 0.00 <0.00> (ø)
...che/dubbo/common/utils/CharSequenceComparator.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...che/dubbo/rpc/cluster/support/FailfastCluster.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...bo/rpc/cluster/interceptor/ClusterInterceptor.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...java/org/apache/dubbo/remoting/etcd/Constants.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...pache/dubbo/metadata/report/support/Constants.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...igurator/override/OverrideConfiguratorFactory.java 0.00% <0.00%> (-100.00%) 0.00% <0.00%> (ø%)
...e/dubbo/registry/status/RegistryStatusChecker.java 0.00% <0.00%> (-81.25%) 0.00% <0.00%> (ø%)
... and 182 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70b6fb3...fdc767a. Read the comment docs.

@AlbumenJ AlbumenJ added this to the 2.7.9 milestone Jan 29, 2021
Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

LGTM.

@chickenlj chickenlj merged commit f4b225e into apache:master Feb 2, 2021
AlbumenJ added a commit to AlbumenJ/dubbo that referenced this pull request May 26, 2021
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.

4 participants