gpt4 book ai didi

org.apache.hadoop.ipc.WeightedRoundRobinMultiplexer类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 05:15:05 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.hadoop.ipc.WeightedRoundRobinMultiplexer类的一些代码示例,展示了WeightedRoundRobinMultiplexer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WeightedRoundRobinMultiplexer类的具体详情如下:
包路径:org.apache.hadoop.ipc.WeightedRoundRobinMultiplexer
类名称:WeightedRoundRobinMultiplexer

WeightedRoundRobinMultiplexer介绍

[英]Determines which queue to start reading from, occasionally drawing from low-priority queues in order to prevent starvation. Given the pull pattern [9, 4, 1] for 3 queues: The cycle is (a minimum of) 9+4+1=14 reads. Queue 0 is read (at least) 9 times Queue 1 is read (at least) 4 times Queue 2 is read (at least) 1 time Repeat There may be more reads than the minimum due to race conditions. This is allowed by design for performance reasons.
[中]确定从哪个队列开始读取,偶尔从低优先级队列中提取以防止饥饿。给定3个队列的拉模式[9,4,1]:循环是(至少)9+4+1=14次读取。队列0被读取(至少)9次队列1被读取(至少)4次队列2被读取(至少)1次重复由于竞争条件,读取次数可能超过最小值。出于性能原因,设计允许这样做。

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

this.multiplexer = new WeightedRoundRobinMultiplexer(numQueues, ns, conf);

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Use the mux by getting and advancing index.
 */
public int getAndAdvanceCurrentIndex() {
 int idx = this.getCurrentIndex();
 this.advanceIndex();
 return idx;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public WeightedRoundRobinMultiplexer(int aNumQueues, String ns,
 Configuration conf) {
 if (aNumQueues <= 0) {
  throw new IllegalArgumentException("Requested queues (" + aNumQueues +
   ") must be greater than zero.");
 }
 this.numQueues = aNumQueues;
 this.queueWeights = conf.getInts(ns + "." +
  IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY);
 if (this.queueWeights.length == 0) {
  this.queueWeights = getDefaultQueueWeights(this.numQueues);
 } else if (this.queueWeights.length != this.numQueues) {
  throw new IllegalArgumentException(ns + "." +
   IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY + " must specify exactly " +
   this.numQueues + " weights: one for each priority level.");
 }
 this.currentQueueIndex = new AtomicInteger(0);
 this.requestsLeft = new AtomicInteger(this.queueWeights[0]);
 LOG.info("WeightedRoundRobinMultiplexer is being used.");
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test
 public void testCustomPattern() {
  // 1x0 1x1
  Configuration conf = new Configuration();
  conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY,
   "1", "1");

  mux = new WeightedRoundRobinMultiplexer(2, "test.custom", conf);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 1);

  // 1x0 3x1 2x2
  conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY,
   "1", "3", "2");

  mux = new WeightedRoundRobinMultiplexer(3, "test.custom", conf);

  for(int i = 0; i < 5; i++) {
   assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
  } // Ensure pattern repeats

 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Advances the index, which will change the current index
 * if called enough times.
 */
