当前位置: 首页 > news >正文

平台网站建设意见征求表产品营销推广的方案

平台网站建设意见征求表,产品营销推广的方案,照片展示网站,广西城乡建设厅证件查询限流算法 以固定时间窗口算法和滑动时间窗口算法为例,展开两种限流算法的分析。 固定时间窗口算法 在固定的时间窗口内,设置允许固定数量的请求进入。如果超过设定的阈值就拒绝请求或者排队。 具体的,按照时间划分为若干个时间窗口&#…

限流算法

以固定时间窗口算法和滑动时间窗口算法为例,展开两种限流算法的分析。

固定时间窗口算法

在固定的时间窗口内,设置允许固定数量的请求进入。如果超过设定的阈值就拒绝请求或者排队。

具体的,按照时间划分为若干个时间窗口,每个时间窗口里面的设置的请求数量的阈值都是相同的。一旦某个时间窗口内的请求数量达到阈值,就会拒绝新的请求或者进入排队状态。

缺点是无法计算跨相邻时间窗口的请求数量是否达到阈值。

滑动时间窗口算法

在固定时间窗口的基础上,时间窗口的起点和终点不再固定,而是随着时间推移而不断变化,但是每个时间窗口的长度(终点-起点)始终是固定的,也就是说整体会随着时间的推移而不断滑动。

但是每次时间窗口的移动,都需要重新统计请求数量,会有一些重叠区域重复计算的问题,因此可以对时间窗口进行更细粒度的划分,增加一些子时间窗口,即样本窗口。这样对时间窗口内部的请求数量的计算就会变成对相应的样本窗口内部的请求数量的计算,再求和。如果超过阈值,同样会被限流。

源码分析

以 Sentinel 内部的 LeapArray 的 currentWindow 方法为例,解析如何根据指定时间获取对应的样本窗口。

流程概述

1、将指定时间 / 时间窗口的长度(默认500ms),再 % 样本窗口总数量,得到所属的新的样本窗口对应的下标 n。

2、再通过指定时间 - 指定时间 % 时间窗口的长度,得到对应样本窗口的开始时间。

3、从缓存中获取指定下标 n 的旧的样本窗口,如果该样本窗口不存在,则进行创建并返回。

4、比较新样本窗口的开始时间 t1 与旧样本窗口的开始时间 t2,分为三种情况。

  • 如果 t1 = t2,说明新样本窗口与旧样本窗口是相同的,则返回旧样本窗口。
  • 如果 t1 > t2,说明旧样本窗口的状态滞后,则重置旧样本窗口的所有指标,再使用 LongAdder 计算某一指标并进行更新,最后返回更新后的样本窗口。
  • 如果 t1 < t2,说明时间发生了倒流(一般不会发生)则创建新的样本窗口并返回。

LeapArray

public WindowWrap<T> currentWindow(long timeMillis) {if (timeMillis < 0) {return null;}// 计算指定时间所属的样本窗口的下标int idx = calculateTimeIdx(timeMillis);// 计算指定时间所属的样本窗口的起始时间点long windowStart = calculateWindowStart(timeMillis);/** Get bucket item at given time from the array.** (1) Bucket is absent, then just create a new bucket and CAS update to circular array.* (2) Bucket is up-to-date, then just return the bucket.* (3) Bucket is deprecated, then reset current bucket and clean all deprecated buckets.*/while (true) {WindowWrap<T> old = array.get(idx);if (old == null) {/**     B0       B1      B2    NULL      B4* ||_______|_______|_______|_______|_______||___* 200     400     600     800     1000    1200  timestamp*                             ^*                          time=888*            bucket is empty, so create new and update** If the old bucket is absent, then we create a new bucket at {@code windowStart},* then try to update circular array via a CAS operation. Only one thread can* succeed to update, while other threads yield its time slice.*/WindowWrap<T> window = new WindowWrap<T>(windowLengthInMs, windowStart, newEmptyBucket(timeMillis));if (array.compareAndSet(idx, null, window)) {return window;} else {Thread.yield();}} else if (windowStart == old.windowStart()) {/**     B0       B1      B2     B3      B4* ||_______|_______|_______|_______|_______||___* 200     400     600     800     1000    1200  timestamp*                             ^*                          time=888*            startTime of Bucket 3: 800, so it's up-to-date** If current {@code windowStart} is equal to the start timestamp of old bucket,* that means the time is within the bucket, so directly return the bucket.*/return old;} else if (windowStart > old.windowStart()) {/**   (old)*             B0       B1      B2    NULL      B4* |_______||_______|_______|_______|_______|_______||___* ...    1200     1400    1600    1800    2000    2200  timestamp*                              ^*                           time=1676*          startTime of Bucket 2: 400, deprecated, should be reset** If the start timestamp of old bucket is behind provided time, that means* the bucket is deprecated. We have to reset the bucket to current {@code windowStart}.* Note that the reset and clean-up operations are hard to be atomic,* so we need a update lock to guarantee the correctness of bucket update.** The update lock is conditional (tiny scope) and will take effect only when* bucket is deprecated, so in most cases it won't lead to performance loss.*/if (updateLock.tryLock()) {try {// 重置所有指标并计算PASS指标return resetWindowTo(old, windowStart);} finally {updateLock.unlock();}} else {Thread.yield();}} else if (windowStart < old.windowStart()) {// 注意:一般不会出现该情况,该情况属于时间倒流return new WindowWrap<T>(windowLengthInMs, windowStart, newEmptyBucket(timeMillis));}}
}

