Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some questions about RateLimiter #3240

simonsfan opened this issue Aug 16, 2018 · 1 comment


None yet
4 participants
Copy link

commented Aug 16, 2018

hello , i use RateLimiter class in order to control too large concurrent request in my project like this:

public class RateLimitAop {

    private HttpServletResponse response;

    private RateLimiter rateLimiter = RateLimiter.create(5.0); //比如说,我这里设置"并发数"为5

    public void serviceLimit() {


    public Object around(ProceedingJoinPoint joinPoint) {
        Boolean flag = rateLimiter.tryAcquire();
        Object obj = null;
        try {
            if (flag) {
                obj = joinPoint.proceed();
                String result = JSONObject.fromObject(ResultUtil.success1(100, "网络繁忙")).toString();
                output(response, result);
        } catch (Throwable e) {
        System.out.println("flag=" + flag + ",obj=" + obj);
        return obj;

    public void output(HttpServletResponse response, String msg) throws IOException {
        ServletOutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
        } catch (IOException e) {
        } finally {

@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
public @interface RateLimitAspect {

public class TestController {
    public String test(){
        return ResultUtil.success1(1001, "success").toString();

when i use jemeter and use 20 threads to pressure this interface,i find my pressure test results always can get 6 concurrent request ,according to usage of guava rateLimiter , it should be 5, is it right ? why my result will be 6 ? hope someone who knows ratelimiter can give me a hand ,thank u very much!


This comment has been minimized.

Copy link

commented Aug 16, 2018

I think this is a question for Stack Overflow. If there turns out to be a bug, please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.