Search in sources :

Example 1 with ResourceUsage

use of com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage in project pulsar by yahoo.

the class LoadBalancerTest method testBrokerRanking.

/*
     * Pre-publish load report to ZK, each broker has: - Difference memory capacity, for the first 3 brokers memory is
     * bottleneck, for the 4/5th brokers CPU become bottleneck since memory is big enough - non-bundles assigned so all
     * idle resources are avaiable for new bundle Check the broker rankings are the load percentage of each broker.
     */
@Test
public void testBrokerRanking() throws Exception {
    for (int i = 0; i < BROKER_COUNT; i++) {
        LoadReport lr = new LoadReport();
        lr.setName(lookupAddresses[i]);
        SystemResourceUsage sru = new SystemResourceUsage();
        sru.setBandwidthIn(new ResourceUsage(0, 1024000));
        sru.setBandwidthOut(new ResourceUsage(0, 1024000));
        sru.setMemory(new ResourceUsage(1024, 2048 * (i + 1)));
        sru.setCpu(new ResourceUsage(60, 400));
        lr.setSystemResourceUsage(sru);
        String znodePath = String.format("%s/%s", SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT, lookupAddresses[i]);
        String loadReportJson = objectMapper.writeValueAsString(lr);
        bkEnsemble.getZkClient().setData(znodePath, loadReportJson.getBytes(Charsets.UTF_8), -1);
    }
    // sleep to wait load ranking be triggered
    Thread.sleep(5000);
    // check the ranking result
    for (int i = 0; i < BROKER_COUNT; i++) {
        AtomicReference<Map<Long, Set<ResourceUnit>>> sortedRanking = getSortedRanking(pulsarServices[i]);
        printSortedRanking(sortedRanking);
        // brokers' ranking would be:
        // 50 --> broker 0 ( 1024 / 2048 )
        // 25 --> broker 1 ( 1024 / 4096 )
        // 16 --> broker 2 ( 1024 / 6144 )
        // 15 --> broker 3 ( 60 / 400 )
        // 15 --> broker 4 ( 60 / 400 )
        assertEquals(sortedRanking.get().size(), 4);
        assertEquals(sortedRanking.get().get(50L).size(), 1);
        assertEquals(sortedRanking.get().get(25L).size(), 1);
        assertEquals(sortedRanking.get().get(16L).size(), 1);
        assertEquals(sortedRanking.get().get(15L).size(), 2);
    }
}
Also used : SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.testng.annotations.Test)

Example 2 with ResourceUsage

use of com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage in project pulsar by yahoo.

the class LoadBalancerTest method testDestinationAssignmentWithExistingBundles.

/*
     * Pre-publish load report to ZK, each broker has: - Difference memory capacity, for the first 3 brokers memory is
     * bottleneck, for the 4/5th brokers CPU become bottleneck since memory is big enough - already has some bundles
     * assigned Check the distribution of new destinations is roughly consistent (with <10% variation) with the ranking
     */
