{"id":10008067,"date":"2023-07-10T15:00:01","date_gmt":"2023-07-10T07:00:01","guid":{"rendered":"https:\/\/ityet.com\/?p=10008067"},"modified":"2023-07-10T15:00:01","modified_gmt":"2023-07-10T07:00:01","slug":"%e5%88%86%e6%9e%90-java-%e5%ba%94%e7%94%a8%e5%9c%a8-istio-%e4%b8%8b%e7%9a%84-warm-up","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008067","title":{"rendered":"\u5206\u6790 Java \u5e94\u7528\u5728 Istio \u4e0b\u7684 warm up"},"content":{"rendered":"<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8Jux\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h2>\u5206\u6790 Java \u5e94\u7528\u5728 Istio \u4e0b\u7684 warm up<\/h2>\n<h3>\u6545\u4e8b\u7684\u5f00\u59cb<\/h3>\n<p>\u5728\u5f88\u4e45\u5f88\u4e45\u524d\u7684\uff0c\u6709\u4e2a\u6d4b\u8bd5\u627e\u5230\u4e00\u4e2a\u5f00\u53d1\uff0c\u8bf4 k8s \u4e0b HPA(\u81ea\u52a8\u4f38\u7f29) \u65b0\u542f\u52a8\u7684 pod \u7684 api latency \u7279\u522b\u9ad8\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8Juz\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u9700\u8981\u6ce8\u610f\uff0c\u4e0a\u56fe\u662f\u5728 Java \u670d\u52a1\u63d0\u4f9b\u8005\u81ea\u8eab\u89c2\u5bdf\u5230\u7684 latency\uff0c\u5373\u89c2\u5bdf\u70b9\u662f\u670d\u52a1\u7684 server \u7aef\u6216\u8bf4 upstream \u3002\u6709\u540c\u5b66\u4f1a\u95ee\uff0c\u8fd9\u4e2a\u91cd\u8981\u5417\uff1f api latency \u5c31\u662f api latency \u4e86\uff0c\u8fd8\u8981\u7ba1\u662f\u4ec0\u4e48\u89c2\u5bdf\u70b9\u7684\u89c2\u5bdf\u7ed3\u679c\uff1f<\/p>\n<p>\u56e0\u4e3a\u5df2\u77e5\u662f server \u7aef\u7684\u89c2\u5bdf\u7ed3\u679c\uff0c\u90a3\u4e48\u5c31\u76f4\u63a5\u8c03\u67e5 server \u7aef\u4e86\u3002\u8fd9\u6b21\u8fd0\u6c14\u6bd4\u8f83\u597d\uff0c\u76f4\u63a5\u88ab\u544a\u77e5 server \u7aef cpu \u4f7f\u7528\u9ad8\u3002\u518d\u770b\u770b pod \u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"yaml\">        resources:\n          limits:\n            cpu: &quot;2&quot;\n            memory: 4Gi\n          requests:\n            cpu: &quot;2&quot;\n            memory: 4Gi<\/code><\/pre>\n<h3>\u8c03\u67e5<\/h3>\n<p>\u76f4\u89c9\u544a\u8bc9\u6211\uff0c\u662f CPU \u9650\u6d41(CPU Throttled)\u4e86\uff08\u8fd9\u4e2a\u76f4\u89c9\u662f\u4e24\u5e74\u524d\u82b1\u4e86\u4e00\u4e2a\u6708\u5728\u5751\u4e2d\u722c\u51fa\u6765\u540e\u5f62\u6210\u7684\uff0cGrafana Dashboard \u4e5f\u662f\u81ea\u5df1\u65b0\u624b\u9020\u7684\uff09\u3002\u4e0d\u5e78\u8a00\u4e2d\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuA\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u540c\u65f6\uff0c\u6ce8\u610f\u5230\u4e00\u4e2a\u73b0\u8c61\u662f\uff0c\u7ebf\u7a0b\u6570\u5728 pod \u542f\u52a8\u65f6\uff0c\u76f4\u7ebf\u62c9\u5347\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuB\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u597d\u4e86\uff0c\u95ee\u9898\u597d\u50cf\u5f88\u7b80\u5355\uff0c\u5c31\u770b\u4ec0\u4e48\u4efb\u52a1\u7528\u4e86\u90a3\u4e48\u591a cpu \uff0c\u6709\u4ec0\u4e48\u53ef\u4ee5\u4f18\u5316\u3002<\/p>\n<h3>\u8c01\u7684\u9505<\/h3>\n<p>\u6027\u80fd\u4f18\u5316\u6709\u4e2a\u57fa\u672c\u7406\u8bba\uff1a<\/p>\n<blockquote><p>\u5982\u679c\u4f60\u4e0d\u80fd\u62c6\u89e3<code>\u4e0d\u53ef\u63a7\u7684\u590d\u6742\u95ee\u9898<\/code>\u4e3a<code>\u53ef\u63a7\u7684\u7b80\u5355\u95ee\u9898<\/code>\uff0c\u90a3\u4e48\u8fd9\u4e2a\u4f18\u5316\u53ea\u80fd\u770b\u8fd0\u6c14\u3002<\/p><\/blockquote>\n<p>\u7528 ps \u62c6\u89e3\u8fdb\u7a0b\u5230\u7ebf\u7a0b\u662f\u4e00\u4e2a\u601d\u8def\u3002\u770b\u770b pod \u542f\u52a8\u671f\u95f4\u7684\u60c5\u51b5\uff1a<\/p>\n<pre><code class=\"bash\">export TZ='Asia\/Shanghai' ;\/\nrm \/tmp\/top-thread-$POD_NAME.log ;\/\nwhile true ; do \/\n  k exec $POD_NAME -- bash -c 'ps --sort=-%cpu  -L -o tid,state,%cpu,cputimes,cputime,nice,pri,comm,maj_flt,psr,policy,wchan -p `pgrep --newest java` | (read -r; printf &quot;%s\/n&quot; &quot;$REPLY&quot;; sort -k3rn -k4rn) | head -20 '  | awk '{ print strftime(&quot;%Y-%m-%d %H:%M:%S&quot;), $0; fflush(); }' | tee -a \/tmp\/top-thread-$POD_NAME.log ;\/\n  sleep 5s ;\/\ndone\n\n\n2023-07-06 21:43:02     TID S %CPU     TIME     TIME  NI PRI COMMAND          MAJFL PSR POL WCHAN\n2023-07-06 21:43:02  414573 R 39.2       50 00:00:50   0  19 C2 CompilerThre      1  26 TS  -\n2023-07-06 21:43:02  414494 S 17.8       23 00:00:23   0  19 java                 9  36 TS  futex_wait_queue\n2023-07-06 21:43:02  414574 R 14.8       19 00:00:19   0  19 C1 CompilerThre      3   2 TS  -\n2023-07-06 21:43:02  415310 R  2.4        2 00:00:02   0  19 s0-io-0              0  63 TS  -\n2023-07-06 21:43:02  415339 R  2.0        2 00:00:02   0  19 s0-io-3              0  65 TS  -\n2023-07-06 21:43:02  415311 R  1.9        2 00:00:02   0  19 s0-io-1              0  63 TS  -\n2023-07-06 21:43:02  415098 R  1.8        2 00:00:02   0  19 Thread-17            0  51 TS  -\n2023-07-06 21:43:02  415808 S  1.7        1 00:00:01   0  19 qtp2063581529-8      0  15 TS  futex_wait_queue\n2023-07-06 21:43:02  415901 S  1.7        1 00:00:01   0  19 qtp2063581529-1      0  72 TS  futex_wait_queue\n2023-07-06 21:43:02  415893 S  1.6        1 00:00:01   0  19 qtp2063581529-1      0  10 TS  do_sys_poll\n2023-07-06 21:43:02  414495 S  1.4        1 00:00:01   0  19 GC Thread#0          0  42 TS  futex_wait_queue\n2023-07-06 21:43:02  414498 S  1.4        1 00:00:01   0  19 GC Thread#1          0   5 TS  futex_wait_queue\n2023-07-06 21:43:02  415882 S  1.3        1 00:00:01   0  19 qtp2063581529-1      0  39 TS  do_sys_poll\n2023-07-06 21:43:02  415768 S  1.2        1 00:00:01   0  19 qtp2063581529-7      0  60 TS  futex_wait_queue\n2023-07-06 21:43:02  415109 R  1.1        1 00:00:01   0  19 Thread-18            1  53 TS  -\n2023-07-06 21:43:02  415892 S  1.1        1 00:00:01   0  19 qtp2063581529-1      0  68 TS  futex_wait_queue\n2023-07-06 21:43:02  415952 S  1.1        0 00:00:00   0  19 qtp2063581529-1      0  15 TS  futex_wait_queue\n2023-07-06 21:43:02  416066 S  1.1        0 00:00:00   0  19 qtp2063581529-2      0  78 TS  futex_wait_queue\n2023-07-06 21:43:02  415867 S  1.0        0 00:00:00   0  19 qtp2063581529-9      0   0 TS  futex_wait_queue\n...<\/code><\/pre>\n<p>\u5176\u4e2d <code>qtp2063581529-...<\/code> \u5c31\u662f\u8d1f\u8d23\u5904\u7406 api \u8bf7\u6c42\u7684\u7ebf\u7a0b\u3002\u90a3\u4e48 <code>C2 CompilerThre<\/code> \u662f\u4ec0\u4e48\uff1f\u5f53\u7136\u5c31\u662f Compiler threads \u4e86\u3002\u5730\u7403\u4eba\u90fd\u77e5\u9053\uff0cjava \u662f Just-In-Time (JIT) compiler \u7684\uff0c\u5c31\u662f\u8fb9\u8dd1\u8fb9\u4f18\u5316\u7f16\u8bd1\u3002JIT \u8fd9\u5757\u6211\u6700\u8fd1\u6574\u7406\u8fc7\u4e00\u4e9b\u7b14\u8bb0\uff0c\u89c1\uff1a <a href=\"https:\/\/link.segmentfault.com\/?enc=YHZxK8UF%2B9BizqlXkmHzQw%3D%3D.y3NlL3ZmI5mEpgnWU8%2FqAEJLK2UEzCaEMeOr9dhWkbuJ2B%2B36r3DO5BNpTmmn1a%2FJNFsT%2B4gkllT3Fu%2BDFn2wF%2BRjKH9IIAcCuVoJTmWiVI%3D\" rel=\"nofollow\">\u300aMark\u2019s DevOps \u96dc\u788e\u300b &#8211; Java Compile<\/a> \u3002<\/p>\n<h3>\u73af\u5883<\/h3>\n<p>Istio 1.17:<\/p>\n<ul>\n<li>\u5df2\u7ecf\u542f\u7528\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=jSUBY09bVvITbMjnQOouuA%3D%3D.A%2BIhlXgu0MYtTAuzazUrrdczMplcOz1RwNZKASbLPYXqkv7%2FXf59xeh%2F%2BGKD52cbTuXgloGjd%2FomeBa8Dfl2htpKvT3U8%2FDKyBPApuMlcuc%3D\" rel=\"nofollow\">warmupDurationSecs<\/a>  <code>warmupDurationSecs: 3m<\/code><\/li>\n<\/ul>\n<p>Open JDK 17<\/p>\n<h3>Tuning(\u8c03\u4f18) &#8211; Take 1<\/h3>\n<h4>Compiler Tuning<\/h4>\n<p>\u672c\u7740\u8c01\u7684\u9505\u8c01\u80cc\u7684\u539f\u5219\u3002\u8ba9 Compiler \u8fdf\u4e00\u70b9\u4f18\u5316\u7f16\u8bd1\uff0c\u907f\u514d\u5728\u542f\u52a8\u65f6\u4e0e\u5176\u5b83\u521d\u59cb\u5316\u4efb\u52a1\u4e89\u7528\u6709\u9650\u7684\u3001\u5bb9\u5668\u9650\u5236\u7684 2 cpus \u3002\u6210\u719f\u7684 Open JDK 17 \u5f53\u7136\u5df2\u7ecf\u63d0\u4f9b\u76f8\u5173\u53c2\u6570\u4e86\u3002\u8ba9\u6211\u4eec\u770b\u770b\uff1a<\/p>\n<blockquote><p>\u8be6\u7ec6\u53c2\u8003\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=E%2BO%2FY%2BVq%2Bj6t7NGitHW8Ww%3D%3D.hkrS%2FqC%2F8mVln39FwZJXZ2H4t9k2L%2FHLlm%2F5XWggbMYD7y8w3fZEsDbiWv7K6DZf30uRebCtf76WzdE22MywbZss7jy4AIoHzq6PgBWzfzHq3FMGPySMuoPkbnPWmvn1\" rel=\"nofollow\">\u300aMark\u2019s DevOps \u96dc\u788e\u300b &#8211; Java Compiler Tuning<\/a><\/p><\/blockquote>\n<p>\u9996\u5148\u6211\u4eec\u77e5\u9053\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cJVM \u662f\u5728\u5e94\u7528\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u6839\u636e\u4ee3\u7801\u7684\u4f7f\u7528\u60c5\u51b5(\u53ef\u6682\u65f6\u7b80\u5355\u89c6\u4e3a\u4ee3\u7801\u88ab\u6267\u884c\u7684\u6b21\u6570)\uff0c\u5206\u671f\u5206\u7ea7\u53bb\u4f18\u5316\u7f16\u8bd1\u7684\u3002\u6bcf\u4e00\u7ea7\uff0c\u90fd\u6709\u6bcf\u4e00\u7ea7\u7684\u51c6\u5165\u95e8\u69db\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuC\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<blockquote><p>source: <a href=\"https:\/\/link.segmentfault.com\/?enc=pDke6sOFgmob94R9d5KLoA%3D%3D.%2B8ldmZX5mBS3ze9iIwunE1h01AZHQGU7Vr1QQF2zQiqbQOCINosSW25LX7455yZ%2F\" rel=\"nofollow\">https:\/\/www.baeldung.com\/jvm-tiered-compilation<\/a><\/p><\/blockquote>\n<table>\n<thead>\n<tr>\n<th>Tier level\uff08\u7f16\u8bd1\u7ea7\u522b\uff09<\/th>\n<th>Meaning<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0<\/td>\n<td>The code has been interpreted<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>Simple C1 compilation<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Limited C1 compilation<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Full C1 compilation<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>C2 compilation<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>JVM \u63d0\u4f9b\u4e86\u4e00\u5806\u53c2\u6570\u53ef\u4ee5\u8c03\u6574\u51e0\u4e2a\u7f16\u8bd1\u5c42\u6b21\u7684\u95e8\u69db\uff0c\u5176\u9ed8\u8ba4\u503c\u4e3a\uff1a<\/p>\n<pre><code class=\"bash\">bash-4.4$ java -XX:+PrintFlagsFinal cp . Main  | grep -i Threshold\n     intx CompileThreshold                         = 10000                                  {pd product} {default}\n   double CompileThresholdScaling                  = 1.000000                                  {product} {default}\n     intx Tier3BackEdgeThreshold                   = 60000                                     {product} {default}\n     intx Tier3CompileThreshold                    = 2000                                      {product} {default}\n     intx Tier3InvocationThreshold                 = 200                                       {product} {default}\n     intx Tier3MinInvocationThreshold              = 100                                       {product} {default}\n     intx Tier4BackEdgeThreshold                   = 40000                                     {product} {default}\n     intx Tier4CompileThreshold                    = 15000                                     {product} {default}\n     intx Tier4InvocationThreshold                 = 5000                                      {product} {default}\n     intx Tier4MinInvocationThreshold              = 600                                       {product} {default}<\/code><\/pre>\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f\u63a8\u8fdf\u4f18\u5316\uff0c\u6240\u4ee5\u5c31\u662f\u52a0\u9ad8\u95e8\u69db\u4e86\u3002\u4e00\u4e2a\u4e2a\u53c2\u6570\u8c03\u6574\u6709\u70b9\u9ebb\u70e6\uff0c\u4e8e\u662f\uff0cJava \u8bbe\u8ba1\u4e86\u4e00\u4e2a\u603b\u7684\u95e8\u69db\u9ad8\u5ea6\u7cfb\u6570\uff1a<code>-XX:CompileThresholdScaling<\/code><\/p>\n<p>\u8bd5\u7740\u52a0\u5927\u8fd9\u4e2a\u7cfb\u6570\uff1a<\/p>\n<pre><code>bash-4.4$ java -XX:+PrintFlagsFinal -XX:CompileThresholdScaling=1.5 -cp . Main | grep -i Threshold                                                                \n     intx CompileThreshold                         = 15000                                  {pd product} {ergonomic}\n   double CompileThresholdScaling                  = 1.500000                                  {product} {command line}\n     intx Tier3BackEdgeThreshold                   = 90000                                     {product} {ergonomic}\n     intx Tier3CompileThreshold                    = 3000                                      {product} {ergonomic}\n     intx Tier3InvocationThreshold                 = 300                                       {product} {ergonomic}\n     intx Tier3MinInvocationThreshold              = 150                                       {product} {ergonomic}\n     intx Tier4BackEdgeThreshold                   = 60000                                     {product} {ergonomic}\n     intx Tier4CompileThreshold                    = 22500                                     {product} {ergonomic}\n     intx Tier4InvocationThreshold                 = 7500                                      {product} {ergonomic}\n     intx Tier4MinInvocationThreshold              = 900                                       {product} <\/code><\/pre>\n<h4>Compiler threads \u4f18\u5148\u7ea7<\/h4>\n<p>\u4e0a\u9762\u77e5\u9053\uff0c\u7f16\u8bd1\u7531\u4e13\u95e8\u7684 Compiler Thread \u8d1f\u8d23\uff0c\u7f16\u8bd1\u7ebf\u7a0b\u7684\u8fd0\u884c\u672c\u8eab\u5c31\u548c\u5e94\u7528  api \u5904\u7406\u7ebf\u7a0b\u4e89\u7528\u672c\u6765\u5c31\u7d27\u5f20\u7684 CPU \u8d44\u6e90\u3002\u6240\u4ee5\uff0c\u8fd8\u6709\u4e00\u4e2a\u601d\u8def\u662f\u964d\u4f4e\u7f16\u8bd1\u7ebf\u7a0b\u7684\u8c03\u5ea6\u4f18\u5148\u7ea7\u3002Java \u63d0\u4f9b\u4e86\u4e00\u4e2a\u53c2\u6570 <code>-XX:CompilerThreadPriority<\/code> \u53ef\u4ee5\u53bb\u8c03\u6574 Compiler Thread \u4f18\u5148\u7ea7\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5bf9\u4e8e\u975e root \u7528\u6237\u3002<code>-XX:CompilerThreadPriority=&lt;n&gt;<\/code> \u9700\u8981\u914d\u5408 <code>-XX:ThreadPriorityPolicy=1<\/code> \u4f7f\u7528\uff0c\u65b9\u53ef\u751f\u6548\u3002<\/p>\n<pre><code class=\"bash\">$ java -XX:CompilerThreadPriority=10 -XX:ThreadPriorityPolicy=1 -cp . Main\n\nOpenJDK 64-Bit Server VM warning: -XX:ThreadPriorityPolicy=1 may require system level permission, e.g., being the root user. If the necessary permission is not possessed, changes to priority will be silently ignored.\n\n$ ps --sort=-%cpu  -L -o tid,state,%cpu,cputimes,cputime,nice,pri,comm,maj_flt,psr,policy,wchan -p `pgrep --newest java` | (read -r; printf &quot;%s\/n&quot; &quot;$REPLY&quot;; sort -k3rn -k4rn) | head -20 '  | awk '{ print strftime(&quot;%Y-%m-%d %H:%M:%S&quot;), $0; fflush(); }\n\n2023-07-06 21:43:02     TID S %CPU     TIME     TIME  NI PRI COMMAND          MAJFL PSR POL WCHAN\n2023-07-06 21:43:02  414573 R 39.2       50 00:00:50   10 29 C2 CompilerThre      1  26 TS  -\n2023-07-06 21:43:02  414494 S 17.8       23 00:00:23   0  19 java                 9  36 TS  futex_wait_queue\n2023-07-06 21:43:02  414574 R 14.8       19 00:00:19   10 29 C1 CompilerThre      3   2 TS  -\n2023-07-06 21:43:02  415310 R  2.4        2 00:00:02   0  19 s0-io-0              0  63 TS  -\n2023-07-06 21:43:02  415339 R  2.0        2 00:00:02   0  19 s0-io-3              0  65 TS  -\n2023-07-06 21:43:02  415311 R  1.9        2 00:00:02   0  19 s0-io-1              0  63 TS  -\n2023-07-06 21:43:02  415098 R  1.8        2 00:00:02   0  19 Thread-17            0  51 TS  -\n2023-07-06 21:43:02  415808 S  1.7        1 00:00:01   0  19 qtp2063581529-8      0  15 TS  futex_wait_queue<\/code><\/pre>\n<p>Linux \u7684\u7ebf\u7a0b\u4f18\u5148\u7ea7\u53c2\u6570\u53eb Nice(NI)\uff0c\u5c31\u662f\u8c26\u8ba9\u7cfb\u6570\u7684\u610f\u601d\u7684\u3002\u5176\u5b9e\u662f\u6570\u5b57\u8d8a\u5c0f\uff0c\u8d8a\u4f18\u5148\u3002<\/p>\n<blockquote><p>\u8be6\u7ec6\u53c2\u8003\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=NNTd%2BczinSH1bjMG80G2kg%3D%3D.ETjZEAPgJRQZ9xUQwUeYfv6g9F4lljLQQRTHNkUehERuxDJVWFRb2ZGxy4z5Fu%2FG%2FkbX3IzGWXNIGN2pgEu5YxslpJk3zMxOjo%2BZvcA5bPI0s63GTwDY%2FHXM%2FoZObVp7\" rel=\"nofollow\">\u300aMark\u2019s DevOps \u96dc\u788e\u300b &#8211; Java Compiler Tuning<\/a><\/p><\/blockquote>\n<h4>Tuning &#8211; Take 1 \u7ed3\u679c<\/h4>\n<p>\u5728 java \u547d\u4ee4\u53c2\u6570\u52a0\u4e0a\uff1a<\/p>\n<pre><code>java -XX:CompilerThreadPriority=15 -XX:ThreadPriorityPolicy=1 -XX:CompileThresholdScaling=20<\/code><\/pre>\n<p>\u540e\uff0c\u770b\u770b\u7ed3\u679c\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuD\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuE\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u53ef\u89c1\uff0c\u8c03\u6574\u53c2\u6570\u4ee5\u540e\uff0c\u6709\u76f8\u5f53\u7684\u6539\u5584\uff0c\u867d\u7136\u8fd8\u662f\u6bd4\u8f83\u96be\u770b\u3002\u8fd9\u65f6\u5982\u679c\u67e5\u770b\u7f16\u8bd1\u7ebf\u7a0b\u7528\u7684 cpu \uff0c\u4f1a\u53d1\u73b0\u7684\u786e\u660e\u663e\u4e0b\u964d\u4e86\uff1a<\/p>\n<pre><code>$ ps --sort=-%cpu  -L -o tid,state,%cpu,cputimes,cputime,nice,pri,comm,maj_flt,psr,policy,wchan -p `pgrep --newest java` | (read -r; printf &quot;%s\/n&quot; &quot;$REPLY&quot;; sort -k3rn -k4rn) | head -20 '  | awk '{ print strftime(&quot;%Y-%m-%d %H:%M:%S&quot;), $0; fflush(); }\n\n2023-07-06 22:43:02     TID S %CPU     TIME     TIME  NI PRI COMMAND          MAJFL PSR POL WCHAN\n2023-07-06 22:43:02  414573 R 12.2       50 00:00:50   10 29 C2 CompilerThre      1  26 TS  -<\/code><\/pre>\n<h3>Tuning &#8211; Take 2<\/h3>\n<p>\u5404\u4f4d\u5e94\u8be5\u8fd8\u8bb0\u5f97\u524d\u9762\u8fd9\u56fe\uff0c\u7ebf\u7a0b\u6570\u5728 pod \u542f\u52a8\u65f6\uff0c\u76f4\u7ebf\u62c9\u5347\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuB\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u5982\u679c\u9650\u5236\u4e86\u5bb9\u5668\u53ea\u4f7f\u7528 2 cpus\uff0c\u4f46\u53c8\u7ed9 java web server \u7684 thread pool \u914d\u7f6e\u4e86\u6bd4\u8f83\u5927\u7684 max threads\u3002<\/p>\n<p>\u60f3\u50cf\u4e00\u4e0b\uff0c200 \u4e2a\u5e76\u53d1 api \u8bf7\u6c42\u8fc7\u6765\u4e86\u3002 java web server \u5f00\u4e86 200 \u7ebf\u7a0b\uff0c\u4ed6\u4eec\u4e4b\u524d\u5e76\u53d1\u4e89\u593a\u53ef\u601c\u7684 2 cpus\u3002\u5c31\u50cf  2022 \u5e74\u6bcf\u5929\u53d1\u751f\u7684\u4e8b\uff0c200 \u4e2a\u4eba\u53bb\u6392\u961f\u9a8c H\u00e9su\u0101n \ud83d\ude37\uff08\u4ec0\u4e48\uff0c\u4f60\u5c45\u7136\u5fd8\u8bb0\u4e86\uff1f\u4f60\u5e78\u798f\u4e86\uff09\u3002\u4e0d\u8fc7\u8fd9\u4e2a\u6bd4\u55bb\u4e0d\u592a\u8d34\u5207\uff0cCPU \u662f\u5206\u7247\u8c03\u5ea6\u7ebf\u7a0b\u7684\u3002\u4f46\u4ece http \u8bf7\u6c42\u7684\u89d2\u5ea6\u770b\uff0c\u5927\u5bb6\u90fd\u5728\u7b49\uff0cCPU \u4e5f\u5728\u5fd9\uff0c\u53ea\u662f\u628a\u6bcf\u4e2a http \u8bf7\u6c42\u7684\u4efb\u52a1\uff0c\u5206\u6210\u7ec6\u5c0f\u7684\u65f6\u95f4\u7247\u3002\u7136\u540e\u4e2d\u95f4\u201c\u968f\u610f\u201d\u63d2\u5165\u5176\u5b83 http \u8bf7\u6c42\u7684\u65f6\u95f4\u7247\u3002\u603b\u4e4b\uff0c\u6700\u540e\u662f\u6bcf\u4e2a http \u8bf7\u6c42\u90fd\u4e0d\u5f00\u5fc3\u3002\u6700\u5dee\u7684\u60c5\u51b5\u4e0b\uff0c downstream client \u5df2\u7ecf timeout \u4e86\uff0cCPU \u8fd8\u5728\u505a\u5df2\u7ecf\u65e0\u610f\u4e49\u7684\u5de5\u4f5c\u3002<\/p>\n<p>\u4e0d\u5982\u5f15\u5165\u51c6\u5165\u548c\u6392\u961f\u673a\u5236\uff0c\u8fd9\u6b63\u662f\u5927\u5e08\u53e3\u4e2d\u5e38\u541f\u8bf5\u7684 \u201cOverload control(\u8fc7\u8f7d\u4fdd\u62a4)\u201d\u3002\u8fd9\u5c31\u53ef\u4ee5\u8ba9\u5df2\u7ecf\u5165\u573a\u7684 http \u8bf7\u6c42\u5728 timeout \u524d\u5b8c\u6210\u3002\u800c\u573a\u5916\u7684 http \u8bf7\u6c42\uff0c\u8981\u4e48\u662f<strong>\u5728\u5185\u5b58\uff08\u800c\u975eCPU)\u4e0a\u6392\u961f<\/strong>\uff08\u5373\u7b49\u5f85\u7ebf\u7a0b\u6c60\u51fa\u73b0\u7a7a\u95f2\u7ebf\u7a0b\uff09\uff0c\u8981\u4e48\u5c31\u5206\u6d41\u53bb\u5176\u5b83  H\u00e9su\u0101n \u68c0\u6d4b\u70b9\uff08\u5176\u5b83\u5df2\u7ecf\u5b8c\u6210 warm up \u7684\u8001 POD\uff09\u3002<\/p>\n<p>\u8981\u5b9e\u73b0\u8fd9\u4e2a\u601d\u8def\uff0c\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u6211\u5148\u7528\u6700\u7b80\u5355\u7684 thread pool \u7ebf\u7a0b\u6c60\u9650\u5236\u3002\u51cf\u5c11 thread pool \u5927\u5c0f\uff0c\u7531 200 \u8c03\u6574\u4e3a  20 \u3002<\/p>\n<blockquote>\n<p>\u80cc\u538b\u673a\u5236(Backpressure) <\/p>\n<p>\u6ca1\u6709\u8003\u8651 Backpressure \u7684 Overload control \u4e0d\u662f\u597d\u7684 Overload control\u3002\u6211\u8fd9\u91cc\u5c31\u662f\u6682\u65f6\u672a\u8003\u8651\u4e86\u3002Backpressure \u5728\u8fd9\u4e2a\u573a\u666f\u4e2d\uff0c\u5c31\u662f\u6307\u5728 web server \u8fc7\u8f7d\u65f6\uff0cclient \u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u65b9\u6cd5\u611f\u77e5\u5230\uff0c\u5e76\u5728\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u4e2d\uff0c\u51cf\u5c11\u8fd9\u4e2a\u6709\u95ee\u9898 web server \u7684\u6d41\u91cf\u6743\u91cd\u3002<\/p>\n<\/blockquote>\n<h4>Tuning &#8211; Take 2 \u7ed3\u679c<\/h4>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuF\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuG\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u53ea\u770b\u8fd9\u4e2a Dashboard \u7684\u8bdd\uff0c\u7ed3\u679c\u662f\u4f18\u79c0\u7684\u3002\u4f46\u5982\u4e4b\u524d\u6240\u8bf4\uff0c\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e2a\u89c2\u5bdf\u70b9\u662f upstream http server \u7aef\u3002\u4f60\u6709\u770b\u770b downstream(client\uff0c\u5728 Istio \u573a\u666f\u4e0b\uff0c\u5c31\u662f\u548c http server \u540c\u4e00 pod \u7684 envoy istio-proxy sidecar) \u7684\u611f\u53d7\u5417\uff1f Backpressure \u505a\u5230\u4f4d\u4e86\u5417\uff1f\u8fd9\u4e2a\u7559\u7ed9\u4e0b\u56de\u5206\u89e3\u5427\u3002<\/p>\n<h3>Tuning &#8211; Take 3<\/h3>\n<p>\u5b9e\u5728\u60f3\u4e0d\u5230\uff0c\u5c45\u7136\u8fd8\u6709 take 3\u3002\u8bdd\u8bf4\uff0c\u4f60\u5e94\u8be5\u4e5f\u6709\u7c7b\u4f3c\u7684\u7ecf\u9a8c\u3002<strong>\u8001\u677f\u6216\u7ba1\u7406\u5c42\u603b\u5728\u8bf4\uff0c\u4f60\u4eec\u8fd9\u4e9b\u57fa\u5c42\u5458\u5de5\uff0c\u8981\u6709\u683c\u5c40<\/strong>\u3002\u90a3\u4e48\uff0c\u95ee\u9898\u6765\u4e86\uff0c\u4ec0\u4e48\u662f\u683c\u5c40\uff1f<\/p>\n<p>\u8001\u677f\u53ef\u80fd\u662f\u8fd9\u6837\u60f3\u7684\uff1a<\/p>\n<blockquote><p>\u505a\u4e8b\u6709\u5bbd\u5e7f\u7684\u89c6\u7ebf\uff0c\u4e0d\u53ea\u770b\u81ea\u5df1\u5c97\u4f4d\u7684\u4e00\u4ea9\u4e09\u5206\u5730\uff0c\u5168\u5c40\u770b\u4e8b\u60c5\uff0c\u4ee5\u4e8b\u4ef6\u7684\u7ed3\u679c\u6548\u76ca\u53bb\u6307\u5bfc\u5de5\u4f5c\u4e0a\u7684\u4e8b\uff0c\u800c\u4e0d\u53ea\u662f\u4e13\u624d\u3002<\/p><\/blockquote>\n<p>\u6211\u4f5c\u4e3a\u57fa\u5c42\u7801\u519c\u7684\u4e00\u4efd\u5b50\uff0c\u662f\u8fd9\u6837\u60f3\u7684\uff1a\uff08\u6ce8\u610f\uff0c\u8fd9\u6837\u60f3\u4e0d\u4ee3\u8868\u5c31\u8fd9\u6837\u8ba4\u540c\uff0c\u8fd9\u91cc\u60f3\u6cd5\u662f\u4e8b\u5b9e\uff0c\u8ba4\u540c\u662f\u7acb\u573a\uff0c\u6ce8\u610f\u5206\u6e05\u695a\u4e8b\u5b9e\u548c\u7acb\u573a\uff09<\/p>\n<blockquote><p>\u5ba2\u6237\u5728\u610f\u7684\u5176\u5b9e\u662f\u6210\u672c\u548c\u6536\u76ca\u3002\u4f60\u7528\u7684\u6280\u672f\u9ad8\u4f4e\uff0c\u6709\u6ca1\u4ec0\u4e48\u6280\u672f\u60c5\u6000\u6ca1\u4ec0\u4e48\u5173\u7cfb\u3002<\/p><\/blockquote>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c1k TPS\uff0c\u6309\u8fd9\u4e2a\u5e94\u7528\u7684\u5b9e\u73b0\u8bbe\u8ba1\u9700\u8981 20 \u4e2a cpu\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u5206 pod:<\/p>\n<ul>\n<li>10 pods\uff0c\u6bcf\u4e2a 2 cpus<\/li>\n<li>5 pods\uff0c\u6bcf\u4e2a 4 cpus<\/li>\n<\/ul>\n<p>10 pods \u548c 5 pods \u6709\u533a\u522b\u5417\uff1f\u8fd8\u771f\u6709\u3002<\/p>\n<p>10 pods \u610f\u5473\u7740\u540c\u4e00\u4e2a java class\u3002\u9700\u8981\u6267\u884c 10 \u6b21 JIT warm up\uff0c\u5c31\u662f 10 \u6b21 JIT warm up \u7528\u7684 cpu times\u3002 \u800c 5 pods \u53ea\u9700\u8981\u5927\u6982\u4e00\u534a\u3002\u5947\u5999\u7684\u662f\uff0c\u4e00\u822c\u5ba2\u6237\u4e0d\u4f1a\u5728\u610f\u4f60\u7684\u6bcf pod cpu \u6570\uff0c\u53ea\u770b\u603b\u8d44\u6e90\u3002<\/p>\n<p>\u8fd8\u6709\u53e6\u5916\u4e00\u79cd\u6280\u672f\u63a7\u53ef\u80fd\u53ef\u4ee5\u63a5\u53d7\u7684\u89e3\u91ca\u662f\uff1a\u73b0\u4ee3 jvm \u5728\u8bbe\u8ba1\u65f6\uff0c\u5df2\u7ecf\u662f\u4e3a\u591a cpu \u4f18\u5316\u8fc7\u7684\u30022 CPU \u4e0b\uff0c\u4f1a\u6709\u5404\u79cd\u540e\u53f0\u7ebf\u7a0b\u4e89\u7528 cpu \uff0c\u6700\u7ec8\u589e\u52a0\u4e1a\u52a1\u7ebf\u7a0b latency \u7684\u53ef\u80fd\u3002\u5982\u7f16\u8bd1\u548c GC\u3002<\/p>\n<p>\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuH\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuI\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuJ\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc8JuK\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<h3>\u7ed3\u8bed<\/h3>\n<p>\u6280\u672f\u6216\u8005\u6709\u51e0\u4e2a\u6240\u8c13\u7684\u5883\u754c\uff1a<\/p>\n<ol>\n<li>\u4e86\u89e3\u65b0\u540d\u8bcd\uff0c\u5b66\u4e60\u4e00\u4e9b\u7f51\u4e0a\u968f\u624b\u53ef\u5f97\u7684\u79d1\u8c31\uff0c\u505a\u4e00\u4e9b\u5c0f\u9879\u76ee\uff0c\u7528\u8fd9\u4e9b\u540d\u8bcd\u5237\u4eae\u81ea\u5df1\u7684\u540d\u7247<\/li>\n<li>\u4e86\u89e3\u8fd9\u4e1c\u897f\u7684\u5b9e\u73b0\u673a\u7406\u751a\u81f3\u6e90\u7801<\/li>\n<li>\u7075\u6d3b\u8fd0\u7528\u548c\u5b9a\u5236<\/li>\n<li>\u77e5\u9053\u5b83\u662f\u4e3a\u4f55\u800c\u6765\uff0c\u5c06\u53d1\u5c55\u5230\u54ea\u513f\u53bb<\/li>\n<li>\u4ec0\u4e48\u90fd\u4e0d\u61c2<\/li>\n<\/ol>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043988205\">https:\/\/segmentfault.com\/a\/1190000043988205<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u6790 Java \u5e94\u7528\u5728 Istio \u4e0b\u7684 warm up \u6545\u4e8b\u7684\u5f00\u59cb \u5728\u5f88\u4e45\u5f88\u4e45\u524d\u7684\uff0c\u6709\u4e2a\u6d4b\u8bd5\u627e\u5230\u4e00\u4e2a\u5f00\u53d1\uff0c\u8bf4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008067","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008067","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008067"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008067\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}