{"id":2007,"date":"2023-04-01T11:40:33","date_gmt":"2023-04-01T03:40:33","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2007"},"modified":"2023-04-07T10:38:49","modified_gmt":"2023-04-07T02:38:49","slug":"do-you-know-what-your-interface-qps-is","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/do-you-know-what-your-interface-qps-is\/","title":{"rendered":"\u9762\u8bd5\uff1a\u77e5\u9053\u4f60\u7684\u63a5\u53e3QPS\u662f\u591a\u5c11\u4e48\uff1f"},"content":{"rendered":"<h2>QPS\u662f\u4ec0\u4e48<\/h2>\n<p>\u6211\u4eec\u5148\u56de\u5fc6\u4e00\u4e0b\uff0cQPS\u7684\u6982\u5ff5\u5982\u4e0b\u6240\u793a:<\/p>\n<blockquote>\n<p>QPS\uff08Query Per Second\uff09\uff1a\u6bcf\u79d2\u8bf7\u6c42\u6570\uff0c\u5c31\u662f\u8bf4\u670d\u52a1\u5668\u5728\u4e00\u79d2\u7684\u65f6\u95f4\u5185\u5904\u7406\u4e86\u591a\u5c11\u4e2a\u8bf7\u6c42<\/p>\n<\/blockquote>\n<p><!-- more --><\/p>\n<p>\u90a3\u6211\u4eec\u600e\u4e48\u4f30\u51fa\u6bcf\u79d2\u949f\u80fd\u5904\u7406\u591a\u5c11\u8bf7\u6c42\u5462\uff1f<\/p>\n<p>OK\uff0c\u7528\u65e5\u5fd7\u6765\u4f30\u8ba1\uff01\u90a3\u65e5\u5fd7\u600e\u4e48\u8bb0\u5f55\u5462\uff0c\u7ec6\u5206\u4e0b\u6765\uff0c\u6709\u4e24\u79cd\u65b9\u5f0f\u3002<\/p>\n<h3>\u81ea\u5df1\u5728\u63a5\u53e3\u91cc\u8bb0\u5f55<\/h3>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u6307\u7684\u662f\u5728\u63a5\u53e3\u91cc\uff0c\u65e5\u5fd7\u8bb0\u5f55\u4e86\u80fd\u4f53\u73b0\u8be5\u63a5\u53e3\u7279\u6027\u7684\uff0c\u5e76\u5177\u6709\u552f\u4e00\u6027\u7684\u5b57\u7b26\u4e32\uff01<\/p>\n<pre><code class=\"language-java\">@RestController\n@RequestMapping(&quot;\/home&quot;)\npublic class IndexController {\n    \/\/\u7701\u7565\n    @RequestMapping(&quot;\/index&quot;)\n    String index() {\n        logger.info(&quot;AppBlog.CN&quot;);\n        return &quot;index&quot;;\n    }\n}<\/code><\/pre>\n<p>\u5047\u8bbe\u73b0\u5728\u6211\u8981\u7edf\u8ba1index\u8fd9\u4e2a\u63a5\u53e3\u7684QPS\uff01<\/p>\n<p>OK\uff0c\u4ec0\u4e48\u53eb\u80fd\u4f53\u73b0\u8be5\u63a5\u53e3\u7279\u6027\u7684\u5b57\u7b26\u4e32\u5462\uff01\u5c31\u50cf\u4e0a\u9762\u7684<code>AppBlog.CN<\/code>\u8fd9\u4e2a\u5b57\u7b26\u4e32\uff0c\u53ea\u5728index\u8fd9\u4e2a\u63a5\u53e3\u91cc\u51fa\u73b0\u8fc7\uff0c\u6ca1\u5728\u5176\u4ed6\u5176\u4ed6\u63a5\u53e3\u91cc\u51fa\u73b0\u8fc7\uff01\u56e0\u6b64\uff0c\u53ea\u8981\u7edf\u8ba1\u51fa<code>AppBlog.CN<\/code>\u8fd9\u4e2a\u5b57\u7b26\u4e32\u5728\u65e5\u5fd7\u91cc\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u5c31\u80fd\u77e5\u9053\u8be5\u63a5\u53e3\u7684\u8bf7\u6c42\u6b21\u6570\uff01<\/p>\n<p>\u4ec0\u4e48\u53eb\u5177\u6709\u552f\u4e00\u6027\u7684\u5b57\u7b26\u4e32\u5462\uff01\u6240\u8c13\u552f\u4e00\u6027\uff0c\u6307\u7684\u662f<code>AppBlog.CN<\/code>\u8fd9\u4e2a\u5b57\u7b26\u4e32\uff0c\u5728\u8fd9\u4e2a\u63a5\u53e3\u7684\u4e00\u6b21\u8c03\u7528\u6d41\u7a0b\u4e2d\uff0c\u53ea\u51fa\u73b0\u4e00\u6b21\uff01\u5982\u679c\u51fa\u73b0\u4e24\u6b21\uff0c\u5c31\u4f1a\u5bfc\u81f4\u5230\u65f6\u5019\u7edf\u8ba1\u51fa\u6765\u7684\u6b21\u6570\u4f1a\u591a\u4e00\u500d\uff0c\u6240\u4ee5\u5c3d\u91cf\u9009\u62e9\u5177\u6709\u552f\u4e00\u6027\u7684\u5b57\u6bb5\uff01<\/p>\n<h3>\u5229\u7528tomcat\u7684access log<\/h3>\n<p>\u5982\u679c\u65e5\u5fd7\u91cc\u6ca1\u6709\u4e0a\u9762\u63d0\u5230\u7684\u5b57\u6bb5\u3002OK\uff0c\u90a3\u5c31\u4f7f\u7528tomcat\u81ea\u5e26\u7684access log\u529f\u80fd\u5427\uff01<\/p>\n<p>Tomcat\u6307\u5b9a\u4e0b\u9762\u4e24\u4e2a\u5c5e\u6027\u5373\u53ef<\/p>\n<pre><code class=\"language-bash\">server.tomcat.accesslog.directory  #\u8bbe\u5b9alog\u7684\u76ee\u5f55\uff0c\u9ed8\u8ba4: logs\n\nserver.tomcat.accesslog.enabled  #\u662f\u5426\u5f00\u542faccess log\uff0c\u9ed8\u8ba4: false<\/code><\/pre>\n<p>\u6b64\u65f6\uff0c\u8bbf\u95ee\u4e00\u6b21\/home\/index\u5730\u5740\uff0c\u4f1a\u6709\u4e0b\u9762\u8fd9\u6837\u65e5\u5fd7<\/p>\n<pre><code class=\"language-bash\">127.0.0.1 - - [19\/Aug\/2019:23:55:27 +0800] &quot;POST \/home\/index HTTP\/1.1&quot; 200 138<\/code><\/pre>\n<p>\u90a3\u4e48\uff0c\u5c31\u53ef\u4ee5\u6839\u636e\u65e5\u5fd7\u4e2d\uff0c\u8be5\u8bb0\u5f55\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u7edf\u8ba1index\u63a5\u53e3\u7684QPS<\/p>\n<h2>\u5b9e\u6218<\/h2>\n<p>\u5047\u8bbe\uff0c\u65e5\u5fd7\u5df2\u7ecf\u62ff\u5230\u624b\u4e86\uff0c\u540d\u5b57\u4e3axxx.log\u3002\u65e5\u5fd7\u5185\u5bb9\u5982\u4e0b<\/p>\n<pre><code class=\"language-bash\">\/\/\u7701\u7565\uff0c\u90fd\u957f\u5dee\u4e0d\u591a\uff0c\u8d34\u5176\u4e2d\u4e00\u6761\u5c31\u884c\n0:0:0:0:0:0:0:1 - - [27\/Dec\/2018:20:41:57 +0800] &quot;GET \/appblog\/upload.do HTTP\/1.1&quot; 404 949 http-bio-8080-exec-5 43<\/code><\/pre>\n<p>\u8fd9\u4e2a\u65f6\u5019\uff0c\u6267\u884c\u4e00\u4e32\u547d\u4ee4\u957f\u4e0b\u9762\u8fd9\u6837\u7684\uff0c\u8fdb\u884c\u7edf\u8ba1\u5373\u53ef<\/p>\n<pre><code class=\"language-bash\">cat xx.log |grep &#039;GET \/appblog&#039;|cut -d &#039; &#039; -f4|uniq -c|sort -n -r<\/code><\/pre>\n<p>\u51fa\u6765\u7b49\u7ed3\u679c\u5c31\u662f<\/p>\n<pre><code class=\"language-bash\">2 [27\/Dec\/2018:20:40:22\n1 [27\/Dec\/2018:20:47:58\n1 [27\/Dec\/2018:20:47:42\n1 [27\/Dec\/2018:20:41:57<\/code><\/pre>\n<p>\u7136\u540e\u5c31\u77e5\u9053\uff0c\u539f\u6765\u572820:40:22\uff0c\u8fd9\u4e2a\u63a5\u53e3\u7684QPS\u6700\u9ad8\uff0c\u8fbe\u5230\u4e86\u60ca\u4eba\u76842QPS\uff01<\/p>\n<ul>\n<li><code>cat xxx.log<\/code>\uff1a\u8bfb\u6587\u4ef6\u5185\u5bb9<\/li>\n<li><code>grep &#039;GET \/appblog&#039;<\/code>\uff1a\u5c06\u6587\u4ef6\u5185\u5bb9\u6309\u7167<code>GET \/appblog<\/code>\u8fdb\u884c\u8fc7\u6ee4<\/li>\n<li><code>cut -d &#039; &#039; -f4<\/code>\uff1a\u8fc7\u6ee4\u51fa\u6765\u7684\u5185\u5bb9\u6309\u7167\u7a7a\u683c\u8fdb\u884c\u5206\u5272\uff0c\u53d6\u7b2c\u56db\u5217\u5185\u5bb9<\/li>\n<li><code>uniq -c<\/code>\uff1a\u6bcf\u5217\u65c1\u8fb9\u663e\u793a\u8be5\u884c\u91cd\u590d\u51fa\u73b0\u7684\u6b21\u6570<\/li>\n<li><code>sort -n -r<\/code>\uff1a\u4f9d\u7167\u6570\u503c\u7684\u5927\u5c0f\u6392\u5e8f<\/li>\n<\/ul>\n<p>\u90a3\u4e48\uff0c\u5982\u679c\u662f\u5176\u4ed6\u65e5\u5fd7\u683c\u5f0f\uff0c\u65e0\u5916\u4e4ecut\u8bed\u53e5\u7684\u5904\u7406\u4e0d\u540c\u800c\u5df2\uff0c\u9053\u7406\u7c7b\u4f3c\uff01\u6b64\u6cd5\u53ef\u4ee5\u4f30\u7b97\u51fa\u5355\u673a\u7684\u67d0\u63a5\u53e3\u7684QPS\u662f\u591a\u5c11\uff01<\/p>\n<h2>\u4f30\u7b97<\/h2>\n<p>\u6211\u4eec\u73b0\u5728\u4f30\u8ba1\u51fa\u4e86\u5355\u673a\u7684QPS\u3002\u63a5\u4e0b\u6765\uff0c\u4f30\u7b97\u96c6\u7fa4\u7684QPS\u3002\u8fd9\u5c31\u8981\u6839\u636e\u8d1f\u8f7d\u5747\u8861\u7684\u7b56\u7565\u6765\u4f30\u8ba1\uff01<br \/>\n\u6bd4\u5982\uff0c\u90e8\u7f72\u4e8632\u53f0\u673a\u5668\uff0c\u8d1f\u8f7d\u5747\u8861\u7684\u7b56\u7565\u6070\u5de7\u4e3a\u8f6e\u8be2\uff0c\u90a3\u96c6\u7fa4\u7684QPS\u5c31\u662f\u5355\u673a\u7684QPS\u4e5832\u5373\u53ef\u3002<br \/>\n\u6240\u4ee5\uff0c\u6839\u636e\u5177\u4f53\u7684\u7b56\u7565\uff0c\u6765\u4f30\u8ba1\u6574\u4e2a\u96c6\u7fa4\u7684QPS\u591a\u5927\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>QPS\u662f\u4ec0\u4e48 \u6211\u4eec\u5148\u56de\u5fc6\u4e00\u4e0b\uff0cQPS\u7684\u6982\u5ff5\u5982\u4e0b\u6240\u793a: QPS\uff08Query Per Second\uff09\uff1a\u6bcf\u79d2\u8bf7\u6c42\u6570\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[97],"tags":[510],"class_list":["post-2007","post","type-post","status-publish","format-standard","hentry","category-tools-skills","tag-qps"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2007"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2007\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}