Search in sources :

Example 1 with TrackerClientImpl

use of com.linkedin.d2.balancer.clients.TrackerClientImpl in project rest.li by linkedin.

the class LoadBalancerStrategyBenchmark method createTrackerClients.

private static Map<URI, TrackerClient> createTrackerClients(int numHosts) {
    Map<URI, TrackerClient> trackerClients = new HashMap<>();
    for (int i = 0; i < numHosts; i++) {
        URI uri = URI.create(URI_PREFIX + i + URI_SUFFIX);
        trackerClients.put(uri, new TrackerClientImpl(uri, DEFAULT_PARTITION_DATA_MAP, new BaseTransportTestClient(), CLOCK, RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS, (status) -> status >= 500 && status <= 599));
    }
    return trackerClients;
}
Also used : Arrays(java.util.Arrays) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) Measurement(org.openjdk.jmh.annotations.Measurement) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) HashMap(java.util.HashMap) Scope(org.openjdk.jmh.annotations.Scope) Warmup(org.openjdk.jmh.annotations.Warmup) ArrayList(java.util.ArrayList) URIRequest(com.linkedin.d2.balancer.util.URIRequest) Request(com.linkedin.r2.message.Request) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SystemClock(com.linkedin.util.clock.SystemClock) URI(java.net.URI) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) RestRequest(com.linkedin.r2.message.rest.RestRequest) Setup(org.openjdk.jmh.annotations.Setup) Mode(org.openjdk.jmh.annotations.Mode) Clock(com.linkedin.util.clock.Clock) DegraderLoadBalancerStrategyV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyV3) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) State(org.openjdk.jmh.annotations.State) Executors(java.util.concurrent.Executors) Benchmark(org.openjdk.jmh.annotations.Benchmark) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RequestContext(com.linkedin.r2.message.RequestContext) RelativeStrategyPropertiesConverter(com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter) Level(org.openjdk.jmh.annotations.Level) Fork(org.openjdk.jmh.annotations.Fork) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) HashMap(java.util.HashMap) URI(java.net.URI) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl)

Example 2 with TrackerClientImpl

use of com.linkedin.d2.balancer.clients.TrackerClientImpl in project rest.li by linkedin.

the class LoadBalancerStrategyTestRunnerBuilder method buildRelativeStrategy.

private LoadBalancerStrategyTestRunner buildRelativeStrategy() {
    if (_serviceProperties == null) {
        setRelativeLoadBalancerStrategies(new D2RelativeStrategyProperties());
    }
    _strategy = new RelativeLoadBalancerStrategyFactory(_clockedExecutor, null, new ArrayList<>(), null, _clockedExecutor).newLoadBalancer(_serviceProperties);
    _transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
    Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
        // If partition map is not specified, by default we only support one partition
        Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
        return new TrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, INTERVAL_IN_MILLIS, (status) -> status >= 500 && status <= 599);
    }).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
    return buildInternal(trackerClientMap);
}
Also used : Arrays(java.util.Arrays) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) Callback(com.linkedin.common.callback.Callback) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) HashMap(java.util.HashMap) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) Map(java.util.Map) DegraderConfigFactory(com.linkedin.d2.balancer.strategies.degrader.DegraderConfigFactory) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) URI(java.net.URI) HttpStatus(org.eclipse.jetty.http.HttpStatus) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) RestException(com.linkedin.r2.message.rest.RestException) RestRequest(com.linkedin.r2.message.rest.RestRequest) com.linkedin.d2.loadBalancerStrategyType(com.linkedin.d2.loadBalancerStrategyType) Set(java.util.Set) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) PropertyKeys(com.linkedin.d2.balancer.properties.PropertyKeys) Collectors(java.util.stream.Collectors) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TransportResponseImpl(com.linkedin.r2.transport.common.bridge.common.TransportResponseImpl) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) RelativeStrategyPropertiesConverter(com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) RelativeLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) DegraderTrackerClientImpl(com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl) TrackerClientImpl(com.linkedin.d2.balancer.clients.TrackerClientImpl) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties)

Aggregations

D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)2 DegraderTrackerClientImpl (com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl)2 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)2 TrackerClientImpl (com.linkedin.d2.balancer.clients.TrackerClientImpl)2 RelativeStrategyPropertiesConverter (com.linkedin.d2.balancer.config.RelativeStrategyPropertiesConverter)2 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)2 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)2 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)2 RelativeLoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategyFactory)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2 Callback (com.linkedin.common.callback.Callback)1 None (com.linkedin.common.util.None)1