Search in sources :

Example 16 with ResourceQuota

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

the class SimpleLoadManagerImpl method timeSmoothQuota.

private ResourceQuota timeSmoothQuota(ResourceQuota oldQuota, double msgRateIn, double msgRateOut, double bandwidthIn, double bandwidthOut, double memory, long timePast) {
    if (oldQuota.getDynamic()) {
        ResourceQuota newQuota = new ResourceQuota();
        newQuota.setMsgRateIn(timeSmoothValue(oldQuota.getMsgRateIn(), msgRateIn, RESOURCE_QUOTA_MIN_MSGRATE_IN, RESOURCE_QUOTA_MAX_MSGRATE_IN, timePast));
        newQuota.setMsgRateOut(timeSmoothValue(oldQuota.getMsgRateOut(), msgRateOut, RESOURCE_QUOTA_MIN_MSGRATE_OUT, RESOURCE_QUOTA_MAX_MSGRATE_OUT, timePast));
        newQuota.setBandwidthIn(timeSmoothValue(oldQuota.getBandwidthIn(), bandwidthIn, RESOURCE_QUOTA_MIN_BANDWIDTH_IN, RESOURCE_QUOTA_MAX_BANDWIDTH_IN, timePast));
        newQuota.setBandwidthOut(timeSmoothValue(oldQuota.getBandwidthOut(), bandwidthOut, RESOURCE_QUOTA_MIN_BANDWIDTH_OUT, RESOURCE_QUOTA_MAX_BANDWIDTH_OUT, timePast));
        newQuota.setMemory(timeSmoothValue(oldQuota.getMemory(), memory, RESOURCE_QUOTA_MIN_MEMORY, RESOURCE_QUOTA_MAX_MEMORY, timePast));
        return newQuota;
    } else {
        return oldQuota;
    }
}
Also used : ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota)

Example 17 with ResourceQuota

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

the class ResourceQuotaCacheTest method testGetSetDefaultQuota.

@Test
public void testGetSetDefaultQuota() throws Exception {
    ResourceQuotaCache cache = new ResourceQuotaCache(zkCache);
    ResourceQuota quota1 = ResourceQuotaCache.getInitialQuotaValue();
    ResourceQuota quota2 = new ResourceQuota();
    quota2.setMsgRateIn(10);
    quota2.setMsgRateOut(20);
    quota2.setBandwidthIn(10000);
    quota2.setBandwidthOut(20000);
    quota2.setMemory(100);
    quota2.setDynamic(false);
    assertEquals(cache.getDefaultQuota(), quota1);
    cache.setDefaultQuota(quota2);
    assertEquals(cache.getDefaultQuota(), quota2);
}
Also used : ResourceQuotaCache(com.yahoo.pulsar.broker.cache.ResourceQuotaCache) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) Test(org.testng.annotations.Test)

Example 18 with ResourceQuota

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

the class ResourceQuotaCache method getQuota.

/**
     * Get resource quota for a specified service unit.
     *
     * @param suName
     *            identifier of the <code>ServiceUnit</code>
     *
     * @return the <code>ResourceQuota</code>.
     */
public ResourceQuota getQuota(String suName) {
    String zpath = ResourceQuotaCache.path(suName);
    ResourceQuota quota = this.readQuotaFromZnode(zpath);
    if (!quota.isValid()) {
        String defaultZpath = ResourceQuotaCache.path(null);
        quota = this.readQuotaFromZnode(defaultZpath);
        if (!quota.isValid()) {
            quota = ResourceQuotaCache.getInitialQuotaValue();
        }
    }
    return quota;
}
Also used : ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota)

Example 19 with ResourceQuota

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

the class ResourceQuotaCache method initZK.

/**
     * Initialize the resource quota root node in ZooKeeper.
     *
     */
public void initZK() throws PulsarServerException {
    String zpath = ResourceQuotaCache.path(null);
    ResourceQuota quota = this.readQuotaFromZnode(zpath);
    if (!quota.isValid()) {
        quota = ResourceQuotaCache.getInitialQuotaValue();
        try {
            this.saveQuotaToZnode(zpath, quota);
        } catch (Exception e) {
            throw new PulsarServerException(e);
        }
    }
}
Also used : PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException) ResourceQuota(com.yahoo.pulsar.common.policies.data.ResourceQuota) KeeperException(org.apache.zookeeper.KeeperException) PulsarServerException(com.yahoo.pulsar.broker.PulsarServerException)

Aggregations

ResourceQuota (com.yahoo.pulsar.common.policies.data.ResourceQuota)19 Test (org.testng.annotations.Test)9 HashMap (java.util.HashMap)7 Map (java.util.Map)7 TreeMap (java.util.TreeMap)6 ResourceUnit (com.yahoo.pulsar.broker.loadbalance.ResourceUnit)3 LoadReport (com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport)3 ResourceUnitRanking (com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUnitRanking)3 SystemResourceUsage (com.yahoo.pulsar.common.policies.data.loadbalancer.SystemResourceUsage)3 ResourceQuotaCache (com.yahoo.pulsar.broker.cache.ResourceQuotaCache)2 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)2 NamespaceBundleStats (com.yahoo.pulsar.common.policies.data.loadbalancer.NamespaceBundleStats)2 ResourceUsage (com.yahoo.pulsar.common.policies.data.loadbalancer.ResourceUsage)2 HashSet (java.util.HashSet)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)1 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 SimpleResourceUnit (com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit)1 RestException (com.yahoo.pulsar.broker.web.RestException)1 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)1