You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "vio-lin (via GitHub)" <gi...@apache.org> on 2025/06/03 03:12:42 UTC

[D] [Q/A][Java SDK (Component)] Should RpcInvocation attribute reused in MergeableCluster [dubbo]

GitHub user vio-lin created a discussion: [Q/A][Java SDK (Component)] Should RpcInvocation attribute reused in MergeableCluster

### Pre-check

- [X] I am sure that all the content I provide is in English.


### Apache Dubbo Component

Java SDK (apache/dubbo)

### Details

In my case, i need some thing to pass concurrency counter from request to response.    

```mermaid
graph TB
  subgraph sync
    A[Reference] -->|concurrency +1| B[service]
    B --> |concurrency -1|C[Reference]
  end

  subgraph async
    D[Reference] -->|concurrency +1| E[service]
    F[server] --> |concurrency -1|G[Reference]
  end
```

i use invocation.attribute to save this concurrencyCounter.   
it work well in almost case. but in case 'MergeableClusterInvoker'  

org.apache.dubbo.rpc.cluster.support.MergeableClusterInvoker#doInvoke
```java
Map<String, Result> results = new HashMap<>();
        for (final Invoker<T> invoker : invokers) {
            RpcInvocation subInvocation = new RpcInvocation(invocation, invoker);
            subInvocation.setAttachment(Constants.ASYNC_KEY, "true");
            try {
                results.put(invoker.getUrl().getServiceKey(), invokeWithContext(invoker, subInvocation));
            } catch (RpcException
```
as invocation reused attribute, the [last] async call back response may decrease concurrency count for [next] request.  

org.apache.dubbo.rpc.cluster.support.BroadcastClusterInvoker#doInvoke create attribte by it self.
```java
 try {
                RpcInvocation subInvocation = new RpcInvocation(
                        invocation.getTargetServiceUniqueName(),
                        invocation.getServiceModel(),
                        invocation.getMethodName(),
                        invocation.getServiceName(),
                        invocation.getProtocolServiceKey(),
                        invocation.getParameterTypes(),
                        invocation.getArguments(),
                        invocation.copyObjectAttachments(),
                        invocation.getInvoker(),
                        Collections.synchronizedMap(new HashMap<>(invocation.getAttributes())),
                        invocation instanceof RpcInvocation ? ((RpcInvocation) invocation).getInvokeMode() : null);
```

some similar use case in `org.apache.dubbo.rpc.filter.ActiveLimitFilter#getElapsed`  may encounter same problem.    

should it use an other api for pass attribute or optimise rpcInvokcation recreate logic  


### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)


GitHub link: https://github.com/apache/dubbo/discussions/15427

----
This is an automatically sent email for notifications@dubbo.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@dubbo.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [D] [Q/A][Java SDK (Component)] Should RpcInvocation attribute reused in MergeableCluster [dubbo]

Posted by "vio-lin (via GitHub)" <gi...@apache.org>.
GitHub user vio-lin edited a discussion: [Q/A][Java SDK (Component)] Should RpcInvocation attribute reused in MergeableCluster

### Pre-check

- [X] I am sure that all the content I provide is in English.


### Apache Dubbo Component

Java SDK (apache/dubbo)

### Details

In my case, i need some thing to pass concurrency counter from request to response.    

```mermaid
graph TB
  subgraph sync_same_reference
    A[request1] -->|concurrency +1| B[invoker1]
    B --> |concurrency -1|C[request2]
    C-->|currency+1|D[invoker2]
    D-->|currency-1|E[reference]
  end

  subgraph async
    D[request1] -->|concurrency +1| E[invoker1]
    H[request2] -->|concurrency +1| I[invoker2]
    F[response1] --> |concurrency -1|G[Reference]
    J[response2] --> |concurrency -1|K[Reference]
  end
```

i use invocation.attribute to save this concurrencyCounter.   
it work well in almost case. but in case 'MergeableClusterInvoker'  

org.apache.dubbo.rpc.cluster.support.MergeableClusterInvoker#doInvoke
```java
Map<String, Result> results = new HashMap<>();
        for (final Invoker<T> invoker : invokers) {
            RpcInvocation subInvocation = new RpcInvocation(invocation, invoker);
            subInvocation.setAttachment(Constants.ASYNC_KEY, "true");
            try {
                results.put(invoker.getUrl().getServiceKey(), invokeWithContext(invoker, subInvocation));
            } catch (RpcException
```
as invocation reused attribute, the [last] async call back response may decrease concurrency count for [next] request.  

