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;
}
}
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);
}
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;
}
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);
}
}
}
Aggregations