{"id":766,"date":"2022-06-25T09:44:54","date_gmt":"2022-06-25T01:44:54","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=766"},"modified":"2022-06-25T09:58:56","modified_gmt":"2022-06-25T01:58:56","slug":"%e5%8c%96%e7%b9%81%e4%b8%ba%e7%ae%80%e7%9a%84%e7%8a%b6%e6%80%81%e6%a8%a1%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=766","title":{"rendered":"\u5316\u7e41\u4e3a\u7b80\u7684\u72b6\u6001\u6a21\u5f0f"},"content":{"rendered":"<p>\u6700\u8fd1\u770b\u4e86\u540c\u4e8b\u5199\u7684\u4e00\u5757\u4ee3\u7801\uff0c\u903b\u8f91\u975e\u5e38\u590d\u6742\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5b9e\u73b0\u7684\u65b9\u5f0f\uff0c\u6211\u5efa\u8bae\u4ed6\u6539\u7528\u72b6\u6001\u6a21\u5f0f, \u8fd9\u6837\u53ef\u4ee5\u7701\u53bb\u5f88\u591a\u590d\u6742\u7684\u5224\u65ad\u5206\u652f<\/p>\n<p>\u8fd9\u662f\u7528\u72b6\u6001\u6a21\u5f0f\u7684\u505a\u6cd5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.fanyamin.com\/wordpress\/wp-content\/uploads\/2022\/06\/image-1656120957811.png\" alt=\"file\" \/><\/p>\n<p>\u4e0d\u7528\u72b6\u6001\u6a21\u5f0f\u7684\u4ee3\u7801\u5927\u81f4\u5982\u6b64<\/p>\n<pre><code>if(cpuRatio &lt; xxx &amp;&amp; memRatio &lt; xxx) {\n     state=Normal\n} else if(cpuRatio &gt; xxx &amp;&amp; memRatio &gt; xxx) {\n     state=Busy\n}\nelse if(cpuRatio &gt; xxx &amp;&amp; memRatio &gt; xxx) {\n     state=Crazy\n}\n\nif(state == Crazy) {\n     delegateOtherDoSomething()\n} else if (state == Busy) {\n     complainAndDoSomething()\n} else if (state == Normal) {\n     doSomething()\n} else {\n     doSomething();\n}\n<\/code><\/pre>\n<p>\u800c\u7528\u72b6\u6001\u6a21\u5f0f\u7684\u4ee3\u7801\u5927\u81f4\u5982\u6b64<\/p>\n<pre><code>newState = currentState.checkState();\nnewState.doSomething();\n<\/code><\/pre>\n<p>\u5f53\u7136\u6211\u7701\u7565\u4e86 checkState \u7684\u903b\u8f91\uff0c\u8be5\u505a\u7684\u4e8b\u5176\u5b9e\u5e76\u6ca1\u6709\u5c11\u591a\u5c11\uff0c\u4f46\u662f\u770b\u8d77\u6765\u6e05\u695a\u591a\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u770b\u4e86\u540c\u4e8b\u5199\u7684\u4e00\u5757\u4ee3\u7801\uff0c\u903b\u8f91\u975e\u5e38\u590d\u6742\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5b9e\u73b0\u7684\u65b9\u5f0f\uff0c\u6211\u5efa\u8bae\u4ed6\u6539\u7528\u72b6\u6001\u6a21\u5f0f, \u8fd9\u6837\u53ef\u4ee5\u7701\u53bb\u5f88\u591a\u590d\u6742\u7684\u5224\u65ad\u5206\u652f \u8fd9\u662f\u7528\u72b6\u6001\u6a21\u5f0f\u7684\u505a\u6cd5 \u4e0d\u7528\u72b6\u6001\u6a21\u5f0f\u7684\u4ee3\u7801\u5927\u81f4\u5982\u6b64 if(cpuRatio &lt; xxx &amp;&amp; memRatio &lt; xxx) { state=Normal } else if(cpuRatio &gt; xxx &amp;&amp; memRatio &gt; xxx) { state=Busy } else if(cpuRatio &gt; xxx &amp;&amp; memRatio &gt; xxx) { state=Crazy } if(state == Crazy) { delegateOtherDoSomething() } else if (state == Busy) { complainAndDoSomething() } else if (state == Normal) [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=766\" title=\"Permanent Link to: \u5316\u7e41\u4e3a\u7b80\u7684\u72b6\u6001\u6a21\u5f0f\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-766","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/766"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=766"}],"version-history":[{"count":4,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/766\/revisions"}],"predecessor-version":[{"id":771,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/766\/revisions\/771"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}