You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/10/13 07:32:45 UTC
[GitHub] [dubbo] ningboliu opened a new pull request, #10745: Adaptive loadbalance
ningboliu opened a new pull request, #10745:
URL: https://github.com/apache/dubbo/pull/10745
## What is the purpose of the change
issue 10571
adaptive loadbalance
## Brief changelog
## Verifying this change
<!-- Follow this checklist to help us incorporate your contribution quickly and easily: -->
## Checklist
- [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) 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.
- [ ] 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.
- [ ] Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
- [ ] 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](https://github.com/apache/dubbo-samples) project.
- [ ] Add some description to [dubbo-website](https://github.com/apache/dubbo-website) project if you are requesting to add a feature.
- [ ] GitHub Actions works fine on your own branch.
- [ ] If this contribution is large, please follow the [Software Donation Guide](https://github.com/apache/dubbo/wiki/Software-donation-guide).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] ningboliu commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
ningboliu commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1031975222
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
+ Invoker invoker = selectByP2C(invokers,url,invocation);
+ invocation.setAttachment(Constants.ADAPTIVE_LOADBALANCE_ATTACHMENT_KEY,attachmentKey);
Review Comment:
Need to pass parameters to provider
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1032128892
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000, value = {"loadbalance:adaptive"})
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ public AdaptiveLoadBalanceFilter(ApplicationModel scopeModel) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+
+ private ThreadPoolExecutor getExecutor(){
+ if (null == executor) {
+ synchronized (this) {
+ if (null == executor) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
+ GlobalResourcesRepository.getInstance().registerDisposable(() -> this.executor.shutdown());
+ }
+ }
+ }
+ return executor;
+ }
+
+ @Override
+ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ return invoker.invoke(invocation);
+ }
+
+ private String buildServiceKey(Invocation invocation){
+ StringBuilder sb = new StringBuilder(128);
+ sb.append(invocation.getInvoker().getUrl().getAddress()).append(":").append(invocation.getProtocolServiceKey());
+ return sb.toString();
+ //return url.getAddress() + ProtocolUtils.serviceKey(url.getPort(), url.getPath(), url.getVersion(), url.getGroup());
+ }
+
+ private String getServiceKey(Invocation invocation){
+
+ String key = (String) invocation.getAttributes().get(invocation.getInvoker());
+ if (StringUtils.isNotEmpty(key)){
+ return key;
+ }
+
+ key = buildServiceKey(invocation);
+ invocation.getAttributes().put(invocation.getInvoker(),key);
+ return key;
+ }
Review Comment:
Will this key be reused?
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000, value = {"loadbalance:adaptive"})
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener {
Review Comment:
Move this filter to implement `Filter` would be better. The implementation are related with the actual provider address.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] sonarcloud[bot] commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1330643117
SonarCloud Quality Gate failed. [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_dubbo&pullRequest=10745)
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [![B](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/B-16px.png 'B')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [1 Bug](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG)
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY)
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT)
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL)
[![28.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/25-16px.png '28.4%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list) [28.4% Coverage](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list)
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] ningboliu commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
ningboliu commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1032399438
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000, value = {"loadbalance:adaptive"})
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ public AdaptiveLoadBalanceFilter(ApplicationModel scopeModel) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+
+ private ThreadPoolExecutor getExecutor(){
+ if (null == executor) {
+ synchronized (this) {
+ if (null == executor) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
+ GlobalResourcesRepository.getInstance().registerDisposable(() -> this.executor.shutdown());
+ }
+ }
+ }
+ return executor;
+ }
+
+ @Override
+ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ return invoker.invoke(invocation);
+ }
+
+ private String buildServiceKey(Invocation invocation){
+ StringBuilder sb = new StringBuilder(128);
+ sb.append(invocation.getInvoker().getUrl().getAddress()).append(":").append(invocation.getProtocolServiceKey());
+ return sb.toString();
+ //return url.getAddress() + ProtocolUtils.serviceKey(url.getPort(), url.getPath(), url.getVersion(), url.getGroup());
+ }
+
+ private String getServiceKey(Invocation invocation){
+
+ String key = (String) invocation.getAttributes().get(invocation.getInvoker());
+ if (StringUtils.isNotEmpty(key)){
+ return key;
+ }
+
+ key = buildServiceKey(invocation);
+ invocation.getAttributes().put(invocation.getInvoker(),key);
+ return key;
+ }
Review Comment:
used 2 times
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] ningboliu commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
ningboliu commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1277172779
**基准测试**
环境
Linux version 3.10.0-1127.el7.x86_64
4C8G
java version "11.0.16.1"
网络:内网千兆网络
启动参数:-Xms2048m -Xmx2048m -XX:+UseG1GC
2服务器
```java
Benchmark Mode Cnt Score Error Units
LoadBalance.adaptive thrpt 4 12908.232 ± 2808.715 ops/s
LoadBalance.random thrpt 4 13197.763 ± 2388.624 ops/s
LoadBalance.roundrobin thrpt 4 11899.578 ± 6931.389 ops/s
LoadBalance.shortestresponse thrpt 4 11052.168 ± 517.151 ops/s
```
3服务器
```java
LoadBalance.adaptive thrpt 4 19371.779 ± 2645.146 ops/s
LoadBalance.random thrpt 4 19628.743 ± 4685.654 ops/s
LoadBalance.roundrobin thrpt 4 19630.657 ± 4619.797 ops/s
LoadBalance.shortestresponse thrpt 4 19250.009 ± 4268.092 ops/s
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1033057607
##########
dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalanceTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class AdaptiveLoadBalanceTest extends LoadBalanceBaseTest {
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Test
+ @Order(0)
+ void testSelectByWeight() {
+ int sumInvoker1 = 0;
+ int sumInvoker2 = 0;
+ int sumInvoker3 = 0;
+ int loop = 10000;
+
+ ApplicationModel scopeModel = ApplicationModel.defaultModel();
+
+ AdaptiveLoadBalance lb = new AdaptiveLoadBalance(scopeModel);
+ for (int i = 0; i < loop; i++) {
+ Invoker selected = lb.select(weightInvokers, null, weightTestInvocation);
+
+ if (selected.getUrl().getProtocol().equals("test1")) {
+ sumInvoker1++;
+ }
+
+ if (selected.getUrl().getProtocol().equals("test2")) {
+ sumInvoker2++;
+ }
+
+ if (selected.getUrl().getProtocol().equals("test3")) {
+ sumInvoker3++;
+ }
+ }
+
+ // 1 : 9 : 6
+ System.out.println(sumInvoker1);
+ System.out.println(sumInvoker2);
+ System.out.println(sumInvoker3);
+ Assertions.assertEquals(sumInvoker1 + sumInvoker2 + sumInvoker3, loop, "select failed!");
+ }
+
+ private String buildServiceKey(Invoker invoker){
+ URL url = invoker.getUrl();
+ return url.getAddress() + ":" + invocation.getProtocolServiceKey();
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Test
+ @Order(1)
+ void testSelectByAdaptive() throws NoSuchFieldException, IllegalAccessException {
+ int sumInvoker1 = 0;
+ int sumInvoker2 = 0;
+ int sumInvoker5 = 0;
+ int loop = 10000;
+
+ scopeModel = ApplicationModel.defaultModel();
+ AdaptiveLoadBalance lb = new AdaptiveLoadBalance(scopeModel);
+
+ lb.select(weightInvokersSR, null, weightTestInvocation);
+
+ for (int i = 0; i < loop; i++) {
+ Invoker selected = lb.select(weightInvokersSR, null, weightTestInvocation);
+
+ Map<String, String> metricsMap = new HashMap<>();
+ String idKey = buildServiceKey(selected);
+
+ if (selected.getUrl().getProtocol().equals("test1")) {
+ sumInvoker1++;
+ metricsMap.put("rt", "10");
+ metricsMap.put("load", "10");
+ metricsMap.put("curTime", String.valueOf(System.currentTimeMillis()-10));
+ getAdaptiveMetricsInstance().addConsumerSuccess(idKey);
+ }
+
+ if (selected.getUrl().getProtocol().equals("test2")) {
+ sumInvoker2++;
+ metricsMap.put("rt", "100");
+ metricsMap.put("load", "40");
+ metricsMap.put("curTime", String.valueOf(System.currentTimeMillis()-100));
+ getAdaptiveMetricsInstance().addConsumerSuccess(idKey);
+ }
+
+ if (selected.getUrl().getProtocol().equals("test5")) {
+ metricsMap.put("rt", "5000");
+ metricsMap.put("load", "400");//400%
+ metricsMap.put("curTime", String.valueOf(System.currentTimeMillis() - 5000));
+
+ getAdaptiveMetricsInstance().addErrorReq(idKey);
+ sumInvoker5++;
+ }
+ getAdaptiveMetricsInstance().setProviderMetrics(idKey,metricsMap);
+
+ }
+ Map<Invoker<LoadBalanceBaseTest>, Integer> weightMap = weightInvokersSR.stream()
+ .collect(Collectors.toMap(Function.identity(), e -> Integer.valueOf(e.getUrl().getParameter("weight"))));
+ Integer totalWeight = weightMap.values().stream().reduce(0, Integer::sum);
+ // max deviation = expectWeightValue * 2
+ int expectWeightValue = loop / totalWeight;
+ int maxDeviation = expectWeightValue * 2;
+ double beta = 0.5;
+ //这个估算值并不准确
+ double ewma1 = beta * 50 + (1 - beta) * 10;
+ double ewma2 = beta * 50 + (1 - beta) * 100;
+ double ewma5 = beta * 50 + (1 - beta) * 5000;
+
+ AtomicInteger weight1 = new AtomicInteger();
+ AtomicInteger weight2 = new AtomicInteger();
+ AtomicInteger weight5 = new AtomicInteger();
+ weightMap.forEach((k, v) ->{
+ if (k.getUrl().getProtocol().equals("test1")){
+ weight1.set(v);
+ }
+ else if (k.getUrl().getProtocol().equals("test2")){
+ weight2.set(v);
+ }
+ else if (k.getUrl().getProtocol().equals("test5")){
+ weight5.set(v);
+ }
+ });
+
+ System.out.println(sumInvoker1);
+ System.out.println(sumInvoker2);
+ System.out.println(sumInvoker5);
Review Comment:
Print here is useless
##########
dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalanceTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class AdaptiveLoadBalanceTest extends LoadBalanceBaseTest {
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Test
+ @Order(0)
+ void testSelectByWeight() {
+ int sumInvoker1 = 0;
+ int sumInvoker2 = 0;
+ int sumInvoker3 = 0;
+ int loop = 10000;
+
+ ApplicationModel scopeModel = ApplicationModel.defaultModel();
+
+ AdaptiveLoadBalance lb = new AdaptiveLoadBalance(scopeModel);
+ for (int i = 0; i < loop; i++) {
+ Invoker selected = lb.select(weightInvokers, null, weightTestInvocation);
+
+ if (selected.getUrl().getProtocol().equals("test1")) {
+ sumInvoker1++;
+ }
+
+ if (selected.getUrl().getProtocol().equals("test2")) {
+ sumInvoker2++;
+ }
+
+ if (selected.getUrl().getProtocol().equals("test3")) {
+ sumInvoker3++;
+ }
+ }
+
+ // 1 : 9 : 6
+ System.out.println(sumInvoker1);
+ System.out.println(sumInvoker2);
+ System.out.println(sumInvoker3);
+ Assertions.assertEquals(sumInvoker1 + sumInvoker2 + sumInvoker3, loop, "select failed!");
+ }
+
+ private String buildServiceKey(Invoker invoker){
+ URL url = invoker.getUrl();
+ return url.getAddress() + ":" + invocation.getProtocolServiceKey();
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Test
+ @Order(1)
+ void testSelectByAdaptive() throws NoSuchFieldException, IllegalAccessException {
+ int sumInvoker1 = 0;
+ int sumInvoker2 = 0;
+ int sumInvoker5 = 0;
+ int loop = 10000;
+
+ scopeModel = ApplicationModel.defaultModel();
+ AdaptiveLoadBalance lb = new AdaptiveLoadBalance(scopeModel);
+
+ lb.select(weightInvokersSR, null, weightTestInvocation);
+
+ for (int i = 0; i < loop; i++) {
+ Invoker selected = lb.select(weightInvokersSR, null, weightTestInvocation);
+
+ Map<String, String> metricsMap = new HashMap<>();
+ String idKey = buildServiceKey(selected);
+
+ if (selected.getUrl().getProtocol().equals("test1")) {
+ sumInvoker1++;
+ metricsMap.put("rt", "10");
+ metricsMap.put("load", "10");
+ metricsMap.put("curTime", String.valueOf(System.currentTimeMillis()-10));
+ getAdaptiveMetricsInstance().addConsumerSuccess(idKey);
+ }
+
+ if (selected.getUrl().getProtocol().equals("test2")) {
+ sumInvoker2++;
+ metricsMap.put("rt", "100");
+ metricsMap.put("load", "40");
+ metricsMap.put("curTime", String.valueOf(System.currentTimeMillis()-100));
+ getAdaptiveMetricsInstance().addConsumerSuccess(idKey);
+ }
+
+ if (selected.getUrl().getProtocol().equals("test5")) {
+ metricsMap.put("rt", "5000");
+ metricsMap.put("load", "400");//400%
+ metricsMap.put("curTime", String.valueOf(System.currentTimeMillis() - 5000));
+
+ getAdaptiveMetricsInstance().addErrorReq(idKey);
+ sumInvoker5++;
+ }
+ getAdaptiveMetricsInstance().setProviderMetrics(idKey,metricsMap);
+
+ }
+ Map<Invoker<LoadBalanceBaseTest>, Integer> weightMap = weightInvokersSR.stream()
+ .collect(Collectors.toMap(Function.identity(), e -> Integer.valueOf(e.getUrl().getParameter("weight"))));
+ Integer totalWeight = weightMap.values().stream().reduce(0, Integer::sum);
+ // max deviation = expectWeightValue * 2
+ int expectWeightValue = loop / totalWeight;
+ int maxDeviation = expectWeightValue * 2;
+ double beta = 0.5;
+ //这个估算值并不准确
Review Comment:
comment in English
##########
dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalanceTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class AdaptiveLoadBalanceTest extends LoadBalanceBaseTest {
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Test
+ @Order(0)
+ void testSelectByWeight() {
+ int sumInvoker1 = 0;
+ int sumInvoker2 = 0;
+ int sumInvoker3 = 0;
+ int loop = 10000;
+
+ ApplicationModel scopeModel = ApplicationModel.defaultModel();
+
+ AdaptiveLoadBalance lb = new AdaptiveLoadBalance(scopeModel);
+ for (int i = 0; i < loop; i++) {
+ Invoker selected = lb.select(weightInvokers, null, weightTestInvocation);
+
+ if (selected.getUrl().getProtocol().equals("test1")) {
+ sumInvoker1++;
+ }
+
+ if (selected.getUrl().getProtocol().equals("test2")) {
+ sumInvoker2++;
+ }
+
+ if (selected.getUrl().getProtocol().equals("test3")) {
+ sumInvoker3++;
+ }
+ }
+
+ // 1 : 9 : 6
+ System.out.println(sumInvoker1);
+ System.out.println(sumInvoker2);
+ System.out.println(sumInvoker3);
Review Comment:
Print is useless in unit test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1009968926
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
Review Comment:
```suggestion
@Activate(group = CONSUMER, order = -200000, value = {"loadbalance:adaptive"})
```
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener , ScopeModelAware {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel) {
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private ThreadPoolExecutor getExecutor(){
+ if (null == executor) {
+ synchronized (this) {
+ if (null == executor) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
+ GlobalResourcesRepository.getInstance().registerDisposable(() -> this.executor.shutdown());
+ }
+ }
+ }
+ return executor;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
Review Comment:
move to constructor
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener , ScopeModelAware {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel) {
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
Review Comment:
move to constructor
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener , ScopeModelAware {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel) {
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private ThreadPoolExecutor getExecutor(){
+ if (null == executor) {
+ synchronized (this) {
+ if (null == executor) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
+ GlobalResourcesRepository.getInstance().registerDisposable(() -> this.executor.shutdown());
+ }
+ }
+ }
+ return executor;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ return invoker.invoke(invocation);
+ }
+
+ private String buildServiceKey(Invocation invocation){
+ return invocation.getInvoker().getUrl().getAddress() + ":" + invocation.getProtocolServiceKey();
+ //return url.getAddress() + ProtocolUtils.serviceKey(url.getPort(), url.getPath(), url.getVersion(), url.getGroup());
+ }
+
+ @Override
+ public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
+
+ try {
+ if (StringUtils.isNotEmpty(invoker.getUrl().getParameter(LOADBALANCE_KEY))
+ && AdaptiveLoadBalance.NAME.equals(invoker.getUrl().getParameter(LOADBALANCE_KEY))) {
+ getAdaptiveMetricsInstance().addConsumerSuccess(buildServiceKey(invocation));
+ }
+ String attachment = appResponse.getAttachment(Constants.ADAPTIVE_LOADBALANCE_ATTACHMENT_KEY);
+ if (StringUtils.isNotEmpty(attachment)) {
+ String[] parties = COMMA_SPLIT_PATTERN.split(attachment);
+ if (parties.length == 0) {
+ return;
+ }
+ Map<String, String> metricsMap = new HashMap<>();
+ for (String party : parties) {
+ String[] groups = party.split(":");
+ if (groups.length != 2) {
+ continue;
+ }
+ metricsMap.put(groups[0], groups[1]);
+ }
+ ProfilerEntry profilerEntry = (ProfilerEntry) invocation.getAttributes().get(Profiler.PROFILER_KEY);
Review Comment:
handle NPE if `profilerEntry` is null
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
Review Comment:
use `ScopeBeanInitializer`
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener , ScopeModelAware {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel) {
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private ThreadPoolExecutor getExecutor(){
+ if (null == executor) {
+ synchronized (this) {
+ if (null == executor) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
+ GlobalResourcesRepository.getInstance().registerDisposable(() -> this.executor.shutdown());
+ }
+ }
+ }
+ return executor;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+ return invoker.invoke(invocation);
+ }
+
+ private String buildServiceKey(Invocation invocation){
+ return invocation.getInvoker().getUrl().getAddress() + ":" + invocation.getProtocolServiceKey();
Review Comment:
replace to StringBuilder and set initial size to improve performance
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
+ Invoker invoker = selectByP2C(invokers,url,invocation);
+ invocation.setAttachment(Constants.ADAPTIVE_LOADBALANCE_ATTACHMENT_KEY,attachmentKey);
Review Comment:
use `attribute` would better?
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
+ Invoker invoker = selectByP2C(invokers,url,invocation);
+ invocation.setAttachment(Constants.ADAPTIVE_LOADBALANCE_ATTACHMENT_KEY,attachmentKey);
+ getAdaptiveMetricsInstance().addConsumerReq(buildServiceKey(invoker,invocation));
+ getAdaptiveMetricsInstance().setPickTime(buildServiceKey(invoker,invocation),System.currentTimeMillis());
+
+ return invoker;
+ }
+
+ private <T> Invoker<T> selectByP2C(List<Invoker<T>> invokers, URL url, Invocation invocation){
+ int length = invokers.size();
+ if(length == 1) {
+ return invokers.get(0);
+ }
+
+ if(length == 2) {
+ return chooseLowLoadInvoker(invokers.get(0),invokers.get(1),invocation);
+ }
+
+ int pos1 = ThreadLocalRandom.current().nextInt(length);
+ int pos2 = ThreadLocalRandom.current().nextInt(length);
+ while(pos1 == pos2) {
+ pos2 = ThreadLocalRandom.current().nextInt(length);
+ }
+
+ return chooseLowLoadInvoker(invokers.get(pos1),invokers.get(pos2),invocation);
+ }
+
+ private String buildServiceKey(Invoker<?> invoker,Invocation invocation){
+ URL url = invoker.getUrl();
+ return url.getAddress() + ":" + invocation.getProtocolServiceKey();
+ }
+
+ private int getTimeout(Invoker<?> invoker, Invocation invocation) {
+ URL url = invoker.getUrl();
+ Object countdown = RpcContext.getClientAttachment().getObjectAttachment(TIME_COUNTDOWN_KEY);
+ int timeout;
+ if (countdown == null) {
+ timeout = (int) RpcUtils.getTimeout(url, invocation.getMethodName(), RpcContext.getClientAttachment(), DEFAULT_TIMEOUT);
+ } else {
+ TimeoutCountDown timeoutCountDown = (TimeoutCountDown) countdown;
+ timeout = (int) timeoutCountDown.timeRemaining(TimeUnit.MILLISECONDS);
+ }
+ return timeout;
Review Comment:
why read current invocation's timeout?
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
+ Invoker invoker = selectByP2C(invokers,url,invocation);
+ invocation.setAttachment(Constants.ADAPTIVE_LOADBALANCE_ATTACHMENT_KEY,attachmentKey);
+ getAdaptiveMetricsInstance().addConsumerReq(buildServiceKey(invoker,invocation));
+ getAdaptiveMetricsInstance().setPickTime(buildServiceKey(invoker,invocation),System.currentTimeMillis());
+
+ return invoker;
+ }
+
+ private <T> Invoker<T> selectByP2C(List<Invoker<T>> invokers, URL url, Invocation invocation){
+ int length = invokers.size();
+ if(length == 1) {
+ return invokers.get(0);
+ }
+
+ if(length == 2) {
+ return chooseLowLoadInvoker(invokers.get(0),invokers.get(1),invocation);
+ }
+
+ int pos1 = ThreadLocalRandom.current().nextInt(length);
+ int pos2 = ThreadLocalRandom.current().nextInt(length);
+ while(pos1 == pos2) {
+ pos2 = ThreadLocalRandom.current().nextInt(length);
+ }
+
+ return chooseLowLoadInvoker(invokers.get(pos1),invokers.get(pos2),invocation);
+ }
+
+ private String buildServiceKey(Invoker<?> invoker,Invocation invocation){
+ URL url = invoker.getUrl();
+ return url.getAddress() + ":" + invocation.getProtocolServiceKey();
+ }
+
+ private int getTimeout(Invoker<?> invoker, Invocation invocation) {
+ URL url = invoker.getUrl();
+ Object countdown = RpcContext.getClientAttachment().getObjectAttachment(TIME_COUNTDOWN_KEY);
+ int timeout;
+ if (countdown == null) {
+ timeout = (int) RpcUtils.getTimeout(url, invocation.getMethodName(), RpcContext.getClientAttachment(), DEFAULT_TIMEOUT);
+ } else {
+ TimeoutCountDown timeoutCountDown = (TimeoutCountDown) countdown;
+ timeout = (int) timeoutCountDown.timeRemaining(TimeUnit.MILLISECONDS);
+ }
+ return timeout;
+ }
+
+ private <T> Invoker<T> chooseLowLoadInvoker(Invoker<T> invoker1,Invoker<T> invoker2,Invocation invocation){
+ int weight1 = getWeight(invoker1, invocation);
+ int weight2 = getWeight(invoker2, invocation);
+ int timeout1 = getTimeout(invoker2, invocation);
Review Comment:
Are there some spell mistakes?
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener , ScopeModelAware {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel) {
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
Review Comment:
Add into `ScopeBeanInitializer`
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.resource.GlobalResourcesRepository;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener , ScopeModelAware {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel) {
Review Comment:
replace to constructor
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
Review Comment:
move to constructor
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AdaptiveLoadBalance.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.loadbalance;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.TimeoutCountDown;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.ScopeModelAware;
+import org.apache.dubbo.rpc.support.RpcUtils;
+
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
+
+/**
+ * AdaptiveLoadBalance
+ * </p>
+ */
+public class AdaptiveLoadBalance extends AbstractLoadBalance implements ScopeModelAware {
+
+ public static final String NAME = "adaptive";
+
+ //default key
+ private String attachmentKey = "mem,load";
+
+ private final int default_timeout = 30_000;
+
+ private ApplicationModel scopeModel;
+
+ private AdaptiveMetrics adaptiveMetrics;
+
+ @Override
+ public void setApplicationModel(ApplicationModel scopeModel){
+ AdaptiveMetrics bean = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ if (bean == null) {
+ scopeModel.getBeanFactory().registerBean(new AdaptiveMetrics());
+ }
+ this.scopeModel = scopeModel;
+ }
+
+ private AdaptiveMetrics getAdaptiveMetricsInstance(){
+ if (adaptiveMetrics == null) {
+ adaptiveMetrics = scopeModel.getBeanFactory().getBean(AdaptiveMetrics.class);
+ }
+ return adaptiveMetrics;
+ }
+
+ @Override
+ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
+ Invoker invoker = selectByP2C(invokers,url,invocation);
+ invocation.setAttachment(Constants.ADAPTIVE_LOADBALANCE_ATTACHMENT_KEY,attachmentKey);
+ getAdaptiveMetricsInstance().addConsumerReq(buildServiceKey(invoker,invocation));
+ getAdaptiveMetricsInstance().setPickTime(buildServiceKey(invoker,invocation),System.currentTimeMillis());
+
+ return invoker;
+ }
+
+ private <T> Invoker<T> selectByP2C(List<Invoker<T>> invokers, URL url, Invocation invocation){
+ int length = invokers.size();
+ if(length == 1) {
+ return invokers.get(0);
+ }
+
+ if(length == 2) {
+ return chooseLowLoadInvoker(invokers.get(0),invokers.get(1),invocation);
+ }
+
+ int pos1 = ThreadLocalRandom.current().nextInt(length);
+ int pos2 = ThreadLocalRandom.current().nextInt(length);
+ while(pos1 == pos2) {
+ pos2 = ThreadLocalRandom.current().nextInt(length);
+ }
+
+ return chooseLowLoadInvoker(invokers.get(pos1),invokers.get(pos2),invocation);
+ }
+
+ private String buildServiceKey(Invoker<?> invoker,Invocation invocation){
+ URL url = invoker.getUrl();
+ return url.getAddress() + ":" + invocation.getProtocolServiceKey();
+ }
Review Comment:
cache this in invocation attribute
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1002875544
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor;
+
+ public AdaptiveLoadBalanceFilter(ApplicationModel applicationModel) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
Review Comment:
should not create executor by default when user do not use this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] sonarcloud[bot] commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1327199830
SonarCloud Quality Gate failed. [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_dubbo&pullRequest=10745)
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [![E](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/E-16px.png 'E')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [2 Bugs](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG)
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY)
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [![E](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/E-16px.png 'E')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [4 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT)
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [25 Code Smells](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL)
[![28.8%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/25-16px.png '28.8%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list) [28.8% Coverage](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list)
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] sonarcloud[bot] commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1328448243
SonarCloud Quality Gate failed. [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_dubbo&pullRequest=10745)
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [![B](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/B-16px.png 'B')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [1 Bug](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG)
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY)
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [![E](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/E-16px.png 'E')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [4 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT)
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL)
[![28.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/25-16px.png '28.4%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list) [28.4% Coverage](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list)
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1003964462
##########
dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AdaptiveMetrics.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc;
+
+import org.apache.dubbo.common.utils.StringUtils;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * adaptive Metrics statistics.
+ */
+public class AdaptiveMetrics {
+
+ private static final ConcurrentMap<String, AdaptiveMetrics> METRICS_STATISTICS = new ConcurrentHashMap<String,
Review Comment:
Should not use static field to store status in Dubbo. Use scope bean instead
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.AdaptiveMetrics;
+import org.apache.dubbo.rpc.Constants;
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see org.apache.dubbo.rpc.Filter
+ * @see org.apache.dubbo.rpc.RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private ThreadPoolExecutor executor = null;
+
+ private ThreadPoolExecutor getExecutor(){
+ if (null == executor) {
+ synchronized (this) {
+ if (null == executor) {
+ executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
+ new NamedInternalThreadFactory("Dubbo-framework-loadbalance-adaptive", true), new ThreadPoolExecutor.DiscardOldestPolicy());
Review Comment:
Register to `org.apache.dubbo.common.resource.GlobalResourcesRepository#registerDisposable`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] sonarcloud[bot] commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1347910176
SonarCloud Quality Gate failed. [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_dubbo&pullRequest=10745)
[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [![B](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/B-16px.png 'B')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG) [1 Bug](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=BUG)
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=VULNERABILITY)
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo&pullRequest=10745&resolved=false&types=SECURITY_HOTSPOT)
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL) [3 Code Smells](https://sonarcloud.io/project/issues?id=apache_dubbo&pullRequest=10745&resolved=false&types=CODE_SMELL)
[![28.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/25-16px.png '28.4%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list) [28.4% Coverage](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_coverage&view=list)
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_dubbo&pullRequest=10745&metric=new_duplicated_lines_density&view=list)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] codecov-commenter commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1327203957
# [Codecov](https://codecov.io/gh/apache/dubbo/pull/10745?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#10745](https://codecov.io/gh/apache/dubbo/pull/10745?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5ea3d84) into [3.2](https://codecov.io/gh/apache/dubbo/commit/da95c62d80ffedeb651ba2fda2362facae7cf9a7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (da95c62) will **decrease** coverage by `0.07%`.
> The diff coverage is `58.22%`.
```diff
@@ Coverage Diff @@
## 3.2 #10745 +/- ##
============================================
- Coverage 64.89% 64.81% -0.08%
Complexity 14 14
============================================
Files 1443 1446 +3
Lines 59907 60065 +158
Branches 8776 8800 +24
============================================
+ Hits 38875 38932 +57
- Misses 16932 17018 +86
- Partials 4100 4115 +15
```
| [Impacted Files](https://codecov.io/gh/apache/dubbo/pull/10745?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ster/filter/support/AdaptiveLoadBalanceFilter.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvZmlsdGVyL3N1cHBvcnQvQWRhcHRpdmVMb2FkQmFsYW5jZUZpbHRlci5qYXZh) | `0.00% <0.00%> (ø)` | |
| [.../apache/dubbo/rpc/filter/ProfilerServerFilter.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9maWx0ZXIvUHJvZmlsZXJTZXJ2ZXJGaWx0ZXIuamF2YQ==) | `55.55% <33.33%> (-5.56%)` | :arrow_down: |
| [...o/rpc/cluster/loadbalance/AdaptiveLoadBalance.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvbG9hZGJhbGFuY2UvQWRhcHRpdmVMb2FkQmFsYW5jZS5qYXZh) | `88.00% <88.00%> (ø)` | |
| [...ain/java/org/apache/dubbo/rpc/AdaptiveMetrics.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9BZGFwdGl2ZU1ldHJpY3MuamF2YQ==) | `89.79% <89.79%> (ø)` | |
| [...ubbo/rpc/cluster/ClusterScopeModelInitializer.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvQ2x1c3RlclNjb3BlTW9kZWxJbml0aWFsaXplci5qYXZh) | `100.00% <100.00%> (ø)` | |
| [...gistrycenter/processor/ZookeeperUnixProcessor.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tdGVzdC9kdWJiby10ZXN0LWNoZWNrL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby90ZXN0L2NoZWNrL3JlZ2lzdHJ5Y2VudGVyL3Byb2Nlc3Nvci9ab29rZWVwZXJVbml4UHJvY2Vzc29yLmphdmE=) | `60.71% <0.00%> (-17.86%)` | :arrow_down: |
| [...apache/dubbo/rpc/protocol/dubbo/FutureAdapter.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9wcm90b2NvbC9kdWJiby9GdXR1cmVBZGFwdGVyLmphdmE=) | `36.00% <0.00%> (-12.00%)` | :arrow_down: |
| [...o/remoting/exchange/support/ReplierDispatcher.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcmVtb3RpbmcvZHViYm8tcmVtb3RpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZW1vdGluZy9leGNoYW5nZS9zdXBwb3J0L1JlcGxpZXJEaXNwYXRjaGVyLmphdmE=) | `72.72% <0.00%> (-9.10%)` | :arrow_down: |
| [...e/dubbo/remoting/transport/netty/NettyChannel.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tcmVtb3RpbmcvZHViYm8tcmVtb3RpbmctbmV0dHkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JlbW90aW5nL3RyYW5zcG9ydC9uZXR0eS9OZXR0eUNoYW5uZWwuamF2YQ==) | `51.13% <0.00%> (-7.96%)` | :arrow_down: |
| [...mmon/threadpool/support/AbortPolicyWithReport.java](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vdGhyZWFkcG9vbC9zdXBwb3J0L0Fib3J0UG9saWN5V2l0aFJlcG9ydC5qYXZh) | `72.72% <0.00%> (-7.58%)` | :arrow_down: |
| ... and [31 more](https://codecov.io/gh/apache/dubbo/pull/10745/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on code in PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#discussion_r1000084782
##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/AdaptiveLoadBalanceFilter.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.cluster.filter.support;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.profiler.Profiler;
+import org.apache.dubbo.common.profiler.ProfilerEntry;
+import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.rpc.*;
+import org.apache.dubbo.rpc.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.cluster.loadbalance.AdaptiveLoadBalance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.dubbo.common.constants.CommonConstants.*;
+
+/**
+ * if the load balance is adaptive ,set attachment to get the metrics of the server
+ * @see Filter
+ * @see RpcContext
+ */
+@Activate(group = CONSUMER, order = -200000)
+public class AdaptiveLoadBalanceFilter implements ClusterFilter, ClusterFilter.Listener {
+
+ /**
+ * uses a single worker thread operating off an bounded queue
+ */
+ private static final ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L,TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024),
Review Comment:
should be lazy init or use dubbo shared executor
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] ningboliu commented on pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
ningboliu commented on PR #10745:
URL: https://github.com/apache/dubbo/pull/10745#issuecomment-1287040866
三轮基准测试结果
![image](https://user-images.githubusercontent.com/30331180/197219140-5225fd67-767d-4396-a215-a943f8654360.png)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ merged pull request #10745: Adaptive loadbalance
Posted by GitBox <gi...@apache.org>.
AlbumenJ merged PR #10745:
URL: https://github.com/apache/dubbo/pull/10745
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org