{"id":99467,"date":"2020-04-13T08:28:08","date_gmt":"2020-04-13T00:28:08","guid":{"rendered":"http:\/\/4563.org\/?p=99467"},"modified":"2020-04-13T08:28:08","modified_gmt":"2020-04-13T00:28:08","slug":"guava-%e7%9a%84-ratelimiter-warmup-%e6%85%a2%e5%90%af%e5%8a%a8%e9%99%90%e6%b5%81%ef%bc%8c%e5%9c%a8%e8%bf%99%e4%b8%aa%e4%be%8b%e5%ad%90%e4%b8%ad%ef%bc%8c%e6%b0%b8%e8%bf%9c%e6%97%a0%e6%b3%95%e8%be%be","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=99467","title":{"rendered":"Guava \u7684 RateLimiter warmup \u6162\u542f\u52a8\u9650\u6d41\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6c38\u8fdc\u65e0\u6cd5\u8fbe\u5230\u6700\u5927\u503c\uff0c\u4e00\u76f4\u5904\u4e8e\u9650\u6d41\u72b6\u6001"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Guava \u7684 RateLimiter warmup \u6162\u542f\u52a8\u9650\u6d41\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6c38\u8fdc\u65e0\u6cd5\u8fbe\u5230\u6700\u5927\u503c\uff0c\u4e00\u76f4\u5904\u4e8e\u9650\u6d41\u72b6\u6001               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hujianxin <\/span>  <span><i><\/i> 61<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>@RestController class HelloWorldController {     @GetMapping(\"\/\")     public String sayHello() {         return \"hello world\";     }      @GetMapping(\"\/download\")     public ResponseEntity&lt;Resource&gt; 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);     } } <\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6700\u5927\u503c\u662f 50MB\/S\uff0c\u4f46\u662f\u5b9e\u9645\u901f\u5ea6\u53ea\u6709 7M\/s\uff0c\u5982\u679c\u79fb\u9664\u9650\u6d41\u76f8\u5173\u4ee3\u7801\uff0c\u5b9e\u9645\u901f\u5ea6\u53ef\u4ee5\u8fbe\u5230 200MB\/s<\/p>\n<p>\u6709\u9047\u5230\u8fc7\u7c7b\u4f3c\u95ee\u9898\u7684\u5927\u4f6c\u5417\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"742412\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : inwar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u4e0d\u662f\u9891\u7387\u4e0a\u7ebf\u4e48?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"742413\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : hujianxin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @inwar \u8bf7\u6559\uff0c\u9891\u7387\u4e0a\u7ebf\u662f\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u4e4b\u524d\u6ca1\u542c\u8fc7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"742414\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jrue0011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1L \u7684\u610f\u601d\u662f RateLimiter \u4e00\u822c\u7528\u6765\u9650\u5236\u6bcf\u79d2\u5bf9\u63a5\u53e3\u7684\u8bbf\u95ee\u91cf\u5427\uff0c\u800c\u4e0d\u662f\u6bcf\u79d2\u4ece InputStream \u6d41\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u91cf<\/p>\n<p>create \u4e0d\u52a0\u5165\u540e\u4e24\u4e2a\u53c2\u6570\u80fd\u6709\u6548\u9650\u5236\u5728 50MB\/s \u5417\uff0c\u80fd\u7684\u8bdd\u5c31\u770b\u770b\u662f\u4e0d\u662f\u540e\u9762\u4e24\u4e2a\u53c2\u6570\u8bbe\u7f6e\u7684\u95ee\u9898\u3002\u3002\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"742415\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : hujianxin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Jrue0011 \u540e\u9762\u4e24\u4e2a\u53c2\u6570\u8c03\u8fc7\u597d\u591a\u79cd\u4e86\uff0c\u5bf9\u7ed3\u679c\u6ca1\u6709\u5f71\u54cd\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Guava \u7684 RateLimit&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/99467"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99467"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/99467\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99467"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}