private void advanceIndex() {
 // Since we did read, we should decrement
 int requestsLeftVal = this.requestsLeft.decrementAndGet();
 // Strict compare with zero (instead of inequality) so that if another
 // thread decrements requestsLeft, only one thread will be responsible
 // for advancing currentQueueIndex
 if (requestsLeftVal == 0) {
  // This is guaranteed to be called exactly once per currentQueueIndex
  this.moveToNextQueue();
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
 public void testCustomPattern() {
  // 1x0 1x1
  Configuration conf = new Configuration();
  conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY,
   "1", "1");

  mux = new WeightedRoundRobinMultiplexer(2, "test.custom", conf);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
  assertEquals(mux.getAndAdvanceCurrentIndex(), 1);

  // 1x0 3x1 2x2
  conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY,
   "1", "3", "2");

  mux = new WeightedRoundRobinMultiplexer(3, "test.custom", conf);

  for(int i = 0; i < 5; i++) {
   assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
   assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
  } // Ensure pattern repeats

 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Advances the index, which will change the current index
 * if called enough times.
 */
private void advanceIndex() {
 // Since we did read, we should decrement
 int requestsLeftVal = this.requestsLeft.decrementAndGet();
 // Strict compare with zero (instead of inequality) so that if another
 // thread decrements requestsLeft, only one thread will be responsible
 // for advancing currentQueueIndex
 if (requestsLeftVal == 0) {
  // This is guaranteed to be called exactly once per currentQueueIndex
  this.moveToNextQueue();
 }
}

代码示例来源:origin: io.hops/hadoop-common

this.multiplexer = new WeightedRoundRobinMultiplexer(numQueues, ns, conf);

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Use the mux by getting and advancing index.
 */
public int getAndAdvanceCurrentIndex() {
 int idx = this.getCurrentIndex();
 this.advanceIndex();
 return idx;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

mux = new WeightedRoundRobinMultiplexer(1, "", new Configuration());
for(int i = 0; i < 10; i++) {
 assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
mux = new WeightedRoundRobinMultiplexer(2, "", new Configuration());
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
mux = new WeightedRoundRobinMultiplexer(3, "", new Configuration());
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
mux = new WeightedRoundRobinMultiplexer(4, "", new Configuration());
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Advances the index, which will change the current index
 * if called enough times.
 */
private void advanceIndex() {
 // Since we did read, we should decrement
 int requestsLeftVal = this.requestsLeft.decrementAndGet();
 // Strict compare with zero (instead of inequality) so that if another
 // thread decrements requestsLeft, only one thread will be responsible
 // for advancing currentQueueIndex
 if (requestsLeftVal == 0) {
  // This is guaranteed to be called exactly once per currentQueueIndex
  this.moveToNextQueue();
 }
}

代码示例来源:origin: io.hops/hadoop-common

public WeightedRoundRobinMultiplexer(int aNumQueues, String ns,
 Configuration conf) {
 if (aNumQueues <= 0) {
  throw new IllegalArgumentException("Requested queues (" + aNumQueues +
   ") must be greater than zero.");
 }
 this.numQueues = aNumQueues;
 this.queueWeights = conf.getInts(ns + "." +
  IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY);
 if (this.queueWeights.length == 0) {
  this.queueWeights = getDefaultQueueWeights(this.numQueues);
 } else if (this.queueWeights.length != this.numQueues) {
  throw new IllegalArgumentException(ns + "." +
   IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY + " must specify exactly " +
   this.numQueues + " weights: one for each priority level.");
 }
 this.currentQueueIndex = new AtomicInteger(0);
 this.requestsLeft = new AtomicInteger(this.queueWeights[0]);
 LOG.info("WeightedRoundRobinMultiplexer is being used.");
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Create a FairCallQueue.
 * @param capacity the maximum size of each sub-queue
 * @param ns the prefix to use for configuration
 * @param conf the configuration to read from
 * Notes: the FairCallQueue has no fixed capacity. Rather, it has a minimum
 * capacity of `capacity` and a maximum capacity of `capacity * number_queues`
 */
public FairCallQueue(int capacity, String ns, Configuration conf) {
 int numQueues = parseNumQueues(ns, conf);
 LOG.info("FairCallQueue is in use with " + numQueues + " queues.");
 this.queues = new ArrayList<BlockingQueue<E>>(numQueues);
 this.overflowedCalls = new ArrayList<AtomicLong>(numQueues);
 for(int i=0; i < numQueues; i++) {
  this.queues.add(new LinkedBlockingQueue<E>(capacity));
  this.overflowedCalls.add(new AtomicLong(0));
 }
 this.scheduler = new DecayRpcScheduler(numQueues, ns, conf);
 this.multiplexer = new WeightedRoundRobinMultiplexer(numQueues, ns, conf);
 // Make this the active source of metrics
 MetricsProxy mp = MetricsProxy.getInstance(ns);
 mp.setDelegate(this);
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Use the mux by getting and advancing index.
 */
public int getAndAdvanceCurrentIndex() {
 int idx = this.getCurrentIndex();
 this.advanceIndex();
 return idx;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

mux = new WeightedRoundRobinMultiplexer(1, "", new Configuration());
for(int i = 0; i < 10; i++) {
 assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
mux = new WeightedRoundRobinMultiplexer(2, "", new Configuration());
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
mux = new WeightedRoundRobinMultiplexer(3, "", new Configuration());
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
mux = new WeightedRoundRobinMultiplexer(4, "", new Configuration());
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);

代码示例来源:origin: io.hops/hadoop-common

/**
 * Advances the index, which will change the current index
 * if called enough times.
 */
private void advanceIndex() {
 // Since we did read, we should decrement
 int requestsLeftVal = this.requestsLeft.decrementAndGet();
 // Strict compare with zero (instead of inequality) so that if another
 // thread decrements requestsLeft, only one thread will be responsible
 // for advancing currentQueueIndex
 if (requestsLeftVal == 0) {
  // This is guaranteed to be called exactly once per currentQueueIndex
  this.moveToNextQueue();
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

public WeightedRoundRobinMultiplexer(int aNumQueues, String ns,
 Configuration conf) {
 if (aNumQueues <= 0) {
  throw new IllegalArgumentException("Requested queues (" + aNumQueues +
   ") must be greater than zero.");
 }
 this.numQueues = aNumQueues;
 this.queueWeights = conf.getInts(ns + "." +
  IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY);
 if (this.queueWeights.length == 0) {
  this.queueWeights = getDefaultQueueWeights(this.numQueues);
 } else if (this.queueWeights.length != this.numQueues) {
  throw new IllegalArgumentException(ns + "." +
   IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY + " must specify exactly " +
   this.numQueues + " weights: one for each priority level.");
 }
 this.currentQueueIndex = new AtomicInteger(0);
 this.requestsLeft = new AtomicInteger(this.queueWeights[0]);
 LOG.info("WeightedRoundRobinMultiplexer is being used.");
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

this.multiplexer = new WeightedRoundRobinMultiplexer(numQueues, ns, conf);

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

/**
 * Use the mux by getting and advancing index.
 */
public int getAndAdvanceCurrentIndex() {
 int idx = this.getCurrentIndex();
 this.advanceIndex();
 return idx;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

/**
 * Advances the index, which will change the current index
 * if called enough times.
 */
private void advanceIndex() {
 // Since we did read, we should decrement
 int requestsLeftVal = this.requestsLeft.decrementAndGet();
 // Strict compare with zero (instead of inequality) so that if another
 // thread decrements requestsLeft, only one thread will be responsible
 // for advancing currentQueueIndex
 if (requestsLeftVal == 0) {
  // This is guaranteed to be called exactly once per currentQueueIndex
  this.moveToNextQueue();
 }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com