@Test public void testParseThresholds() { Configuration conf = new Configuration(); scheduler = new DecayRpcScheduler(1, "", conf); assertEqualDecimalArrays(new double[]{}, scheduler.getThresholds()); scheduler = new DecayRpcScheduler(2, "", conf); assertEqualDecimalArrays(new double[]{0.5}, scheduler.getThresholds()); scheduler = new DecayRpcScheduler(3, "", conf); assertEqualDecimalArrays(new double[]{0.25, 0.5}, scheduler.getThresholds()); scheduler = new DecayRpcScheduler(4, "", conf); assertEqualDecimalArrays(new double[]{0.125, 0.25, 0.5}, scheduler.getThresholds()); conf = new Configuration(); conf.set("ns." + DecayRpcScheduler.IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY, "1, 10, 20, 50, 85"); scheduler = new DecayRpcScheduler(6, "ns", conf); assertEqualDecimalArrays(new double[]{0.01, 0.1, 0.2, 0.5, 0.85}, scheduler.getThresholds()); }
private static double[] parseThresholds(String ns, Configuration conf, int numQueues) { int[] percentages = conf.getInts(ns + "." + IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY); if (percentages.length == 0) { return getDefaultThresholds(numQueues); } else if (percentages.length != numQueues-1) { throw new IllegalArgumentException("Number of thresholds should be " + (numQueues-1) + ". Was: " + percentages.length); } double[] decimals = new double[percentages.length]; for (int i = 0; i < percentages.length; i++) { decimals[i] = percentages[i] / 100.0; } return decimals; }
DecayRpcScheduler implements RpcScheduler, DecayRpcSchedulerMXBean { private static double[] parseThresholds(String ns, Configuration conf, int numQueues) { int[] percentages = conf.getInts(ns + "." + IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY); if (percentages.length == 0) { return getDefaultThresholds(numQueues); } else if (percentages.length != numQueues-1) { throw new IllegalArgumentException("Number of thresholds should be " + (numQueues-1) + ". Was: " + percentages.length); } double[] decimals = new double[percentages.length]; for (int i = 0; i < percentages.length; i++) { decimals[i] = percentages[i] / 100.0; } return decimals; } }
DecayRpcScheduler implements RpcScheduler, DecayRpcSchedulerMXBean { private static double[] parseThresholds(String ns, Configuration conf, int numQueues) { int[] percentages = conf.getInts(ns + "." + IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY); if (percentages.length == 0) { return getDefaultThresholds(numQueues); } else if (percentages.length != numQueues-1) { throw new IllegalArgumentException("Number of thresholds should be " + (numQueues-1) + ". Was: " + percentages.length); } double[] decimals = new double[percentages.length]; for (int i = 0; i < percentages.length; i++) { decimals[i] = percentages[i] / 100.0; } return decimals; } DecayRpcScheduler(int numQueues, String ns, Configuration conf); }
DecayRpcScheduler implements RpcScheduler, DecayRpcSchedulerMXBean { private static double[] parseThresholds(String ns, Configuration conf, int numQueues) { int[] percentages = conf.getInts(ns + "." + IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY); if (percentages.length == 0) { return getDefaultThresholds(numQueues); } else if (percentages.length != numQueues-1) { throw new IllegalArgumentException("Number of thresholds should be " + (numQueues-1) + ". Was: " + percentages.length); } double[] decimals = new double[percentages.length]; for (int i = 0; i < percentages.length; i++) { decimals[i] = percentages[i] / 100.0; } return decimals; } DecayRpcScheduler(int numQueues, String ns, Configuration conf); @Override int getPriorityLevel(Schedulable obj); @VisibleForTesting double getDecayFactor(); @VisibleForTesting long getDecayPeriodMillis(); @VisibleForTesting double[] getThresholds(); @VisibleForTesting void forceDecay(); @VisibleForTesting Map<Object, Long> getCallCountSnapshot(); @VisibleForTesting long getTotalCallSnapshot(); int getUniqueIdentityCount(); long getTotalCallVolume(); String getSchedulingDecisionSummary(); String getCallVolumeSummary(); }
DecayRpcScheduler implements RpcScheduler, DecayRpcSchedulerMXBean { private static double[] parseThresholds(String ns, Configuration conf, int numQueues) { int[] percentages = conf.getInts(ns + "." + IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY); if (percentages.length == 0) { return getDefaultThresholds(numQueues); } else if (percentages.length != numQueues-1) { throw new IllegalArgumentException("Number of thresholds should be " + (numQueues-1) + ". Was: " + percentages.length); } double[] decimals = new double[percentages.length]; for (int i = 0; i < percentages.length; i++) { decimals[i] = percentages[i] / 100.0; } return decimals; } DecayRpcScheduler(int numQueues, String ns, Configuration conf); @Override int getPriorityLevel(Schedulable obj); @VisibleForTesting double getDecayFactor(); @VisibleForTesting long getDecayPeriodMillis(); @VisibleForTesting double[] getThresholds(); @VisibleForTesting void forceDecay(); @VisibleForTesting Map<Object, Long> getCallCountSnapshot(); @VisibleForTesting long getTotalCallSnapshot(); int getUniqueIdentityCount(); long getTotalCallVolume(); String getSchedulingDecisionSummary(); String getCallVolumeSummary(); static final String IPC_CALLQUEUE_DECAYSCHEDULER_PERIOD_KEY; static final long IPC_CALLQUEUE_DECAYSCHEDULER_PERIOD_DEFAULT; static final String IPC_CALLQUEUE_DECAYSCHEDULER_FACTOR_KEY; static final double IPC_CALLQUEUE_DECAYSCHEDULER_FACTOR_DEFAULT; static final String IPC_CALLQUEUE_DECAYSCHEDULER_THRESHOLDS_KEY; static final String DECAYSCHEDULER_UNKNOWN_IDENTITY; static final Log LOG; }