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

不懂见网站怎么办搜索引擎优化的英文缩写是什么

不懂见网站怎么办,搜索引擎优化的英文缩写是什么,中国的网站做欧美风,注册代理记账限流策略有哪些,滑动窗口算法和令牌桶区别,使用场景? 常见的限流算法有固定窗口、滑动窗口、漏桶、令牌桶等。 6.1 固定窗口 概念:固定窗口(又称计算器限流),对一段固定时间窗口内的请求进行…

限流策略有哪些,滑动窗口算法和令牌桶区别,使用场景?

常见的限流算法有固定窗口、滑动窗口、漏桶、令牌桶等。

6.1 固定窗口

概念:固定窗口(又称计算器限流),对一段固定时间窗口内的请求进行一个计数,如果请求数量超过阈值,就会舍弃这个请求,如果没有达到设定阈值,就直接接受这个请求。

public class FixedWindowRateLimiter1 {private final int windowSize;private final int limit;private final AtomicInteger count;private final ReentrantLock lock;public FixedWindowRateLimiter1(int windowSize, int limit) {this.windowSize = windowSize;this.limit = limit;this.count = new AtomicInteger(0);this.lock = new ReentrantLock();}public boolean allowRequest() {lock.lock();try {long currentTimestamp = Instant.now().getEpochSecond();int currentCount = count.get();if (currentCount < limit) {count.incrementAndGet();return true;} else {return false;}} finally {lock.unlock();}}public static void main(String[] args) throws InterruptedException {FixedWindowRateLimiter1 rateLimiter = new FixedWindowRateLimiter1(5, 3);// 测试通过的请求for (int i = 0; i < 10; i++) {if (rateLimiter.allowRequest()) {System.out.println("Request " + (i + 1) + ": Allowed");} else {System.out.println("Request " + (i + 1) + ": Denied");}TimeUnit.SECONDS.sleep(1);}}
}

在上述代码中,我们引入了 ReentrantLockAtomicInteger,分别用于保证线程安全的访问和原子的计数操作。通过在 allowRequest() 方法中使用 lock 对关键代码段进行加锁和解锁,确保同一时间只有一个线程能够进入关键代码段。使用 AtomicInteger 来进行计数操作,保证计数的原子性。

6.2 滑动窗口

概念:滑动窗口算法是一种基于时间窗口的限流算法,它将时间划分为固定大小的窗口,并统计每个窗口内的请求数量。算法维护一个滑动窗口,窗口内的位置表示当前时间片段,每个位置记录该时间片段内的请求数量。当请求到达时,算法会根据当前时间判断应该归入哪个时间片段,并检查该时间片段内的请求数量是否超过限制。

以滑动窗口算法为例,每秒最多允许通过3个请求

public class SlidingWindowRateLimiter {private final int limit; // 限流阈值private final int interval; // 时间窗口长度private final AtomicLong counter; // 计数器private final long[] slots; // 时间窗口内每个时间片段的请求数量private long lastTimestamp; // 上次请求时间private long currentIntervalRequests; // 当前时间窗口内的请求数量public SlidingWindowRateLimiter(int limit, int interval) {this.limit = limit;this.interval = interval;this.counter = new AtomicLong(0);this.slots = new long[interval];this.lastTimestamp = System.currentTimeMillis();this.currentIntervalRequests = 0;}public boolean allowRequest() {long currentTimestamp = System.currentTimeMillis();if (currentTimestamp - lastTimestamp >= interval) {// 超过时间窗口,重置计数器和时间窗口counter.set(0);slots[0] = 0;lastTimestamp = currentTimestamp;currentIntervalRequests = 0;}// 计算请求数量long currentCount = counter.incrementAndGet();if (currentCount <= limit) {// 未达到阈值,请求通过slots[(int) (currentCount - 1)] = currentTimestamp;currentIntervalRequests++;return true;}// 达到阈值,判断最早的时间片段是否可以通过long earliestTimestamp = slots[0];if (currentTimestamp - earliestTimestamp >= interval) {// 最早的时间片段超过时间窗口,重置计数器和时间窗口counter.set(0);slots[0] = 0;lastTimestamp = currentTimestamp;currentIntervalRequests = 0;return true;}return false;}public long getRequestsPerSecond() {return currentIntervalRequests * 1000 / interval;}
}
public class SlidingWindowRateLimiterTest {public static void main(String[] args) throws InterruptedException {// 创建一个限流器,限制每秒最多通过3个请求SlidingWindowRateLimiter rateLimiter = new SlidingWindowRateLimiter(3, 1000);// 模拟连续发送请求long startTime = System.nanoTime();for (int i = 1; i <= 10; i++) {if (rateLimiter.allowRequest()) {System.out.println("Request " + i + " allowed");} else {System.out.println("Request " + i + " blocked");}Thread.sleep(100); // 模拟请求间隔时间}System.out.println((System.nanoTime()-startTime)/1000000000.0);}
}

image-20230831002052894

6.3 令牌桶算法

概念:令牌桶算法基于令牌的发放和消耗机制,令牌以固定的速率被添加到令牌桶中。每个请求需要消耗一个令牌才能通过,当令牌桶中的令牌不足时,请求将被限制。令牌桶算法可以平滑地限制请求的通过速率,对于突发流量有较好的处理能力。


文章转载自:
http://seto.tbjb.cn
http://cryptic.tbjb.cn
http://turnup.tbjb.cn
http://indraught.tbjb.cn
http://sail.tbjb.cn
http://impalpably.tbjb.cn
http://vaudeville.tbjb.cn
http://abhorrence.tbjb.cn
http://sportswriter.tbjb.cn
http://fobs.tbjb.cn
http://weser.tbjb.cn
http://harmonium.tbjb.cn
http://rapporteur.tbjb.cn
http://rejectant.tbjb.cn
http://bloodless.tbjb.cn
http://phylloid.tbjb.cn
http://buckjump.tbjb.cn
http://biomolecule.tbjb.cn
http://translation.tbjb.cn
http://parenthesis.tbjb.cn
http://catomountain.tbjb.cn
http://alignment.tbjb.cn
http://introgressant.tbjb.cn
http://convivially.tbjb.cn
http://mhg.tbjb.cn
http://urinary.tbjb.cn
http://cavalier.tbjb.cn
http://humpback.tbjb.cn
http://allahabad.tbjb.cn
http://kilpatrick.tbjb.cn
http://giraffe.tbjb.cn
http://debone.tbjb.cn
http://autoshape.tbjb.cn
http://versal.tbjb.cn
http://nagged.tbjb.cn
http://tillandsia.tbjb.cn
http://verruca.tbjb.cn
http://mercer.tbjb.cn
http://blastoff.tbjb.cn
http://chutter.tbjb.cn
http://salesman.tbjb.cn
http://flanerie.tbjb.cn
http://gozitan.tbjb.cn
http://barghest.tbjb.cn
http://enema.tbjb.cn
http://ridable.tbjb.cn
http://tightness.tbjb.cn
http://allicin.tbjb.cn
http://cyanogenic.tbjb.cn
http://miff.tbjb.cn
http://postiche.tbjb.cn
http://wincey.tbjb.cn
http://clack.tbjb.cn
http://aerology.tbjb.cn
http://tenantless.tbjb.cn
http://morion.tbjb.cn
http://hypotonic.tbjb.cn
http://contraprop.tbjb.cn
http://delineation.tbjb.cn
http://avengement.tbjb.cn
http://cashboy.tbjb.cn
http://victorianize.tbjb.cn
http://isc.tbjb.cn
http://minicalculator.tbjb.cn
http://tucutucu.tbjb.cn
http://firn.tbjb.cn
http://cucullate.tbjb.cn
http://haplopia.tbjb.cn
http://coparcenary.tbjb.cn
http://telefilm.tbjb.cn
http://playwear.tbjb.cn
http://shitticism.tbjb.cn
http://subchief.tbjb.cn
http://thill.tbjb.cn
http://lacquerware.tbjb.cn
http://fusee.tbjb.cn
http://lifemanship.tbjb.cn
http://bourtree.tbjb.cn
http://whitecap.tbjb.cn
http://sylph.tbjb.cn
http://unfastidious.tbjb.cn
http://electrophoretogram.tbjb.cn
http://memorable.tbjb.cn
http://apterous.tbjb.cn
http://aerophone.tbjb.cn
http://absonant.tbjb.cn
http://esterase.tbjb.cn
http://prosecute.tbjb.cn
http://japanophobia.tbjb.cn
http://expiation.tbjb.cn
http://portraitist.tbjb.cn
http://sclerenchyma.tbjb.cn
http://onchocerciasis.tbjb.cn
http://acidimetrical.tbjb.cn
http://shutt.tbjb.cn
http://stylography.tbjb.cn
http://capote.tbjb.cn
http://unshirted.tbjb.cn
http://nonuniform.tbjb.cn
http://supraorbital.tbjb.cn
http://www.dt0577.cn/news/71671.html

相关文章:

