The realization of 95-99 lines of internal calculation index in flink
In 15 years, a general API monitoring system was designed in an e-commerce company from zero. At that time, it only calculated the success rate + average time, and did not calculate the 75Magi 90th 95pm 99999 line. This time the unit needed it, so it prompted me to think about this question, asked the unit CAT maintenance staff, and roughly understood the calculation method, which was consistent with the article I published in the unit intranet BBS in July 18, so I wrote the following code directly.
PercentageCalculation.java
Package com.ymm.computation.udf.define;import org.apache.flink.table.functions.AggregateFunction;import org.slf4j.Logger;import org.slf4j.LoggerFactory;// batch calculation 95line similar data public class PercentageCalculation extends AggregateFunction {/ * / private static final long serialVersionUID = 4009559061130131166L; private static final Logger LOG = LoggerFactory .getLogger (PercentageCalculation.class); / / private static BlockingQueue GLOBAL_QUEUE = new LinkedBlockingQueue () @ Override public PercentageAccumulator createAccumulator () {return new PercentageAccumulator ();} public void accumulate (PercentageAccumulator accumulator, Object value) {accumulator.accumulate (value);} @ Override public Object getValue (PercentageAccumulator accumulator) {return accumulator.getValue ();} public void resetAccumulator (PercentageAccumulator acc) {acc = null;//help GC}}
PercentageAccumulator.java
Package com.ymm.computation.udf.define;import org.slf4j.Logger;import org.slf4j.LoggerFactoryThirty Universe! Do not use this class public class PercentageAccumulator {private static final Logger LOG = LoggerFactory. GetLogger (PercentageAccumulator.class); public final static double PERCENT_50 = 0.5; public final static double PERCENT_75 = 0.25; public final static double PERCENT_90 = 0.1; public final static double PERCENT_95 = 0.05; public final static double PERCENT_99 = 0.01for other parameters. Public final static double PERCENT_999 = 0.001; public final static double PERCENT_9999 = 0.0001; public final static int PERCENT_COUNT = 7 Private final static int [] SCALE = {/ 1, / 2, / 4 / / 8, / / 16, / / 32 / / 64, / / 128, / / 256 / / 512, / / 1024, / / 2048, / / 4096 / / 8192, / / 16384, / / 32768 / / 65536 / /} Private int [] countContainer = {/ 0, / /