Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The realization of 95-99 lines of internal calculation index in flink

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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, / /

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report