@Override
    protected ServiceInstance doChoose(String serviceName, List<ServiceInstance> instances) {
        final ServiceStats serviceStats = ServiceStatsManager.INSTANCE.getServiceStats(serviceName);
        List<Double> responseTimeWeights = calculateResponseTimeWeight(serviceStats, instances);
        double maxWeights = responseTimeWeights.get(responseTimeWeights.size() - 1);
        if (maxWeights <= DOUBLE_GAP) {
            // At this time, the response time has not yet been counted, and a round-robin call is used
            return defaultLb.doChoose(serviceName, instances);
        }
        final double seed = ThreadLocalRandom.current().nextDouble(maxWeights);
        ServiceInstance result = null;
        for (int i = 0, size = responseTimeWeights.size(); i < size; i++) {
            if (seed <= responseTimeWeights.get(i)) {
                result = instances.get(i);
                break;
            }
        }
        if (result == null) {
            return defaultLb.doChoose(serviceName, instances);
        }
        return result;
    }
@Test
    public void doChoose() {
        final WeightedResponseTimeLoadbalancer weightedResponseTimeLoadbalancer =
                new WeightedResponseTimeLoadbalancer();
        int port1 = 9999;
        int port2 = 8888;
        String serviceName = "lb";
        final ServiceInstance serviceInstance1 = CommonUtils.buildInstance(serviceName, port1);
        final ServiceInstance serviceInstance2 = CommonUtils.buildInstance(serviceName, port2);
        final ServiceStats serviceStats = ServiceStatsManager.INSTANCE.getServiceStats(serviceName);
        final InstanceStats stats1 = serviceStats.getStats(serviceInstance1);
        for (int i =0; i < 10; i ++) {
            // The first instance of the simulation has a long response time
            stats1.beforeRequest();
            stats1.afterRequest(1000L);
        }
        final List<ServiceInstance> serviceInstances = Arrays.asList(serviceInstance1, serviceInstance2);
        // Simulate 100 requests, and instances with low concurrency will be more likely to be selected
        int count1 = 0, count2 = 0;
        for (int i = 0; i < 100; i++) {
            final Optional<ServiceInstance> choose = weightedResponseTimeLoadbalancer
                    .choose(serviceName, serviceInstances);
            Assert.assertTrue(choose.isPresent());
            if (choose.get().getPort() == port1) {
                count1++;
            } else {
                count2++;
            }
        }
        Assert.assertTrue(count1 < count2);
    }