@Test
public void testDestinationAssignmentWithExistingBundles() throws Exception {
    for (int i = 0; i < BROKER_COUNT; i++) {
        ResourceQuota defaultQuota = new ResourceQuota();
        defaultQuota.setMsgRateIn(20);
        defaultQuota.setMsgRateOut(60);
        defaultQuota.setBandwidthIn(20000);
        defaultQuota.setBandwidthOut(60000);
        defaultQuota.setMemory(87);
        pulsarServices[i].getLocalZkCacheService().getResourceQuotaCache().setDefaultQuota(defaultQuota);
        LoadReport lr = new LoadReport();
        lr.setName(lookupAddresses[i]);
        SystemResourceUsage sru = new SystemResourceUsage();
        sru.setBandwidthIn(new ResourceUsage(0, 1024000));
        sru.setBandwidthOut(new ResourceUsage(0, 1024000));
        sru.setMemory(new ResourceUsage(0, 2048 * (i + 1)));
        sru.setCpu(new ResourceUsage(60, 400));
        lr.setSystemResourceUsage(sru);
        Map<String, NamespaceBundleStats> bundleStats = new HashMap<String, NamespaceBundleStats>();
        for (int j = 0; j < (i + 1) * 5; j++) {
            String bundleName = String.format("pulsar/use/primary-ns-%d-%d/0x00000000_0xffffffff", i, j);
            NamespaceBundleStats stats = new NamespaceBundleStats();
            bundleStats.put(bundleName, stats);
        }
        lr.setBundleStats(bundleStats);
        String znodePath = String.format("%s/%s", SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT, lookupAddresses[i]);
        String loadReportJson = objectMapper.writeValueAsString(lr);
        bkEnsemble.getZkClient().setData(znodePath, loadReportJson.getBytes(Charsets.UTF_8), -1);
    }
    // sleep to wait load ranking be triggered
    Thread.sleep(5000);
    // print ranking
    for (int i = 0; i < BROKER_COUNT; i++) {
        AtomicReference<Map<Long, Set<ResourceUnit>>> sortedRanking = getSortedRanking(pulsarServices[i]);
        printSortedRanking(sortedRanking);
    }
    // check owner of new destiations and verify that the distribution is roughly
    // consistent (variation < 10%) with the broker capacity:
    int totalNamespaces = 250;
    int[] expectedAssignments = new int[] { 17, 34, 51, 68, 85 };
    Map<String, Integer> namespaceOwner = new HashMap<>();
    for (int i = 0; i < totalNamespaces; i++) {
        DestinationName fqdn = DestinationName.get("persistent://pulsar/use/primary-ns-" + i + "/test-topic");
        ResourceUnit found = pulsarServices[0].getLoadManager().getLeastLoaded(pulsarServices[0].getNamespaceService().getBundle(fqdn));
        if (namespaceOwner.containsKey(found.getResourceId())) {
            namespaceOwner.put(found.getResourceId(), namespaceOwner.get(found.getResourceId()) + 1);
        } else {
            namespaceOwner.put(found.getResourceId(), 1);
        }
    }
    double expectedMaxVariation = 10.0;
    for (int i = 0; i < BROKER_COUNT; i++) {
        long actualValue = 0;
        String resourceId = "http://" + lookupAddresses[i];
        if (namespaceOwner.containsKey(resourceId)) {
            actualValue = namespaceOwner.get(resourceId);
        }
        long expectedValue = expectedAssignments[i];
        double variation = Math.abs(actualValue - expectedValue) * 100.0 / expectedValue;
        log.info("Destination assignment - {}, actual: {}, expected baseline: {}, variation: {}/%", lookupAddresses[i], actualValue, expectedValue, String.format("%.2f", variation));
        assertTrue(variation < expectedMaxVariation);
    }
}
Also used : HashMap(java.util.HashMap) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) NamespaceBundleStats(com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.testng.annotations.Test)

Example 3 with ResourceUsage

use of com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage in project pulsar by yahoo.

the class LoadBalancerTest method createResourceDescription.

/*
     * creates a ResourceDescription where the max limits for different parameters are as below
     *
     * Memory = 16GB cpu = 100 percent bandwidthIn = 1Gbps bandwidthOut = 1Gbps threads = 100
     */
private PulsarResourceDescription createResourceDescription(long memoryInMB, long cpuPercentage, long bandwidthInMbps, long bandwidthOutInMbps, long threads) {
    long KB = 1024;
    long MB = 1024 * KB;
    long GB = 1024 * MB;
    PulsarResourceDescription rd = new PulsarResourceDescription();
    rd.put("memory", new ResourceUsage(memoryInMB, 4 * GB));
    rd.put("cpu", new ResourceUsage(cpuPercentage, 100));
    rd.put("bandwidthIn", new ResourceUsage(bandwidthInMbps * MB, GB));
    rd.put("bandwidthOut", new ResourceUsage(bandwidthOutInMbps * MB, GB));
    return rd;
}
Also used : PulsarResourceDescription(com.yahoo.pulsar.broker.loadbalance.impl.PulsarResourceDescription) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage)

Example 4 with ResourceUsage

use of com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage in project pulsar by yahoo.

the class LoadBalancerTest method writeLoadReportsForDynamicQuota.

