跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Guava 的 RateLimiter warmup 慢启动限流,在这个例子中,永远无法达到最大值,一直处于限流状态
未分類
13 4 月 2020

Guava 的 RateLimiter warmup 慢启动限流,在这个例子中,永远无法达到最大值,一直处于限流状态

Guava 的 RateLimiter warmup 慢启动限流,在这个例子中,永远无法达到最大值,一直处于限流状态

資深大佬 : hujianxin 61

@RestController class HelloWorldController {     @GetMapping("/")     public String sayHello() {         return "hello world";     }      @GetMapping("/download")     public ResponseEntity<Resource> download() throws FileNotFoundException {         RateLimiter rateLimiter = GuavaRateLimiter.create(52428800L, 500, TimeUnit.MILLISECONDS)         FileInputStream in = new FileInputStream("/home/hujianxin/Downloads/officesp2010-kb2687455-fullfile-x64-en-us.exe");         InputStreamResource resource = new InputStreamResource(new InputStream() {             @Override             public int read() throws IOException {                 rateLimiter.acquire();                 return in.read();             }              @Override             public int read(byte[] b) throws IOException {                 rateLimiter.acquire(b.length);                 return in.read(b);             }              @Override             public int read(byte[] b, int off, int len) throws IOException {                 rateLimiter.acquire(len);                 return in.read(b, off, len);             }         });         return ResponseEntity.ok().body(resource);     } } 

在这个例子中,最大值是 50MB/S,但是实际速度只有 7M/s,如果移除限流相关代码,实际速度可以达到 200MB/s

有遇到过类似问题的大佬吗?

大佬有話說 (4)

  • 資深大佬 : inwar

    这个不是频率上线么?

  • 主 資深大佬 : hujianxin

    @inwar 请教,频率上线是什么意思呢?之前没听过

  • 資深大佬 : Jrue0011

    1L 的意思是 RateLimiter 一般用来限制每秒对接口的访问量吧,而不是每秒从 InputStream 流读取的字节数量

    create 不加入后两个参数能有效限制在 50MB/s 吗,能的话就看看是不是后面两个参数设置的问题。。。

  • 主 資深大佬 : hujianxin

    @Jrue0011 后面两个参数调过好多种了,对结果没有影响。。。

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具