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 2021/09/16 10:29:26 UTC

[GitHub] [dubbo] startjava opened a new issue #8826: 如何写DEMO能看到LeastActive运行的效果

startjava opened a new issue #8826:
URL: https://github.com/apache/dubbo/issues/8826


   如何写DEMO能看到LeastActive运行的效果


-- 
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] 24kpure commented on issue #8826: 如何写DEMO能看到LeastActive运行的效果

Posted by GitBox <gi...@apache.org>.
24kpure commented on issue #8826:
URL: https://github.com/apache/dubbo/issues/8826#issuecomment-922251552


   Any load balancer that uses the active parameter needs to be configured in consumer.
   ```
   @DubboReference(loadbalance = LoadbalanceRules.LEAST_ACTIVE, timeout = 6000000, filter = "activelimit", active=100)
   private IService3 service3;
   ```
   


-- 
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] startjava edited a comment on issue #8826: 如何写DEMO能看到LeastActive运行的效果

Posted by GitBox <gi...@apache.org>.
startjava edited a comment on issue #8826:
URL: https://github.com/apache/dubbo/issues/8826#issuecomment-920934465


   我的提供者代码:
   ```
   package com.ghy.www.my.loadbalance.provider.service;
   
   import com.ghy.www.api.IService3;
   import org.springframework.beans.factory.annotation.Value;
   
   public class HelloService3 implements IService3 {
       @Value("${server.port}")
       private int portValue;
   
       @Override
       public String getHello(String username) {
           System.out.println("HelloService3 portValue=" + portValue + " username=" + username);
           if (portValue == 8085) {
               try {
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           if (portValue == 8086) {
               try {
                   Thread.sleep(200);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           if (portValue == 8087) {
               try {
                   Thread.sleep(10);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           return "hello3 " + username + " port=" + portValue;
       }
   }
   ```
   
   消费者引用代码:
   ```
       @DubboReference(loadbalance = LoadbalanceRules.LEAST_ACTIVE, timeout = 6000000, filter = "activelimit")
       private IService3 service3;
   ```
   
   消费者调用代码:
   ```
   private int test3_provider1_runtime = 0;
       private int test3_provider2_runtime = 0;
       private int test3_provider3_runtime = 0;
   
       class MyThread1 extends Thread {
           private int i;
           private CountDownLatch latch;
   
           public MyThread1(int i, CountDownLatch latch) {
               this.i = i;
               this.latch = latch;
           }
   
           @Override
           public void run() {
               String helloString = service3.getHello("中国人" + (i + 1));
               System.out.println("public String test3() " + helloString);
               int runPort = Integer.parseInt(helloString.substring(helloString.length() - 4, helloString.length()));
               System.out.println(runPort + " " + (i + 1) + "次运行");
               switch (runPort) {
                   case 8085:
                       test3_provider1_runtime++;
                       break;
                   case 8086:
                       test3_provider2_runtime++;
                       break;
                   case 8087:
                       test3_provider3_runtime++;
                       break;
               }
               latch.countDown();
           }
       }
   
       @RequestMapping("Test3")
       public void test3(HttpServletRequest request, HttpServletResponse response) {
           CountDownLatch latch = new CountDownLatch(10000);
           for (int i = 0; i < 10000; i++) {
               MyThread1 t = new MyThread1(i, latch);
               t.start();
           }
           try {
               latch.await();
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           System.out.println("test3_provider1_runtime=" + test3_provider1_runtime);
           System.out.println("test3_provider2_runtime=" + test3_provider2_runtime);
           System.out.println("test3_provider3_runtime=" + test3_provider3_runtime);
           test3_provider1_runtime=0;
           test3_provider2_runtime=0;
           test3_provider3_runtime=0;
       }
   
   ```
   得出结果:
   ```
   test3_provider1_runtime=2852
   test3_provider2_runtime=3541
   test3_provider3_runtime=3606
   ```
   
   我不知道这个结果是不是LeastActive运行的效果。感谢
   
   我总感觉这个结果不对劲,8085端口运行的最慢,为什么还有2852次运行呢?好像不太符合常理
   


-- 
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] startjava commented on issue #8826: 如何写DEMO能看到LeastActive运行的效果