private void writeLoadReportsForDynamicQuota(long timestamp) throws Exception {
    for (int i = 0; i < BROKER_COUNT; i++) {
        LoadReport lr = new LoadReport();
        lr.setName(lookupAddresses[i]);
        lr.setTimestamp(timestamp);
        SystemResourceUsage sru = new SystemResourceUsage();
        sru.setBandwidthIn(new ResourceUsage(5000 * (10 + i * 5), 1024000));
        sru.setBandwidthOut(new ResourceUsage(15000 * (10 + i * 5), 1024000));
        sru.setMemory(new ResourceUsage(25 * (10 + i * 5), 2048 * (i + 1)));
        sru.setCpu(new ResourceUsage(200, 400));
        lr.setSystemResourceUsage(sru);
        Map<String, NamespaceBundleStats> bundleStats = new HashMap<String, NamespaceBundleStats>();
        for (int j = 0; j < 5; j++) {
            String bundleName = String.format("pulsar/use/primary-ns-%d-%d/0x00000000_0xffffffff", i, j);
            NamespaceBundleStats stats = new NamespaceBundleStats();
            stats.msgRateIn = 5 * (i + j);
            stats.msgRateOut = 15 * (i + j);
            stats.msgThroughputIn = 5000 * (i + j);
            stats.msgThroughputOut = 15000 * (i + j);
            stats.topics = 25 * (i + j);
            stats.consumerCount = 50 * (i + j);
            stats.producerCount = 50 * (i + j);
            bundleStats.put(bundleName, stats);
        }
        lr.setBundleStats(bundleStats);
        String znodePath = String.format("%s/%s", SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT, lookupAddresses[i]);
        String loadReportJson = objectMapper.writeValueAsString(lr);
        bkEnsemble.getZkClient().setData(znodePath, loadReportJson.getBytes(Charsets.UTF_8), -1);
    }
}
Also used : NamespaceBundleStats(com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats) HashMap(java.util.HashMap) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage) SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage)

Example 5 with ResourceUsage

use of com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage in project pulsar by yahoo.

the class SimpleLoadManagerImplTest method testResourceDescription.

@Test
public void testResourceDescription() {
    PulsarResourceDescription rd = new PulsarResourceDescription();
    rd.put("memory", new ResourceUsage(1024, 4096));
    rd.put("cpu", new ResourceUsage(10, 100));
    rd.put("bandwidthIn", new ResourceUsage(250 * 1024, 1024 * 1024));
    rd.put("bandwidthOut", new ResourceUsage(550 * 1024, 1024 * 1024));
    PulsarResourceDescription rd1 = new PulsarResourceDescription();
    rd1.put("memory", new ResourceUsage(2048, 4096));
    rd1.put("cpu", new ResourceUsage(50, 100));
    rd1.put("bandwidthIn", new ResourceUsage(550 * 1024, 1024 * 1024));
    rd1.put("bandwidthOut", new ResourceUsage(850 * 1024, 1024 * 1024));
    assertTrue(rd.compareTo(rd1) == 1);
    assertTrue(rd1.calculateRank() > rd.calculateRank());
    SimpleLoadCalculatorImpl calc = new SimpleLoadCalculatorImpl();
    calc.recaliberateResourceUsagePerServiceUnit(null);
    assertNull(calc.getResourceDescription(null));
}
Also used : SystemResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage) Test(org.testng.annotations.Test)

Aggregations

ResourceUsage (com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage)14 SystemResourceUsage (com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage)14 Test (org.testng.annotations.Test)11 HashMap (java.util.HashMap)9 Map (java.util.Map)8 HashSet (java.util.HashSet)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 SimpleResourceUnit (com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit)4 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)4 LoadReport (com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport)4 Field (java.lang.reflect.Field)4 TreeMap (java.util.TreeMap)4 NamespaceBundleStats (com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats)3 PulsarResourceDescription (com.yahoo.pulsar.broker.loadbalance.impl.PulsarResourceDescription)2 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)2 ResourceQuota (com.yahoo.pulsar.common.policies.data.ResourceQuota)2 LocalZooKeeperCache (com.yahoo.pulsar.zookeeper.LocalZooKeeperCache)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ResourceAvailabilityRanker (com.yahoo.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker)1 SimpleLoadManagerImpl (com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl)1