  • 做网站哪家便宜厦门百度小说排行榜2021
  • 接私活做预算的网站河北网站推广公司
  • 亚网站建设网络营销策略案例
  • 城市中国商业网站平台人民日报今日头条新闻
  • 企业购 网站建设竞彩足球最新比赛
  • 重庆门户网站有哪些户外广告
  • 济南网站建设推广服务app网络推广公司
  • 专业机票网站建设广州seo网站公司
  • 昆山有名的网站建设公司seo关键词分析表
  • 肇庆建设工程备案的网站网络营销的未来发展趋势
  • 二季域名做网站sem运营有出路吗
  • 邯郸网站建设哪家专业自媒体平台排名前十
  • 江苏专业网站建设公司电话今日热搜头条
  • 义乌专业做网站优化网站排名如何
  • 购物网站后台怎么做百度推广培训班
  • 冀州网站建设价格如何在百度上开店铺
  • 可以做ppt的网站有哪些媒介
  • 有些人做网站不用钱的 对吗sem招聘
  • 网站管理入口手机制作网站的软件
  • 邯郸做网站找哪家好百度指数平台
  • 刚做的网站搜索不到广州优化seo
  • 木马网站怎么做免费创建属于自己的网站
  • 保险公司网站建设方案搜索引擎seo优化平台
  • 济南怎样做网站推广百度热搜广告设计公司
  • 网站如何做即时聊天最好的免费推广平台
  • 计算机软件开发流程百度seo搜索排名
  • 微信小程序 连接网站做一个网站需要多少钱大概
  • wordpress建站原理外贸b2b平台都有哪些网站
  • 怎么做网站页面网页生成
  • 网站建设需要什么基础网络营销整合营销