Skip to content

Comments

Optimize security protocol reflection performance#15444

Closed
vio-lin wants to merge 2 commits intoapache:3.3from
vio-lin:optimse-security-protocol-reflection-performance
Closed

Optimize security protocol reflection performance#15444
vio-lin wants to merge 2 commits intoapache:3.3from
vio-lin:optimse-security-protocol-reflection-performance

Conversation

@vio-lin
Copy link
Contributor

@vio-lin vio-lin commented Jun 9, 2025

What is the purpose of the change?

#14937

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • 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. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2025

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.91%. Comparing base (6939e3c) to head (0b3c355).
Report is 1 commits behind head on 3.3.

Files with missing lines Patch % Lines
.../java/org/apache/dubbo/config/ReferenceConfig.java 90.47% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #15444      +/-   ##
============================================
- Coverage     60.92%   60.91%   -0.01%     
- Complexity    11432    11435       +3     
============================================
  Files          1887     1887              
  Lines         86266    86277      +11     
  Branches      12929    12929              
============================================
  Hits          52559    52559              
- Misses        28269    28284      +15     
+ Partials       5438     5434       -4     
Flag Coverage Δ
integration-tests-java17 33.09% <90.47%> (+<0.01%) ⬆️
integration-tests-java8 33.13% <90.47%> (+0.01%) ⬆️
samples-tests-java17 31.46% <90.47%> (+0.01%) ⬆️
samples-tests-java8 29.27% <90.47%> (+<0.01%) ⬆️
unit-tests 58.84% <90.47%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zrlw
Copy link
Contributor

zrlw commented Jun 9, 2025

in your machine it take how many times to process SerializeSecurityConfigurator addition with this pr? what's the different of cpu profile between the pr and original codes?
could you provide samples to https://github.com/apache/dubbo-samples or https://github.com/apache/dubbo-integration-cases/

@vio-lin
Copy link
Contributor Author

vio-lin commented Jun 10, 2025

in your machine it take how many times to process SerializeSecurityConfigurator addition with this pr? what's the different of cpu profile between the pr and original codes? could you provide samples to https://github.com/apache/dubbo-samples or https://github.com/apache/dubbo-integration-cases/

https://github.com/vio-lin/dubbo-samples/tree/test-security-protocol

dubbo-samples\2-advanced\dubbo-samples-async\dubbo-samples-async-simple-boot

step:

  1. start org.apache.dubbo.async.boot.provider.ProviderApplication2
  2. start org.apache.dubbo.async.boot.provider.ProviderApplication
  3. start org.apache.dubbo.async.boot.consumer.ConsumerApplication

With this pr SerializeSecurityConfigurator addition only process when client init。

case providers times(pre) thisPr description
case1 1 provider 3 1 1 from RegisterProtocolWrapper,one from ServiceDiscoveryRegistryDirectory, one for RegistryDirectory
case2 2 provider 5 5 1 frorm RegisterProtocolWrapper, 2 from ServiceDiscoveryRegistryDirectory, 2 from RegistryDirectory
case4 2000 provider 4001 1 1 frorm RegisterProtocolWrapper, 2000 from ServiceDiscoveryRegistryDirectory, 2000 from RegistryDirectory

in server side times relay to protocols size it can not be very large.
in client size 2 * providerSize

the cpu profile , i use interface with 3 method and requesttype and response type with one layer inner class.
it may take 9 ms process in SerializeSecurityConfigurator addition my pc.
9ms pluse server size it may be problem in RegisterNotify.

@zrlw
Copy link
Contributor

zrlw commented Jun 10, 2025

If it is necessary to add sample testing, you'd better add a separate test module instead of updating dubbo-samples-async-simple-boot, and submit a dubbo-samples pr for it.

@zrlw
Copy link
Contributor

zrlw commented Jun 10, 2025

@AlbumenJ PTAL

@zrlw
Copy link
Contributor

zrlw commented Jun 10, 2025

one reference.get() will call ProtocolSecurityWrapper#refer twice, first calling for the registry url like 'registry://xxx', second calling for the rpc url like 'tri://x.x.x.x/....', but only call ReferenceConfig#createProxy once.
this pr will cause registry url will not be processed.

@zrlw
Copy link
Contributor

zrlw commented Jun 12, 2025

