Coder Social home page Coder Social logo

ratemit's Introduction

ratemit

微服务常见的一个措施就是限流,下面主要整理一下常用的限流算法以及code。目前大抵算法分两类

  1. 常规桶类算法(令牌桶和漏桶),核心**就是三个核心变量,当前桶最大容量、固定时间内可以补充的token数、上次补充token时间。流程如下:

具体详见Eureka、guava 、Resilience4j、dubbo限流。

其中需要注意的两点

a、 桶的预热,就是没出桶是就有全部token还是怎么慢慢填充,具体详见guava

b、 guava属于预拿的,比如你可以先预拿1000个,后面的需要很长时间才能补充

c、 Resilience4j不提供tryAcquire,只能一个一个的拿

  1. 基于滑动窗口,核心**就是内置一个数组,比如1秒10个,则划分长度为10的数组,每个窗口有一个起始毫秒数,通过窗口滑动的方式记录。目前看到三种算法实现

a、阿里的sentinel(LeapArray)

b、springcloud hystricx旧版本(HystrixRollingNumber)

c、 rxjava time window()

需要注意的是:

  1. hystricx后期已经拥抱rxjava ,之前的HystrixRollingNumber已经被废弃了

具体详见 https://www.jianshu.com/p/2e36f0eb9d03

ratemit's People

Contributors

zhuyou1234 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.