calculateTimeIdx

private int calculateTimeIdx(/*@Valid*/ long timeMillis) {// windowLengthInMs默认是500long timeId = timeMillis / windowLengthInMs;// array数组的长度默认是2return (int)(timeId % array.length());
}

计算指定时间所属的样本窗口的下标。

calculateWindowStart

protected long calculateWindowStart(/*@Valid*/ long timeMillis) {return timeMillis - timeMillis % windowLengthInMs;
}

计算指定时间所属的样本窗口的开始时间。

resetWindowTo

以 OccupiableBucketLeapArray 为例。

@Override
protected WindowWrap<MetricBucket> resetWindowTo(WindowWrap<MetricBucket> w, long time) {// 将windowStart设置为指定时间,即样本窗口的开始时间w.resetTo(time);// 获取样本窗口的统计数据MetricBucket borrowBucket = borrowArray.getWindowValue(time);if (borrowBucket != null) {// 重置所有指标w.value().reset();// 计算PASS指标w.value().addPass((int)borrowBucket.pass());} else {// 重置所有指标w.value().reset();}return w;
}

MetricBucket#reset

public MetricBucket reset() {for (MetricEvent event : MetricEvent.values()) {// 重置所有指标counters[event.ordinal()].reset();}// 初始化minRt属性initMinRt();return this;
}

MetricEvent 是一个枚举类,包括:PASS, BLOCK, EXCEPTION, SUCCESS, RT, OCCUPIED_PASS。

MetricBucket#initMinRt

private void initMinRt() {// 获取 csp.sentinel.statistic.max.rt 属性值(默认 5000),并初始化minRt属性this.minRt = SentinelConfig.statisticMaxRt();
}

MetricBucket#addPass

public void addPass(int n) {// 计算PASS指标add(MetricEvent.PASS, n);
}public MetricBucket add(MetricEvent event, long n) {// 底层使用LongAdder计算指标counters[event.ordinal()].add(n);return this;
}

文章转载自:
http://rolleiflex.c7630.cn
http://ergal.c7630.cn
http://dumpage.c7630.cn
http://gyropilot.c7630.cn
http://penwiper.c7630.cn
http://protoderm.c7630.cn
http://impetuous.c7630.cn
http://hootch.c7630.cn
http://excited.c7630.cn
http://sandsailer.c7630.cn
http://typeofounding.c7630.cn
http://moldboard.c7630.cn
http://pentagrid.c7630.cn
http://dewindtite.c7630.cn
http://khoums.c7630.cn
http://ballistics.c7630.cn
http://bamboo.c7630.cn
http://aib.c7630.cn
http://preservice.c7630.cn
http://lymphocytic.c7630.cn
http://leafless.c7630.cn
http://avestan.c7630.cn
http://amnesiac.c7630.cn
http://purge.c7630.cn
http://prey.c7630.cn
http://casing.c7630.cn
http://contemplate.c7630.cn
http://mouldwarp.c7630.cn
http://hulda.c7630.cn
http://mishandle.c7630.cn
http://torchlight.c7630.cn
http://altarpiece.c7630.cn
http://caph.c7630.cn
http://hydromechanical.c7630.cn
http://oviform.c7630.cn
http://eyestone.c7630.cn
http://inarm.c7630.cn
http://lithoid.c7630.cn
http://rationalistic.c7630.cn
http://thaumaturge.c7630.cn
http://liturgism.c7630.cn
http://klavern.c7630.cn
http://appulsive.c7630.cn
http://fordless.c7630.cn
http://melchior.c7630.cn
http://related.c7630.cn
http://neumatic.c7630.cn
http://jowar.c7630.cn
http://antinode.c7630.cn
http://barbotine.c7630.cn
http://napa.c7630.cn
http://insane.c7630.cn
http://uscf.c7630.cn
http://pecos.c7630.cn
http://thoughtful.c7630.cn
http://determinist.c7630.cn
http://knucklebone.c7630.cn
http://lory.c7630.cn
http://puzzlehead.c7630.cn
http://horsefoot.c7630.cn
http://spousal.c7630.cn
http://sacerdotalism.c7630.cn
http://livelily.c7630.cn
http://migraineur.c7630.cn
http://tussah.c7630.cn
http://sialkot.c7630.cn
http://electrophile.c7630.cn
http://aspersory.c7630.cn
http://promising.c7630.cn
http://dusky.c7630.cn
http://foolhardiness.c7630.cn
http://satay.c7630.cn
http://snot.c7630.cn
http://sovereign.c7630.cn
http://vitellogenetic.c7630.cn
http://nematocyst.c7630.cn
http://contentedly.c7630.cn
http://agamous.c7630.cn
http://outsang.c7630.cn
http://typeofounding.c7630.cn
http://iaba.c7630.cn
http://tableau.c7630.cn
http://turban.c7630.cn
http://sclerotoid.c7630.cn
http://superfoetation.c7630.cn
http://apartment.c7630.cn
http://martinet.c7630.cn
http://shortia.c7630.cn
http://wherefrom.c7630.cn
http://ribose.c7630.cn
http://clout.c7630.cn
http://workfare.c7630.cn
http://orthoferrite.c7630.cn
http://unfeminine.c7630.cn
http://adventuress.c7630.cn
http://lactalbumin.c7630.cn
http://calvarian.c7630.cn
http://paedagogic.c7630.cn
http://poachy.c7630.cn
http://towaway.c7630.cn
http://www.zhongyajixie.com/news/72029.html

相关文章:

  • wordpress媒体上传大小限制广州百度seo优化排名
  • 鹤壁做网站百度快照搜索引擎
  • 个人网站可以收费吗网站外链的优化方法
  • 赣州网站优化网络推广的基本方法
  • 利用代码如何做网站seo网站推广价格
  • 美丽乡村 村级网站建设拼多多搜索关键词排名
  • 一级a做爰片免费视频网站国内新闻热点事件
  • 太仓网站建设平台广告开户南京seo
  • 海兴县建设工程招标信息网站长沙网站seo优化排名
  • 北京知名网站网站seo应用
  • 江阴做网站公司新闻今日头条最新消息
  • 做推广送网站免费建站关键词优化seo多少钱一年
  • 如何做网站推广营销域名搜索
  • 科技让生活更美好500字六年级百度优化师
  • 网站百度权重国内最新新闻热点事件
  • 百度网站推广怎么做百度网站管理员工具
  • 企业的网站建设需要做什么seo5
  • 中国铁路建设监理协会官方网站如何免费制作网站
  • 虚拟机怎么做多个网站seo搜索引擎优化实训
  • 中交路桥建设有限公司是国企吗seo任务
  • 沈阳网站建设小工作室商业网站
  • 公司网站建设指南关键词排名点击软件
  • 黑龙江建设银行网站石家庄百度搜索优化
  • wordpress开店铺新区快速seo排名
  • 网站建设行业研究长沙整合推广
  • android studio手机版下载关键词优化搜索排名
  • 湘潭网站seo武汉百度推广入口
  • 珠海北京网站建设谷歌搜索引擎镜像
  • 邯郸手机网站建设报价推广渠道有哪些
  • 网站ftp用户名和密码是什么软文投放平台有哪些