SlidingTimeWindowReservoir
/** * A {@link Reservoir} implementation backed by a sliding window that stores only the measurements made * in the last {@code N} seconds (or other time unit). */ public class SlidingTimeWindowReservoir implements Reservoir { // allow for this many duplicate ticks before overwriting measurements private static final int COLLISION_BUFFER = 256; // only trim on updating once every N private static final int TRIM_THRESHOLD = 256; private final Clock clock; private final ConcurrentSkipListMapConcurrentSkipListMap.headMapmeasurements; private final long window; private final AtomicLong lastTick; private final AtomicLong count; /** * Creates a new {@link SlidingTimeWindowReservoir} with the given window of time. * * @param window the window of time * @param windowUnit the unit of {@code window} */ public SlidingTimeWindowReservoir(long window, TimeUnit windowUnit) { this(window, windowUnit, Clock.defaultClock()); } /** * Creates a new {@link SlidingTimeWindowReservoir} with the given clock and window of time. * * @param window the window of time * @param windowUnit the unit of {@code window} * @param clock the {@link Clock} to use */ public SlidingTimeWindowReservoir(long window, TimeUnit windowUnit, Clock clock) { this.clock = clock; this.measurements = new ConcurrentSkipListMap (); this.window = windowUnit.toNanos(window) * COLLISION_BUFFER; this.lastTick = new AtomicLong(clock.getTick() * COLLISION_BUFFER); this.count = new AtomicLong(); } @Override public int size() { trim(); return measurements.size(); } @Override public void update(long value) { if (count.incrementAndGet() % TRIM_THRESHOLD == 0) { trim(); } measurements.put(getTick(), value); } @Override public Snapshot getSnapshot() { trim(); return new UniformSnapshot(measurements.values()); } private long getTick() { for (; ; ) { final long oldTick = lastTick.get(); final long tick = clock.getTick() * COLLISION_BUFFER; // ensure the tick is strictly incrementing even if there are duplicate ticks final long newTick = tick - oldTick > 0 ? tick : oldTick + 1; if (lastTick.compareAndSet(oldTick, newTick)) { return newTick; } } } private void trim() { measurements.headMap(getTick() - window).clear(); } }
public void update(long value) { if (count.incrementAndGet() % TRIM_THRESHOLD == 0) { trim(); } measurements.put(getTick(), value); } private void trim() { measurements.headMap(getTick() - window).clear(); }
返回key小于/等于指定值的部分,然后清除掉
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/66892.html
摘要:百分位數(shù)第百分位數(shù)是這樣一個(gè)值,它使得至少有的數(shù)據(jù)項(xiàng)小于或等于這個(gè)值,且至少有的數(shù)據(jù)項(xiàng)大于或等于這個(gè)值。即使極值變動(dòng)大,相比其他幾個(gè),還是比較接近實(shí)際數(shù)據(jù),曲線會(huì)有明顯變動(dòng),不像其他的一段時(shí)間可能都是平滑的。 基本概念 mean(平均值) 均值是就全部數(shù)據(jù)計(jì)算的,它具有優(yōu)良的數(shù)學(xué)性質(zhì),是實(shí)際中應(yīng)用最廣泛的集中趨勢(shì)測(cè)度值.其主要缺點(diǎn)是易受數(shù)據(jù)極端值的影響,對(duì)于偏態(tài)分布的數(shù)據(jù),均值的代表性...
摘要:?jiǎn)挝唤榻B既然扯到了這個(gè)單位,那就有必要先解釋下這個(gè)單位具體含義,上的解釋注意圖中的畫(huà)線部分,這個(gè)單位需要高版本的瀏覽器支持,不過(guò),一般用于移動(dòng)端布局,所以,基本上無(wú)需考慮瀏覽器版本問(wèn)題,放心用吧。相對(duì)于根元素的大小,自動(dòng)計(jì)算出其具體值。 A. 先看一個(gè)函數(shù): /* * 設(shè)置根元素字體大小 * @param Number minSW 最小縮放的設(shè)備屏幕寬度 * @param Nu...
摘要:需求控制編輯框上傳的圖片不超過(guò)。從文件中找到如下圖代碼位置,選取需要上傳的圖片,獲取圖片的大小,將其當(dāng)做新增參數(shù),給標(biāo)簽新增屬性。我的解決方法就是將在中加載出來(lái)的模態(tài)框中,關(guān)閉按鈕的屬性替換成代碼的事件,用來(lái)隱藏模態(tài)框,如下圖所示。 這里先看一下summernote.js模樣,如下圖,可以添加圖片、視頻、鏈接等。showImg(https://segmentfault.com/img/...
摘要:首先屏幕是由一個(gè)一個(gè)顯示單元組成的每一個(gè)顯示單元都是物理世界真實(shí)存在的把一個(gè)顯示單元的大小稱(chēng)為一個(gè)物理像素通常我們所說(shuō)的分辨率就是指一塊屏幕顯示單元的個(gè)數(shù)比如叉表示這塊屏幕由叉?zhèn)€顯示單元組成其次通常情況下個(gè)顯示單元對(duì)應(yīng)計(jì)算機(jī)系統(tǒng)中的也就是說(shuō) 首先 屏幕是由一個(gè)一個(gè)顯示單元組成的.1 每一個(gè)顯示單元都是物理世界真實(shí)存在的;2 把一個(gè)顯示單元的大小稱(chēng)為一個(gè)物理像素;3 通常我們所說(shuō)的 分辨...
閱讀 1648·2019-08-30 15:55
閱讀 973·2019-08-30 15:44
閱讀 866·2019-08-30 10:48
閱讀 2025·2019-08-29 13:42
閱讀 3179·2019-08-29 11:16
閱讀 1235·2019-08-29 11:09
閱讀 2053·2019-08-26 11:46
閱讀 611·2019-08-26 11:44