org.apache.dubbo.rpc.cluster.support.BroadcastClusterInvoker#doInvoke create attribte by it self.
```java
 try {
                RpcInvocation subInvocation = new RpcInvocation(
                        invocation.getTargetServiceUniqueName(),
                        invocation.getServiceModel(),
                        invocation.getMethodName(),
                        invocation.getServiceName(),
                        invocation.getProtocolServiceKey(),
                        invocation.getParameterTypes(),
                        invocation.getArguments(),
                        invocation.copyObjectAttachments(),
                        invocation.getInvoker(),
                        Collections.synchronizedMap(new HashMap<>(invocation.getAttributes())),
                        invocation instanceof RpcInvocation ? ((RpcInvocation) invocation).getInvokeMode() : null);
```

some similar use case in `org.apache.dubbo.rpc.filter.ActiveLimitFilter#getElapsed`  may encounter same problem.    

should it use an other api for pass attribute or optimise rpcInvokcation recreate logic  


### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)


GitHub link: https://github.com/apache/dubbo/discussions/15427

----
This is an automatically sent email for notifications@dubbo.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@dubbo.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [D] [Q/A][Java SDK (Component)] Should RpcInvocation attribute reused in MergeableCluster [dubbo]

Posted by "vio-lin (via GitHub)" <gi...@apache.org>.
GitHub user vio-lin edited a discussion: [Q/A][Java SDK (Component)] Should RpcInvocation attribute reused in MergeableCluster

### Pre-check

- [X] I am sure that all the content I provide is in English.


### Apache Dubbo Component

Java SDK (apache/dubbo)

### Details

In my case, i need some thing to pass concurrency counter from request to response.    

sync
```mermaid
graph LR
    A[request1] -->|concurrency +1| B[invoker1]
    B --> |concurrency -1|C[request2]
    C-->|currency+1|D[invoker2]
    D-->|currency-1|E[reference]

```

async
```mermaid
graph LR
    D[request1] -->|concurrency +1| E[invoker1]
    H[request2] -->|concurrency +1| I[invoker2]
    F[response1] --> |concurrency -1|G[Reference]
    J[response2] --> |concurrency -1|K[Reference]

```

i use invocation.attribute to save this concurrencyCounter.   
it work well in almost case. but in case 'MergeableClusterInvoker'  

org.apache.dubbo.rpc.cluster.support.MergeableClusterInvoker#doInvoke
```java
Map<String, Result> results = new HashMap<>();
        for (final Invoker<T> invoker : invokers) {
            RpcInvocation subInvocation = new RpcInvocation(invocation, invoker);
            subInvocation.setAttachment(Constants.ASYNC_KEY, "true");
            try {
                results.put(invoker.getUrl().getServiceKey(), invokeWithContext(invoker, subInvocation));
            } catch (RpcException
```
as invocation reused attribute, the [last] async call back response may decrease concurrency count for [next] request.  

but in org.apache.dubbo.rpc.cluster.support.BroadcastClusterInvoker#doInvoke create attribte by it self.
```java
 try {
                RpcInvocation subInvocation = new RpcInvocation(
                        invocation.getTargetServiceUniqueName(),
                        invocation.getServiceModel(),
                        invocation.getMethodName(),
                        invocation.getServiceName(),
                        invocation.getProtocolServiceKey(),
                        invocation.getParameterTypes(),
                        invocation.getArguments(),
                        invocation.copyObjectAttachments(),
                        invocation.getInvoker(),
                        Collections.synchronizedMap(new HashMap<>(invocation.getAttributes())),
                        invocation instanceof RpcInvocation ? ((RpcInvocation) invocation).getInvokeMode() : null);
```

some similar use case in `org.apache.dubbo.rpc.filter.ActiveLimitFilter#getElapsed`  may encounter same problem.    

should it use an other api for pass attribute or optimise rpcInvokcation recreate logic  


### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)


GitHub link: https://github.com/apache/dubbo/discussions/15427

----
This is an automatically sent email for notifications@dubbo.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@dubbo.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org