Giter VIP home page Giter VIP logo

ratelimiter's Introduction

限流器

1、概述:
基于令牌桶算法实现,实现qps限制。blog: http://www.liuyukang.com/archives/cppxianliuqi


2、特点:
(1)接口使用简单,无业务侵入,接入成本极低
(2)线程安全,CPU友好,性能强劲
(3)极轻量,核心代码150行


3、编译:
进入src,make之后即可生成libratelimiter.so。


4、使用:
example中提供示例,将libratelimiter.so放入/usr/lib/中后进入example,make即可生成可执行文件。下面这段代码将会执行5s:

int main()
{
    RateLimiter r(100);//100qps限流器

    for(int i = 0; i < 500; ++i)
    {
        r.pass();//通过的速率为100/s
    }

    return 0;
}

ratelimiter's People

Contributors

yukangliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ratelimiter's Issues

关于CacheLine的问题

  1. 为啥CacheLine 你代码里面写的是256?

  2. 为啥这里定义的时候,前后的大小是一致的?
    char _frontPadding[CACHELINE_PADDING_FOR_ATOMIC_INT64_SIZE];
    std::atomic_int64_t _seq;
    char _backPadding[CACHELINE_PADDING_FOR_ATOMIC_INT64_SIZE];

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.