Posted by GitBox <gi...@apache.org>.
startjava commented on issue #8826:
URL: https://github.com/apache/dubbo/issues/8826#issuecomment-920946765


   当我加大提供者的sleep时间时:
   package com.ghy.www.my.loadbalance.provider.service;
   
   import com.ghy.www.api.IService3;
   import org.springframework.beans.factory.annotation.Value;
   
   public class HelloService3 implements IService3 {
       @Value("${server.port}")
       private int portValue;
   
       @Override
       public String getHello(String username) {
           System.out.println("HelloService3 portValue=" + portValue + " username=" + username);
           if (portValue == 8085) {
               try {
                   Thread.sleep(800);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           if (portValue == 8086) {
               try {
                   Thread.sleep(700);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           if (portValue == 8087) {
               try {
                   Thread.sleep(10);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           return "hello3 " + username + " port=" + portValue;
       }
   }
   
   执行消费者后,提供者出现警告:
   Thread pool is EXHAUSTED! Thread Name: DubboServerHandler-192.168.30.188:20882, Pool Size: 200 (active: 200, core: 200, max: 200, largest: 200), Task: 991 (completed: 791), Executor status:(isShutdown:false, isTerminated:false, isTerminating:false), in dubbo://192.168.30.188:20882!, dubbo version: 3.0.3-SNAPSHOT, current host: 192.168.191.1
   
   这个实验不管我如何测,都测不出理想中的效果(由于8085最慢,所以请求到8085的请求是“超级”少的)。


-- 
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] startjava commented on issue #8826: 如何写DEMO能看到LeastActive运行的效果

Posted by GitBox <gi...@apache.org>.
startjava commented on issue #8826:
URL: https://github.com/apache/dubbo/issues/8826#issuecomment-920934465


   我的提供者代码:
   package com.ghy.www.my.loadbalance.provider.service;
   
   import com.ghy.www.api.IService3;
   import org.springframework.beans.factory.annotation.Value;
   
   public class HelloService3 implements IService3 {
       @Value("${server.port}")
       private int portValue;
   
       @Override
       public String getHello(String username) {
           System.out.println("HelloService3 portValue=" + portValue + " username=" + username);
           if (portValue == 8085) {
               try {
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           if (portValue == 8086) {
               try {
                   Thread.sleep(200);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           if (portValue == 8087) {
               try {
                   Thread.sleep(10);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
           return "hello3 " + username + " port=" + portValue;
       }
   }
   
   消费者引用代码:
       @DubboReference(loadbalance = LoadbalanceRules.LEAST_ACTIVE, timeout = 6000000, filter = "activelimit")
       private IService3 service3;
   
   消费者调用代码:
   private int test3_provider1_runtime = 0;
       private int test3_provider2_runtime = 0;
       private int test3_provider3_runtime = 0;
   
       class MyThread1 extends Thread {
           private int i;
           private CountDownLatch latch;
   
           public MyThread1(int i, CountDownLatch latch) {
               this.i = i;
               this.latch = latch;
           }
   
           @Override
           public void run() {
               String helloString = service3.getHello("中国人" + (i + 1));
               System.out.println("public String test3() " + helloString);
               int runPort = Integer.parseInt(helloString.substring(helloString.length() - 4, helloString.length()));
               System.out.println(runPort + " " + (i + 1) + "次运行");
               switch (runPort) {
                   case 8085:
                       test3_provider1_runtime++;
                       break;
                   case 8086:
                       test3_provider2_runtime++;
                       break;
                   case 8087:
                       test3_provider3_runtime++;
                       break;
               }
               latch.countDown();
           }
       }
   
       @RequestMapping("Test3")
       public void test3(HttpServletRequest request, HttpServletResponse response) {
           CountDownLatch latch = new CountDownLatch(10000);
           for (int i = 0; i < 10000; i++) {
               MyThread1 t = new MyThread1(i, latch);
               t.start();
           }
           try {
               latch.await();
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           System.out.println("test3_provider1_runtime=" + test3_provider1_runtime);
           System.out.println("test3_provider2_runtime=" + test3_provider2_runtime);
           System.out.println("test3_provider3_runtime=" + test3_provider3_runtime);
           test3_provider1_runtime=0;
           test3_provider2_runtime=0;
           test3_provider3_runtime=0;
       }
   
   得出结果:
   test3_provider1_runtime=2852
   test3_provider2_runtime=3541
   test3_provider3_runtime=3606
   
   我不知道这个结果是不是LeastActive运行的效果。感谢
   


-- 
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