Package com.linkedin.d2.balancer.clients

Examples of com.linkedin.d2.balancer.clients.TrackerClient


    assertNull(_state.getClient("service-1", uri));

    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));

    TrackerClient client = _state.getClient("service-1", uri);

    assertNotNull(client);
    assertEquals(client.getUri(), uri);

    //now we publish an event that tells service-1 changes cluster. Now it's hosted in cluster-2
    _serviceRegistry.put("service-1", new ServiceProperties("service-1", "cluster-2",
                                                            "/test", "random", null,
                                                            Collections.<String, Object>emptyMap(),
                                                             null, null, schemes, null));

    //this time, since we haven't listened to cluster-2 and there's no uri in cluster-2, we get no client.
    assertNull(_state.getClient("service-1", uri));

    //we shouldn't be affected by any update to cluster-1 uris because now service-1 listen to cluster-2
    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));
    assertNull(_state.getClient("service-1", uri));

    //now let's create URI for cluster 2 and make the state listen to cluster_2
    _state.listenToCluster("cluster-2", new NullStateListenerCallback());

    URI uri2 = URI.create("http://cluster-2/test");
    Map<Integer, PartitionData> partitionData2 = new HashMap<Integer, PartitionData>(1);
    partitionData2.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    Map<URI, Map<Integer, PartitionData>> uriData2 = new HashMap<URI, Map<Integer, PartitionData>>();
    uriData2.put(uri2, partitionData2);

    //if we start publishing new event to cluster-2 then we should get trackerClient
    _uriRegistry.put("cluster-2", new UriProperties("cluster-2", uriData2));

    client = _state.getClient("service-1", uri2);

    assertNotNull(client);
    assertEquals(client.getUri(), uri2);

    //just to make sure that any event from cluster-1 doesn't affect us anymore
    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));
    client = _state.getClient("service-1", uri2);

    assertNotNull(client);
    assertEquals(client.getUri(), uri2);

    //if we pass uri from cluster-1, we also get no tracker client
    client = _state.getClient("service-1", uri);

    assertNull(client);
View Full Code Here


        null, null, schemes, null));

    // first we announce uri with empty partition data map
    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));

    TrackerClient client = _state.getClient("service-1", uri);

    assertNotNull(client);
    assertEquals(client.getUri(), uri);
    // tracker client should see empty partition data map
    assertTrue(client.getParttitionDataMap().isEmpty());

    // then we update this uri to have a non-empty partition data map
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));

    TrackerClient updatedClient = _state.getClient("service-1", uri);

    assertNotNull(updatedClient);
    // should have got a different tracker client
    assertNotSame(client, updatedClient);
    assertEquals(updatedClient.getUri(), uri);
    // this updated client should have updated partition data map
    assertFalse(updatedClient.getParttitionDataMap().isEmpty());
    assertEquals(updatedClient.getParttitionDataMap(), partitionDataMap);

  }
View Full Code Here

    else
    {
      debug(_log, "Degrader honoring target host header in request, skipping hashing.  URI: " + targetHostUri.toString());
    }

    TrackerClient client = null;

    if (targetHostUri != null)
    {
      // These are the clients that were passed in, NOT necessarily the clients that make up the
      // consistent hash ring! Therefore, this linear scan is the best we can do.
      for (TrackerClient trackerClient : trackerClients)
      {
        if (trackerClient.getUri().equals(targetHostUri))
        {
          client = trackerClient;
          break;
        }
      }

      if (client == null)
      {
        warn(_log, "No client found for " + targetHostUri + (hostHeaderUri == null ?
                ", degrader load balancer state is inconsistent with cluster manager" :
                ", target host specified is no longer part of cluster"));
      }
    }
    else
    {
      warn(_log, "unable to find a URI to use");
    }

    boolean dropCall = client == null;

    if (!dropCall)
    {
      dropCall = client.getDegrader(DEFAULT_PARTITION_ID).checkDrop();

      if (dropCall)
      {
        warn(_log, "client's degrader is dropping call for: ", client);
      }
View Full Code Here

          // if config is correct, only one thread would fail because broken client throws exception only once util next reset,
          // and state update would succeed
          // if config is broken, every thread would fail and state update would be unsuccessful
          try
          {
            TrackerClient resultTC = getTrackerClient(strategyAdapter, null, new RequestContext(), 1, clients);
            if (trackerClientMustNotBeNull && resultTC == null)
            {
              throw new RuntimeException("Failed the test because resultTC returns null");
            }
          }
View Full Code Here

    clients.add(getClient(uri2, new TestClock()));

    // since cluster call count is 0, we will default to random
    for (int i = 0; i < 1000; ++i)
    {
      TrackerClient client = getTrackerClient(strategy, null, new RequestContext(), 0, clients);

      assertNotNull(client);
      assertTrue(clients.contains(client));
    }
  }
View Full Code Here

    DegraderLoadBalancerStrategyV3 strategy = getStrategy();
    List<TrackerClient> clients = new ArrayList<TrackerClient>();
    URI uri1 = URI.create("http://test.linkedin.com:3242/fdsaf");
    Map<Integer, PartitionData> weightMap = new HashMap<Integer, PartitionData>();
    weightMap.put(0, new PartitionData(1d));
    TrackerClient client = new TrackerClient(uri1,
        weightMap,
        new TestLoadBalancerClient(uri1),
        new TestClock(), null);

    clients.add(client);
View Full Code Here

    List<TrackerClient> clients = new ArrayList<TrackerClient>();
    URI uri1 = URI.create("http://test.linkedin.com:3242/fdsaf");
    URI uri2 = URI.create("http://test.linkedin.com:3243/fdsaf");
    TestClock clock1 = new TestClock();
    TestClock clock2 = new TestClock();
    TrackerClient client1 = getClient(uri1, clock1);
    TrackerClient client2 = getClient(uri2, clock2);

    clients.add(client1);
    clients.add(client2);

    // force client2 to be disabled
    DegraderControl dcClient2Default = client2.getDegraderControl(DEFAULT_PARTITION_ID);
    dcClient2Default.setMinCallCount(1);
    dcClient2Default.setOverrideMinCallCount(1);
    dcClient2Default.setMaxDropRate(1d);
    dcClient2Default.setUpStep(1d);
    dcClient2Default.setHighErrorRate(0);
    CallCompletion cc = client2.getCallTracker().startCall();
    clock2.addMs(10000);
    cc.endCallWithError();

    clock1.addMs(15000);
    clock2.addMs(5000);

    System.err.println(dcClient2Default.getCurrentComputedDropRate());
    System.err.println(dcClient2Default.getCurrentComputedDropRate());

    // now verify that we only get client1
    for (int i = 0; i < 1000; ++i)
    {
      assertEquals(getTrackerClient(strategy, null, new RequestContext(), 0, clients), client1);
    }

    // now force client1 to be disabled
    DegraderControl dcClient1Default = client1.getDegraderControl(DEFAULT_PARTITION_ID);
    dcClient1Default.setMinCallCount(1);
    dcClient1Default.setOverrideMinCallCount(1);
    dcClient1Default.setMaxDropRate(1d);
    dcClient1Default.setUpStep(1d);
    dcClient1Default.setHighErrorRate(0);
    cc = client1.getCallTracker().startCall();
    clock1.addMs(10000);
    cc.endCallWithError();

    clock1.addMs(5000);

    // now verify that we never get a client back
    for (int i = 0; i < 1000; ++i)
    {
      assertNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients));
    }

    // now enable client1 and client2
    clock1.addMs(15000);
    clock2.addMs(15000);
    client1.getCallTracker().startCall().endCall();
    client2.getCallTracker().startCall().endCall();
    clock1.addMs(5000);
    clock2.addMs(5000);

    // now verify that we get client 1 or 2
    for (int i = 0; i < 1000; ++i)
View Full Code Here

    List<TrackerClient> clients = new ArrayList<TrackerClient>();
    URI uri1 = URI.create("http://test.linkedin.com:3242/fdsaf");
    URI uri2 = URI.create("http://test.linkedin.com:3243/fdsaf");
    TestClock clock1 = new TestClock();
    TestClock clock2 = new TestClock();
    TrackerClient client1 =
        new TrackerClient(uri1, getDefaultPartitionData(1d), new TestLoadBalancerClient(uri1), clock1, null);
    TrackerClient client2 =
        new TrackerClient(uri2, getDefaultPartitionData(0.8d), new TestLoadBalancerClient(uri2), clock2, null);

    clients.add(client1);
    clients.add(client2);

    System.err.println(client2.getDegraderControl(DEFAULT_PARTITION_ID).getCurrentComputedDropRate());
    System.err.println(client1.getDegraderControl(DEFAULT_PARTITION_ID).getCurrentComputedDropRate());

    // trigger a state update
    assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients));

    // now verify that the ring has degraded client 2 by 20%
    ConsistentHashRing<URI> ring =
        (ConsistentHashRing<URI>) strategy.getState().getPartitionState(DEFAULT_PARTITION_ID).getRing();

    Map<URI, AtomicInteger> count = new HashMap<URI, AtomicInteger>();

    count.put(uri1, new AtomicInteger(0));
    count.put(uri2, new AtomicInteger(0));

    for (Point<URI> point : ring.getPoints())
    {
      count.get(point.getT()).incrementAndGet();
    }

    // .8 weight should degrade the weight of client2 by 20%
    assertEquals(count.get(uri1).get(), 100);
    assertEquals(count.get(uri2).get(), 80);

    // now do a basic verification to verify getTrackerClient is properly weighting things
    double calls = 10000d;
    int client1Count = 0;
    int client2Count = 0;
    double tolerance = 0.05d;

    for (int i = 0; i < calls; ++i)
    {
      TrackerClient client = getTrackerClient(strategy, null, new RequestContext(), 1, clients);

      assertNotNull(client);

      if (client.getUri().equals(uri1))
      {
        ++client1Count;
      }
      else
      {
View Full Code Here

    List<TrackerClient> clients = new ArrayList<TrackerClient>();
    URI uri1 = URI.create("http://someTestService/someTestUrl");
    URI uri2 = URI.create("http://abcxfweuoeueoueoueoukeueoueoueoueoueouo/2354");
    TestClock clock1 = new TestClock();
    TestClock clock2 = new TestClock();
    TrackerClient client1 = getClient(uri1, clock1);
    TrackerClient client2 = getClient(uri2, clock2);

    clients.add(client1);
    clients.add(client2);

    // force client2 to be disabled
    DegraderControl dcClient2Default = client2.getDegraderControl(DEFAULT_PARTITION_ID);
    dcClient2Default.setOverrideMinCallCount(1);
    dcClient2Default.setMinCallCount(1);
    dcClient2Default.setMaxDropRate(1d);
    dcClient2Default.setUpStep(0.4d);
    dcClient2Default.setHighErrorRate(0);
    CallCompletion cc = client2.getCallTracker().startCall();
    clock2.addMs(1);
    cc.endCallWithError();

    clock1.addMs(15000);
    clock2.addMs(5000);

    System.err.println(dcClient2Default.getCurrentComputedDropRate());
    System.err.println(client1.getDegraderControl(DEFAULT_PARTITION_ID).getCurrentComputedDropRate());

    // trigger a state update
    assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients));

    // now verify that the ring has degraded client 2 by 20%
    ConsistentHashRing<URI> ring =
        (ConsistentHashRing<URI>) strategy.getState().getPartitionState(DEFAULT_PARTITION_ID).getRing();

    Map<URI, AtomicInteger> count = new HashMap<URI, AtomicInteger>();

    count.put(uri1, new AtomicInteger(0));
    count.put(uri2, new AtomicInteger(0));

    for (Point<URI> point : ring.getPoints())
    {
      count.get(point.getT()).incrementAndGet();
    }

    // .4 degradation should degrade the weight of client2 by 40%
    assertEquals(count.get(uri1).get(), 100);
    assertEquals(count.get(uri2).get(), 60);

    // now do a basic verification to verify getTrackerClient is properly weighting things
    double calls = 10000d;
    int client1Count = 0;
    int client2Count = 0;
    double tolerance = 0.05d;

    for (int i = 0; i < calls; ++i)
    {
      TrackerClient client = getTrackerClient(strategy, null, new RequestContext(), 1, clients);

      assertNotNull(client);

      if (client.getUri().equals(uri1))
      {
        ++client1Count;
      }
      else
      {
View Full Code Here

      List<LoadBalancerState.SchemeStrategyPair> orderedStrategies =
              _state.getStrategiesForService(serviceName,
                                             service.getPrioritizedSchemes());

      TrackerClient trackerClient = chooseTrackerClient(request, requestContext, serviceName, clusterName, cluster,
                                                        uriItem, uris, orderedStrategies, service);

      String clusterAndServiceUriString = trackerClient.getUri() + service.getPath();
      client = new RewriteClient(serviceName,
                                               URI.create(clusterAndServiceUriString),
                                               trackerClient);

      _serviceAvailableStats.inc();
View Full Code Here

TOP

Related Classes of com.linkedin.d2.balancer.clients.TrackerClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.