i think the simplest way might be:

  1. move markedClass from method registerInterface into the fields of SerializeSecurityConfigurator for checking whether the interface has been checked or not, using HashSet is enough since registerInterface is synchronized method.
  2. add such checking codes to the beginning of method registerInterface:
        if (!checkClass(clazz)) {
            return;
        } 
  1. change the result type of checkClass method and remove markedClass from it's input params
private boolean checkClass(Class<?> clazz) {
        if (clazz == null) {
            return false;
        }

        if (!markedClass.add(clazz)) {
            return false;
        }
        // return true at follow codes.

@zrlw
Copy link
Contributor

zrlw commented Jun 12, 2025

i think the simplest way might be:

  1. move markedClass from method registerInterface into the fields of SerializeSecurityConfigurator for checking whether the interface has been checked or not, using HashSet is enough since registerInterface is synchronized method.
  2. add such checking codes to the beginning of method registerInterface:
        if (!checkClass(clazz)) {
            return;
        } 
  1. change the result type of checkClass method and remove markedClass from it's input params
private boolean checkClass(Class<?> clazz) {
        if (clazz == null) {
            return false;
        }

        if (!markedClass.add(clazz)) {
            return false;
        }
        // return true at follow codes.

@vio-lin would you like testing this plan and feedback what's the different?

@vio-lin
Copy link
Contributor Author

vio-lin commented Jun 12, 2025

i think the simplest way might be:

  1. move markedClass from method registerInterface into the fields of SerializeSecurityConfigurator for checking whether the interface has been checked or not, using HashSet is enough since registerInterface is synchronized method.
  2. add such checking codes to the beginning of method registerInterface:
        if (!checkClass(clazz)) {
            return;
        } 
  1. change the result type of checkClass method and remove markedClass from it's input params
private boolean checkClass(Class<?> clazz) {
        if (clazz == null) {
            return false;
        }

        if (!markedClass.add(clazz)) {
            return false;
        }
        // return true at follow codes.

@vio-lin would you like testing this plan and feedback what's the different?

wait for moment.

@zrlw zrlw added the status/waiting-for-feedback Need reporters to triage label Jun 19, 2025
@zrlw
Copy link
Contributor

zrlw commented Jun 23, 2025

@vio-lin any progress?

@vio-lin
Copy link
Contributor Author

vio-lin commented Jun 24, 2025

@vio-lin any progress?

on vacation last week. 😀
test today.

it works well

i change my test case registry multi instance to local zookeeper.
and use ai to create some complext response type ( 300lins )

provider

    <dubbo:protocol name="dubbo" port="20880"/>

    <bean id="asyncService" class="org.apache.dubbo.async.boot.provider.HiServiceImpl"/>

    <dubbo:service interface="org.apache.dubbo.samples.async.boot.HiService" version="1.001" ref="asyncService"/>
    <dubbo:service interface="org.apache.dubbo.samples.async.boot.HiService" version="1.002" ref="asyncService"/>
    <dubbo:service interface="org.apache.dubbo.samples.async.boot.HiService" version="1.003" ref="asyncService"/>

consumer

public class Task implements CommandLineRunner {
    @DubboReference(async = true,version = "*")
    private HiService hiService;

add breakPoint in org.apache.dubbo.registry.integration.RegistryDirectory#toInvokers the method start and end.

there is result.

case code instance count Time to process
1 code in dubbo 500instance 3091ms
2 code we changed 500instance 204ms
3 code in dubbo 1000instance 5166ms
4 code we change 1000instance 176ms

@zrlw
Copy link
Contributor

zrlw commented Jun 27, 2025

@vio-lin any progress?

on vacation last week. 😀 test today.

it works well

if so, just optimize SerializeSecurityConfigurator like this #15500 ?

@zrlw zrlw added help wanted Everything needs help from contributors type/enhancement Everything related with code enhancement or performance labels Jun 27, 2025
@zrlw zrlw changed the title Optimse security protocol reflection performance Optimize security protocol reflection performance Jun 29, 2025
@vio-lin
Copy link
Contributor Author

vio-lin commented Jun 30, 2025

@vio-lin any progress?

on vacation last week. 😀 test today.
it works well

if so, just optimize SerializeSecurityConfigurator like this #15500 ?

look good to me。

@zrlw zrlw closed this Jun 30, 2025
@zrlw
Copy link
Contributor

zrlw commented Jun 30, 2025

solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Everything needs help from contributors status/waiting-for-feedback Need reporters to triage type/enhancement Everything related with code enhancement or performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants