Search in sources :

Example 1 with ZooKeeperCache

use of com.yahoo.pulsar.zookeeper.ZooKeeperCache in project pulsar by yahoo.

the class LoadBalancerTest method testLoadBalanceDistributionAmongUnequallyLoaded.

@Test(enabled = false)
void testLoadBalanceDistributionAmongUnequallyLoaded() throws Exception {
    long memoryMB = 4096;
    long cpuPercent = 25;
    long bInMbps = 256;
    long bOutMbps = 256;
    long threads = 25;
    LoadManager loadManager = new SimpleLoadManagerImpl(pulsarServices[0]);
    ZooKeeperCache mockCache = mock(ZooKeeperCache.class);
    Set<String> activeBrokers = Sets.newHashSet("prod1-broker1.messaging.use.example.com:8080", "prod1-broker2.messaging.use.example.com:8080", "prod1-broker3.messaging.use.example.com:8080");
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    Field zkCacheField = PulsarService.class.getDeclaredField("localZkCache");
    zkCacheField.setAccessible(true);
    zkCacheField.set(pulsarServices[0], mockCache);
    int totalAvailabilityWeight = 0;
    TreeMap<Long, Set<ResourceUnit>> sortedRankingsInstance = new TreeMap<Long, Set<ResourceUnit>>();
    for (int i = 1; i <= 3; i++) {
        PulsarResourceDescription rd = createResourceDescription(memoryMB * i, cpuPercent * i, bInMbps * i, bOutMbps * 2, threads * i);
        ResourceUnit ru1 = new SimpleResourceUnit(String.format("http://prod1-broker%d.messaging.use.example.com:8080", i), rd);
        LoadRanker ranker = new ResourceAvailabilityRanker();
        long rank = ranker.getRank(rd);
        if (sortedRankingsInstance.containsKey(rank)) {
            // get the object set and put the rd in it
            sortedRankingsInstance.get(rank).add(ru1);
        } else {
            Set<ResourceUnit> rus = new HashSet<ResourceUnit>();
            rus.add(ru1);
            sortedRankingsInstance.put(rank, rus);
        }
        totalAvailabilityWeight += rank;
    }
    Field sortedRankings = SimpleLoadManagerImpl.class.getDeclaredField("sortedRankings");
    sortedRankings.setAccessible(true);
    AtomicReference<TreeMap<Long, Set<ResourceUnit>>> ar = new AtomicReference<TreeMap<Long, Set<ResourceUnit>>>();
    ar.set(sortedRankingsInstance);
    sortedRankings.set(loadManager, ar);
    int totalNamespaces = 1000;
    Map<String, Integer> namespaceOwner = new HashMap<String, Integer>();
    for (int i = 0; i < totalNamespaces; i++) {
        ResourceUnit found = loadManager.getLeastLoaded(DestinationName.get("persistent://pulsar/use/primary-ns/topic-" + i));
        if (namespaceOwner.containsKey(found.getResourceId())) {
            namespaceOwner.put(found.getResourceId(), namespaceOwner.get(found.getResourceId()) + 1);
        } else {
            namespaceOwner.put(found.getResourceId(), 0);
        }
    }
    for (Map.Entry<Long, Set<ResourceUnit>> entry : sortedRankingsInstance.entrySet()) {
        int selectionProbability = (int) (((double) entry.getKey() / totalAvailabilityWeight) * 100);
        int idealExpectedOwned = selectionProbability * (int) ((double) totalNamespaces / 100);
        int expectedOwnedLowerBound = idealExpectedOwned - idealExpectedOwned / 10;
        int expectedOwnedUpperBound = idealExpectedOwned + idealExpectedOwned / 10;
        for (ResourceUnit ru : entry.getValue()) {
            assertTrue(namespaceOwner.containsKey(ru.getResourceId()));
            int ownedNamespaces = namespaceOwner.get(ru.getResourceId());
            assertTrue(ownedNamespaces > expectedOwnedLowerBound || ownedNamespaces < expectedOwnedUpperBound);
        }
    }
}
Also used : PulsarResourceDescription(com.yahoo.pulsar.broker.loadbalance.impl.PulsarResourceDescription) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ResourceAvailabilityRanker(com.yahoo.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker) Field(java.lang.reflect.Field) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) SimpleLoadManagerImpl(com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) LocalZooKeeperCache(com.yahoo.pulsar.zookeeper.LocalZooKeeperCache) ZooKeeperCache(com.yahoo.pulsar.zookeeper.ZooKeeperCache) HashSet(java.util.HashSet) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.testng.annotations.Test)

Example 2 with ZooKeeperCache

use of com.yahoo.pulsar.zookeeper.ZooKeeperCache in project pulsar by yahoo.

the class BookKeeperClientFactoryImpl method create.

@Override
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient) throws IOException {
    ClientConfiguration bkConf = new ClientConfiguration();
    if (conf.getBookkeeperClientAuthenticationPlugin() != null && conf.getBookkeeperClientAuthenticationPlugin().trim().length() > 0) {
        bkConf.setClientAuthProviderFactoryClass(conf.getBookkeeperClientAuthenticationPlugin());
        bkConf.setProperty(conf.getBookkeeperClientAuthenticationParametersName(), conf.getBookkeeperClientAuthenticationParameters());
    }
    bkConf.setThrottleValue(0);
    bkConf.setAddEntryTimeout((int) conf.getBookkeeperClientTimeoutInSeconds());
    bkConf.setReadEntryTimeout((int) conf.getBookkeeperClientTimeoutInSeconds());
    bkConf.setSpeculativeReadTimeout(conf.getBookkeeperClientSpeculativeReadTimeoutInMillis());
    bkConf.setNumChannelsPerBookie(16);
    bkConf.setUseV2WireProtocol(true);
    bkConf.setLedgerManagerFactoryClassName(HierarchicalLedgerManagerFactory.class.getName());
    if (conf.isBookkeeperClientHealthCheckEnabled()) {
        bkConf.enableBookieHealthCheck();
        bkConf.setBookieHealthCheckInterval(conf.getBookkeeperHealthCheckIntervalSec(), TimeUnit.SECONDS);
        bkConf.setBookieErrorThresholdPerInterval(conf.getBookkeeperClientHealthCheckErrorThresholdPerInterval());
        bkConf.setBookieQuarantineTime((int) conf.getBookkeeperClientHealthCheckQuarantineTimeInSeconds(), TimeUnit.SECONDS);
    }
    if (conf.isBookkeeperClientRackawarePolicyEnabled()) {
        bkConf.setEnsemblePlacementPolicy(RackawareEnsemblePlacementPolicy.class);
        bkConf.setProperty(RackawareEnsemblePlacementPolicy.REPP_DNS_RESOLVER_CLASS, ZkBookieRackAffinityMapping.class.getName());
        bkConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(zkClient) {
        });
    }
    if (conf.getBookkeeperClientIsolationGroups() != null && !conf.getBookkeeperClientIsolationGroups().isEmpty()) {
        bkConf.setEnsemblePlacementPolicy(ZkIsolatedBookieEnsemblePlacementPolicy.class);
        bkConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, conf.getBookkeeperClientIsolationGroups());
        if (bkConf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) == null) {
            bkConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(zkClient) {
            });
        }
    }
    try {
        return new BookKeeper(bkConf, zkClient);
    } catch (InterruptedException | KeeperException e) {
        throw new IOException(e);
    }
}
Also used : BookKeeper(org.apache.bookkeeper.client.BookKeeper) HierarchicalLedgerManagerFactory(org.apache.bookkeeper.meta.HierarchicalLedgerManagerFactory) IOException(java.io.IOException) ZkBookieRackAffinityMapping(com.yahoo.pulsar.zookeeper.ZkBookieRackAffinityMapping) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) ZooKeeperCache(com.yahoo.pulsar.zookeeper.ZooKeeperCache) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with ZooKeeperCache

use of com.yahoo.pulsar.zookeeper.ZooKeeperCache in project pulsar by yahoo.

the class LoadBalancerTest method testLoadbalanceDistributionAmongEquallyLoaded.

/*
     * Simple Test, creates three Resource Units (brokers) with equal load and expects that out of 1005 namespaces it
     * should be divided fairly equally with about 10% of variation
     *
     */
@Test(enabled = false)
public void testLoadbalanceDistributionAmongEquallyLoaded() throws Exception {
    LoadManager loadManager = new SimpleLoadManagerImpl(pulsarServices[0]);
    ZooKeeperCache mockCache = mock(ZooKeeperCache.class);
    Set<String> activeBrokers = Sets.newHashSet("prod1-broker1.messaging.use.example.com:8080", "prod1-broker2.messaging.use.example.com:8080", "prod1-broker3.messaging.use.example.com:8080");
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    Field zkCacheField = PulsarService.class.getDeclaredField("localZkCache");
    zkCacheField.setAccessible(true);
    zkCacheField.set(pulsarServices[0], mockCache);
    long memoryMB = 4096;
    long cpuPercent = 45;
    long bInMbps = 350;
    long bOutMbps = 180;
    long threads = 10;
    // TODO move to its own test
    PulsarResourceDescription rd = createResourceDescription(memoryMB, cpuPercent, bInMbps, bOutMbps, threads);
    Set<ResourceUnit> rus = new HashSet<ResourceUnit>();
    for (String broker : activeBrokers) {
        ResourceUnit ru = new SimpleResourceUnit(broker, rd);
        rus.add(ru);
    }
    TreeMap<Long, Set<ResourceUnit>> sortedRankingsInstance = new TreeMap<Long, Set<ResourceUnit>>();
    LoadRanker ranker = new ResourceAvailabilityRanker();
    sortedRankingsInstance.put(ranker.getRank(rd), rus);
    Field sortedRankings = SimpleLoadManagerImpl.class.getDeclaredField("sortedRankings");
    sortedRankings.setAccessible(true);
    AtomicReference<TreeMap<Long, Set<ResourceUnit>>> ar = new AtomicReference<TreeMap<Long, Set<ResourceUnit>>>();
    ar.set(sortedRankingsInstance);
    sortedRankings.set(loadManager, ar);
}
Also used : PulsarResourceDescription(com.yahoo.pulsar.broker.loadbalance.impl.PulsarResourceDescription) Set(java.util.Set) HashSet(java.util.HashSet) ResourceAvailabilityRanker(com.yahoo.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) Field(java.lang.reflect.Field) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) SimpleLoadManagerImpl(com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) LocalZooKeeperCache(com.yahoo.pulsar.zookeeper.LocalZooKeeperCache) ZooKeeperCache(com.yahoo.pulsar.zookeeper.ZooKeeperCache) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with ZooKeeperCache

use of com.yahoo.pulsar.zookeeper.ZooKeeperCache in project pulsar by yahoo.

the class LoadBalancerTest method testLoadBalanceDiscardingInactiveBrokersInSelection.

/**
     * This test puts few brokers in the ranking that load balance uses but does not put few brokers in the mock
     * zookeeper cache, if the broker is not in the zk cache, it's considered inactive.
     *
     * We should not see any of these inactive brokers assigned any namespace.
     */
@Test(enabled = false)
void testLoadBalanceDiscardingInactiveBrokersInSelection() throws Exception {
    long memoryMB = 2096;
    long cpuPercent = 12;
    long bInMbps = 100;
    long bOutMbps = 100;
    long threads = 3;
    LoadManager loadManager = new SimpleLoadManagerImpl(pulsarServices[0]);
    ZooKeeperCache mockCache = mock(ZooKeeperCache.class);
    Set<String> activeBrokers = Sets.newHashSet("prod1-broker1.messaging.use.example.com:8080", "prod1-broker2.messaging.use.example.com:8080");
    when(mockCache.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)).thenReturn(activeBrokers);
    Field zkCacheField = PulsarService.class.getDeclaredField("localZkCache");
    zkCacheField.setAccessible(true);
    zkCacheField.set(pulsarServices[0], mockCache);
    TreeMap<Long, Set<ResourceUnit>> sortedRankingsInstance = new TreeMap<Long, Set<ResourceUnit>>();
    for (int i = 1; i <= 3; i++) {
        PulsarResourceDescription rd = createResourceDescription(memoryMB * i, cpuPercent * i, bInMbps * i, bOutMbps * 2, threads * i);
        ResourceUnit ru1 = new SimpleResourceUnit(String.format("http://prod1-broker%d.messaging.use.example.com:8080", i), rd);
        LoadRanker ranker = new ResourceAvailabilityRanker();
        long rank = ranker.getRank(rd);
        if (sortedRankingsInstance.containsKey(rank)) {
            // get the object set and put the rd in it
            sortedRankingsInstance.get(rank).add(ru1);
        } else {
            Set<ResourceUnit> rus = new HashSet<ResourceUnit>();
            rus.add(ru1);
            sortedRankingsInstance.put(rank, rus);
        }
    }
    Field sortedRankings = SimpleLoadManagerImpl.class.getDeclaredField("sortedRankings");
    sortedRankings.setAccessible(true);
    AtomicReference<TreeMap<Long, Set<ResourceUnit>>> ar = new AtomicReference<TreeMap<Long, Set<ResourceUnit>>>();
    ar.set(sortedRankingsInstance);
    sortedRankings.set(loadManager, ar);
    int totalNamespaces = 10;
    Map<String, Integer> namespaceOwner = new HashMap<String, Integer>();
    for (int i = 0; i < totalNamespaces; i++) {
        ResourceUnit found = loadManager.getLeastLoaded(DestinationName.get("persistent://pulsar/use/primary-ns/topic" + i));
        if (namespaceOwner.containsKey(found.getResourceId())) {
            namespaceOwner.put(found.getResourceId(), namespaceOwner.get(found.getResourceId()) + 1);
        } else {
            namespaceOwner.put(found.getResourceId(), 0);
        }
    }
    String inactiveBroker = "prod1-broker3.messaging.use.example.com:8080";
    // check owner list contains only two entries, broker-3 should not be in
    assertTrue(namespaceOwner.size() == 2);
    assertTrue(!namespaceOwner.containsKey(inactiveBroker));
}
Also used : PulsarResourceDescription(com.yahoo.pulsar.broker.loadbalance.impl.PulsarResourceDescription) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ResourceAvailabilityRanker(com.yahoo.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) Field(java.lang.reflect.Field) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) SimpleLoadManagerImpl(com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) LocalZooKeeperCache(com.yahoo.pulsar.zookeeper.LocalZooKeeperCache) ZooKeeperCache(com.yahoo.pulsar.zookeeper.ZooKeeperCache) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ZooKeeperCache (com.yahoo.pulsar.zookeeper.ZooKeeperCache)4 PulsarResourceDescription (com.yahoo.pulsar.broker.loadbalance.impl.PulsarResourceDescription)3 ResourceAvailabilityRanker (com.yahoo.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker)3 SimpleLoadManagerImpl (com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl)3 SimpleResourceUnit (com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit)3 LocalZooKeeperCache (com.yahoo.pulsar.zookeeper.LocalZooKeeperCache)3 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 TreeMap (java.util.TreeMap)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Test (org.testng.annotations.Test)3 HashMap (java.util.HashMap)2 ZkBookieRackAffinityMapping (com.yahoo.pulsar.zookeeper.ZkBookieRackAffinityMapping)1 IOException (java.io.IOException)1 Map (java.util.Map)1 BookKeeper (org.apache.bookkeeper.client.BookKeeper)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 HierarchicalLedgerManagerFactory (org.apache.bookkeeper.meta.HierarchicalLedgerManagerFactory)1 KeeperException (org.apache.zookeeper.KeeperException)1