{"id":7818,"date":"2026-08-20T04:10:40","date_gmt":"2026-08-19T20:10:40","guid":{"rendered":"https:\/\/www.babel.cc\/blog\/?p=7818"},"modified":"2026-08-20T04:10:40","modified_gmt":"2026-08-19T20:10:40","slug":"%e4%bc%81%e4%b8%9a%e6%b0%b8%e5%8a%a8%e6%9c%ba%e7%9b%91%e6%8e%a7%e8%84%9a%e6%9c%ac%e6%80%bb%e6%8a%a5%e8%ad%a6%e4%bb%bb%e5%8a%a1%e5%86%b7%e5%86%bb%ef%bc%9f%e5%85%88%e6%a3%80%e6%9f%a5%e4%bd%a0","status":"publish","type":"post","link":"https:\/\/www.babel.cc\/blog\/?p=7818","title":{"rendered":"\u4f01\u4e1a\u6c38\u52a8\u673a\u76d1\u63a7\u811a\u672c\u603b\u62a5\u8b66&#8221;\u4efb\u52a1\u51b7\u51bb&#8221;\uff1f\u5148\u68c0\u67e5\u4f60\u6709\u6ca1\u6709\u628a ts \u5f53\u5b57\u7b26\u4e32\u6bd4\u8f83"},"content":{"rendered":"<p>\u4f01\u4e1a\u6c38\u52a8\u673a\u76d1\u63a7\u811a\u672c\u603b\u62a5\u8b66&quot;\u4efb\u52a1\u51b7\u51bb&quot;\uff1f\u5148\u68c0\u67e5\u4f60\u6709\u6ca1\u6709\u628a ts \u5f53\u5b57\u7b26\u4e32\u6bd4\u8f83<\/p>\n<p>\u4f01\u4e1a\u4e91\u76d8\u548c\u79c1\u6709\u5316\u90e8\u7f72\u7684\u56e2\u961f\uff0c\u5e38\u4f1a\u642d\u5efa\u4e00\u5957\u81ea\u52a8\u5316\u4efb\u52a1\u76d1\u63a7\u7cfb\u7edf\uff0c\u7528\u6765\u68c0\u6d4b\u5173\u952e\u8fdb\u7a0b\u662f\u5426\u8fd8\u6d3b\u7740\u3001\u4efb\u52a1\u961f\u5217\u6709\u6ca1\u6709\u5361\u4f4f\u3002\u8fd9\u5957\u7cfb\u7edf\u8fd0\u884c\u4e45\u4e86\uff0c\u5076\u5c14\u4f1a\u51fa\u73b0\u4e00\u4e2a\u5947\u602a\u73b0\u8c61\uff1a\u660e\u660e\u6240\u6709\u8fdb\u7a0b\u90fd\u5728\u6b63\u5e38\u8dd1\uff0c\u76d1\u63a7\u811a\u672c\u5374\u6301\u7eed\u62a5\u8b66&quot;\u4efb\u52a1\u51b7\u51bb&quot;\uff08task frozen\uff09\u3002\u53cd\u590d\u6392\u67e5\u8fdb\u7a0b\u65e5\u5fd7\u3001\u5185\u5b58\u3001\u7f51\u7edc\u5ef6\u8fdf\uff0c\u6700\u540e\u53d1\u73b0\u6839\u56e0\u662f\u4e00\u4e2a\u6781\u5bb9\u6613\u88ab\u5ffd\u7565\u4f4e\u7ea7\u9519\u8bef\u2014\u2014\u628a Unix \u65f6\u95f4\u6233\u5f53\u4f5c\u5b57\u7b26\u4e32\u5728\u6bd4\u8f83\u3002<\/p>\n<p>\u8fd9\u4e2a\u9519\u8bef\u5728 Node.js\u3001Python\u3001Shell \u811a\u672c\u91cc\u90fd\u53ef\u80fd\u51fa\u73b0\uff0c\u5c24\u5176\u5728\u56e2\u961f\u4ea4\u63a5\u3001\u7ef4\u62a4\u811a\u672c\u91cd\u6784\u65f6\u9ad8\u53d1\u3002\u672c\u6587\u4ece\u6839\u56e0\u5206\u6790\u51fa\u53d1\uff0c\u62c6\u89e3\u8fd9\u4e2a\u6bd4\u8f83\u64cd\u4f5c\u7684\u5e38\u89c1\u5199\u6cd5\u3001\u4e3a\u4f55\u5b57\u7b26\u4e32\u6bd4\u8f83\u4f1a\u51fa\u9519\uff0c\u4ee5\u53ca\u5982\u4f55\u7528\u6b63\u786e\u7684\u65b9\u5f0f\u4fee\u590d\u3002<\/p>\n<p>\u4e00\u3001\u95ee\u9898\u7684\u5178\u578b\u75c7\u72b6<\/p>\n<p>\u5148\u8bf4\u51e0\u4e2a\u5b9e\u9645\u573a\u666f\uff0c\u5e2e\u4f60\u5224\u65ad\u81ea\u5df1\u662f\u4e0d\u662f\u8e29\u4e86\u8fd9\u4e2a\u5751\uff1a<\/p>\n<p>\u76d1\u63a7\u811a\u672c\u6bcf\u5206\u949f\u8dd1\u4e00\u6b21\uff0c\u4f46&quot;\u4efb\u52a1\u51b7\u51bb&quot;\u544a\u8b66\u4e00\u76f4\u5b58\u5728\uff0c\u65e5\u5fd7\u91cc\u770b\u5230\u7684\u4efb\u52a1\u72b6\u6001\u662f RUNNING\uff0c\u8fdb\u7a0b\u4e5f\u6ca1\u6302\u3002\u68c0\u67e5\u544a\u8b66\u9608\u503c\u8bbe\u7f6e\uff1a\u51b7\u51bb\u65f6\u95f4\u7a97\u53e3 300 \u79d2\uff085 \u5206\u949f\uff09\uff0c\u8d85\u8fc7 300 \u79d2\u6ca1\u6709\u5fc3\u8df3\u5c31\u544a\u8b66\u3002\u65e5\u5fd7\u91cc\u4efb\u52a1\u6700\u540e\u4e00\u6b21\u5fc3\u8df3\u7684\u65f6\u95f4\u6233\u662f 1783207553748\uff08Unix \u6beb\u79d2\uff09\uff0c\u5f53\u524d\u65f6\u95f4\u6233\u662f 1783207600000\uff0c\u4e24\u8005\u5dee\u503c 46252 \u6beb\u79d2\uff08\u7ea6 46 \u79d2\uff09\uff0c\u8fdc\u672a\u8fbe\u5230 300 \u79d2\u9608\u503c\u2014\u2014\u4f46\u544a\u8b66\u504f\u504f\u89e6\u53d1\u4e86\u3002<\/p>\n<p>\u66f4\u8be1\u5f02\u7684\u573a\u666f\uff1a\u544a\u8b66\u5728\u67d0\u4e2a\u65f6\u95f4\u70b9\u4e4b\u540e\u7a81\u7136\u505c\u6b62\uff0c\u4efb\u52a1\u72b6\u6001\u4ece&quot;FROZEN&quot;\u81ea\u52a8\u53d8\u6210\u4e86&quot;RUNNING&quot;\uff0c\u6ca1\u6709\u4efb\u4f55\u4eba\u5de5\u4ecb\u5165\u3002\u8fd9\u4e2a\u65f6\u95f4\u8282\u70b9\u901a\u5e38\u53d1\u751f\u5728\u65f6\u949f\u8df3\u52a8\u5230\u67d0\u4e2a\u7279\u5b9a\u4f4d\u6570\u65f6\uff0c\u6bd4\u5982\u4ece 1783207599999 \u8df3\u5230 1783207600000\u3002<\/p>\n<p>\u5982\u679c\u4ee5\u4e0a\u573a\u666f\u6709\u4efb\u4f55\u4e00\u6761\u7b26\u5408\u4f60\u7684\u73b0\u72b6\uff0c\u57fa\u672c\u53ef\u4ee5\u786e\u5b9a\u662f ts \u6bd4\u8f83\u903b\u8f91\u51fa\u4e86\u95ee\u9898\u3002<\/p>\n<p>\u4e8c\u3001\u4e3a\u4ec0\u4e48\u5b57\u7b26\u4e32\u6bd4\u8f83\u4f1a\u51fa\u9519<\/p>\n<p>\u5148\u628a\u8fd9\u4e2a\u95ee\u9898\u8bf4\u6e05\u695a\u3002Unix \u65f6\u95f4\u6233\u672c\u8d28\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u6bd4\u5982 1783207553748\uff0c\u4ee3\u8868\u4ece 1970-01-01 00:00:00 UTC \u5f00\u59cb\u7ecf\u8fc7\u7684\u6beb\u79d2\u6570\u3002\u4f46\u5728\u5f88\u591a\u76d1\u63a7\u811a\u672c\u91cc\uff0c\u8fd9\u4e2a\u503c\u4f1a\u88ab\u8f6c\u6210\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u4ece JSON\u3001\u65e5\u5fd7\u6587\u4ef6\u91cc\u8bfb\u53d6\u65f6\u9ed8\u8ba4\u5c31\u662f\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u770b\u4e00\u4e2a\u5178\u578b\u7684\u9519\u8bef\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ Node.js \u793a\u4f8b\r\nconst lastHeartbeat = task.lastHeartbeatTs;  \/\/ \u503c\u662f &quot;1783207553748&quot;\uff08\u5b57\u7b26\u4e32\uff09\r\nconst now = Date.now().toString();            \/\/ \u503c\u662f &quot;1783207600000&quot;\uff08\u5b57\u7b26\u4e32\uff09\r\nconst diff = now - lastHeartbeat;            \/\/ JavaScript \u4f1a\u505a\u9690\u5f0f\u8f6c\u6362\r\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u770b\u8d77\u6765\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c<code>now - lastHeartbeat<\/code> \u4f1a\u89e6\u53d1 JS \u7684\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff0c\u628a\u5b57\u7b26\u4e32\u8f6c\u6210\u6570\u5b57\u518d\u505a\u51cf\u6cd5\u3002\u4f46\u95ee\u9898\u5f80\u5f80\u85cf\u5728\u76d1\u63a7\u903b\u8f91\u7684\u4e0a\u6e38\u3002<\/p>\n<p>\u518d\u770b\u4e00\u4e2a\u66f4\u5bb9\u6613\u51fa\u9519\u7684\u573a\u666f\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u4ece JSON \u914d\u7f6e\u6587\u4ef6\u6216\u73af\u5883\u53d8\u91cf\u8bfb\u53d6\r\nconst threshold = process.env.FROZEN_THRESHOLD_MS;  \/\/ &quot;300000&quot;\uff08\u5b57\u7b26\u4e32\uff09\r\nconst lastTs = task.lastHeartbeat;                  \/\/ &quot;1783207553748&quot;\uff08\u5b57\u7b26\u4e32\uff09\r\nconst nowTs = Date.now().toString();                \/\/ &quot;1783207600000&quot;\uff08\u5b57\u7b26\u4e32\uff09\r\n\r\n\/\/ \u5b57\u7b26\u4e32\u6bd4\u8f83\uff1a\u903b\u8f91\u770b\u4f3c\u6b63\u786e\r\nif (nowTs - lastTs &gt; threshold) {\r\n  triggerAlert(&#39;Task Frozen&#39;);\r\n}\r\n<\/code><\/pre>\n<p>\u95ee\u9898\u5728\u4e8e\uff1a\u5f53 <code>threshold<\/code> \u662f\u5b57\u7b26\u4e32 <code>&quot;300000&quot;<\/code>\u3001<code>nowTs - lastTs<\/code> \u505a\u51cf\u6cd5\u65f6 JS \u4f1a\u628a\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u8f6c\u6210\u6570\u5b57\uff08\u9690\u5f0f\u8f6c\u6362\uff09\uff0c\u7ed3\u679c\u770b\u8d77\u6765\u662f\u5bf9\u7684\u3002\u4f46\u5982\u679c\u5728\u67d0\u4e9b\u5206\u652f\u91cc <code>nowTs<\/code> \u548c <code>lastTs<\/code> \u6ca1\u6709\u88ab\u51cf\u6cd5\u8fd0\u7b97\uff0c\u800c\u662f\u505a\u4e86\u5b57\u7b26\u4e32\u62fc\u63a5\u6216\u76f4\u63a5\u6bd4\u8f83\u5927\u5c0f\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u9519\u8bef\u5199\u6cd5\uff1a\u76f4\u63a5\u5b57\u7b26\u4e32\u6bd4\u8f83\u5927\u5c0f\r\nif (lastTs &gt; nowTs) {  \/\/ \u5b57\u7b26\u4e32\u6bd4\u8f83\uff1a&quot;1783207553748&quot; &gt; &quot;1783207600000&quot; \uff1f\r\n  \/\/ \u8fd9\u4e2a\u5206\u652f\u6c38\u8fdc\u4e0d\u8be5\u8fdb\u53bb\uff0c\u4f46\u5b57\u7b26\u4e32\u6bd4\u8f83\u6709\u65f6\u4f1a\u610f\u5916\u8fdb\u5165\r\n}\r\n<\/code><\/pre>\n<p>\u66f4\u5927\u7684\u5751\u5728 Python \u7684\u65e5\u5fd7\u8bfb\u53d6\u573a\u666f\uff1a<\/p>\n<pre><code class=\"language-python\"># Python: \u4ece\u65e5\u5fd7\u6587\u4ef6\u8bfb\u53d6\u65f6\u95f4\u6233\r\nwith open(&#39;task_heartbeat.log&#39;, &#39;r&#39;) as f:\r\n    last_ts_str = f.readline().strip()  # &quot;1783207553748&quot;\r\n\r\n# \u5b57\u7b26\u4e32\u6bd4\u8f83\r\nnow_ts_str = str(int(time.time() * 1000))\r\nif int(now_ts_str) - int(last_ts_str) &gt; 300000:\r\n    send_alert()\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u770b\u8d77\u6765\u6b63\u786e\uff0c\u4f46\u5982\u679c\u65e5\u5fd7\u91cc\u6df7\u5165\u4e86\u7a7a\u884c\u3001\u6362\u884c\u7b26\u6216\u683c\u5f0f\u4e0d\u7edf\u4e00\u7684timestamp\uff0c\u5c31\u4f1a\u629b\u51fa\u5f02\u5e38\u6216\u4ea7\u751f\u610f\u5916\u884c\u4e3a\u3002\u800c\u5f88\u591a\u76d1\u63a7\u811a\u672c\u4e3a\u4e86&quot;\u5065\u58ee\u6027&quot;\u52a0\u4e86\u5f02\u5e38\u6355\u83b7\uff0c\u6355\u83b7\u540e\u5c31\u9759\u9ed8\u8df3\u8fc7\u5224\u65ad\uff0c\u5bfc\u81f4\u4efb\u52a1\u72b6\u6001\u6c38\u8fdc\u505c\u5728&quot;FROZEN&quot;\u3002<\/p>\n<p>\u4e09\u3001\u5b9e\u9645\u6848\u4f8b\u62c6\u89e3<\/p>\n<p>\u6765\u770b\u4e00\u4e2a\u771f\u5b9e\u76d1\u63a7\u7cfb\u7edf\u91cc\u7684\u4ee3\u7801\u7247\u6bb5\uff08\u7b80\u5316\u7248\uff09\uff1a<\/p>\n<pre><code class=\"language-javascript\">function checkTaskFrozen(task) {\r\n  const config = getMonitorConfig();\r\n  const frozenThreshold = config.frozenThresholdMs;  \/\/ 300000\uff08\u6570\u5b57\uff09\r\n  const lastTs = task.lastHeartbeat;                  \/\/ \u4ece DB \u8bfb\u53d6\uff0c\u53ef\u80fd\u662f\u5b57\u7b26\u4e32\r\n  const nowTs = Date.now();\r\n\r\n  \/\/ \u5206\u652f1\uff1a\u6b63\u5e38\u903b\u8f91\r\n  const diff = nowTs - lastTs;\r\n  if (diff &gt; frozenThreshold) {\r\n    return &#39;FROZEN&#39;;\r\n  }\r\n\r\n  \/\/ \u5206\u652f2\uff1a\u4ece\u5916\u90e8 API \u83b7\u53d6\u7684\u4efb\u52a1\u72b6\u6001\uff08\u8fd9\u91cc lastTs \u88ab\u8f6c\u6210\u4e86\u5b57\u7b26\u4e32\uff09\r\n  const externalTask = fetchExternalTask(task.id);\r\n  const extLastTs = externalTask.lastHeartbeat;  \/\/ &quot;1783207553748&quot; \u5b57\u7b26\u4e32\r\n\r\n  \/\/ \u8fd9\u91cc\u7684\u6bd4\u8f83\uff1a\u6570\u5b57 - \u5b57\u7b26\u4e32\uff0cJS \u9690\u5f0f\u8f6c\u6362\r\n  const extDiff = nowTs - extLastTs;  \/\/ \u6b63\u5e38\u5de5\u4f5c\r\n  if (extDiff &gt; frozenThreshold) {\r\n    return &#39;FROZEN&#39;;\r\n  }\r\n\r\n  \/\/ \u5206\u652f3\uff1a\u5b9a\u65f6\u4efb\u52a1\u62c9\u53d6\u5386\u53f2\u8bb0\u5f55\uff08JSON.parse \u7ed3\u679c\uff09\r\n  const historyRecord = JSON.parse(fs.readFileSync(&#39;history.json&#39;, &#39;utf8&#39;));\r\n  const histLastTs = historyRecord.lastHeartbeat;  \/\/ &quot;1783207553748&quot; \u5b57\u7b26\u4e32\r\n\r\n  \/\/ \u5b57\u7b26\u4e32\u76f4\u63a5\u6bd4\u8f83\uff08\u6ca1\u6709\u51cf\u6cd5\uff09\r\n  if (histLastTs &gt; frozenThreshold) {  \/\/ \u903b\u8f91\u5b8c\u5168\u9519\u8bef\uff01\r\n    \/\/ &quot;1783207553748&quot; &gt; 300000 \u2014\u2014 \u6c38\u8fdc\u662f true\r\n    return &#39;FROZEN&#39;;\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u6709\u4e09\u4e2a\u5206\u652f\uff0c\u5206\u652f1\u548c\u5206\u652f2\u662f\u6b63\u786e\u7684\uff0c\u5206\u652f3\u7684\u9519\u8bef\u662f\u628a\u65f6\u95f4\u6233\u5b57\u7b26\u4e32\u548c\u6beb\u79d2\u9608\u503c\u76f4\u63a5\u6bd4\u8f83\u3002\u5b57\u7b26\u4e32 &quot;1783207553748&quot; \u548c\u6570\u5b57 300000 \u6bd4\u8f83\uff0cJavaScript \u628a\u4e24\u8005\u90fd\u8f6c\u6210\u6570\u5b57\uff0c\u7ed3\u679c\u662f 1783207553748 &gt; 300000\uff0c\u6c38\u8fdc\u4e3a\u771f\uff0c\u6240\u4ee5\u4efb\u52a1\u6c38\u8fdc\u88ab\u5224\u5b9a\u4e3a FROZEN\u3002<\/p>\n<p>\u5982\u679c\u76d1\u63a7\u811a\u672c\u6070\u597d\u7528\u4e86\u5206\u652f3\u7684\u903b\u8f91\uff0c\u5c31\u4f1a\u51fa\u73b0&quot;\u6240\u6709\u4efb\u52a1\u90fd\u663e\u793a\u51b7\u51bb\uff0c\u4f46\u8fdb\u7a0b\u6ca1\u6302&quot;\u7684\u8be1\u5f02\u73b0\u8c61\u3002<\/p>\n<p>\u56db\u3001\u6b63\u786e\u505a\u6cd5<\/p>\n<p>\u539f\u5219\u53ea\u6709\u4e00\u6761\uff1a<strong>\u65f6\u95f4\u6233\u59cb\u7ec8\u4ee5 Number\uff08\u6570\u5b57\uff09\u7c7b\u578b\u53c2\u4e0e\u8fd0\u7b97\u548c\u6bd4\u8f83\uff0c\u4e25\u7981\u5b57\u7b26\u4e32\u76f4\u63a5\u6bd4\u8f83<\/strong>\u3002<\/p>\n<p>Node.js\/JavaScript\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/ \u8bfb\u53d6\u65f6\u7acb\u5373\u8f6c\u6570\u5b57\r\nconst lastTs = Number(task.lastHeartbeat);\r\nconst nowTs = Date.now();\r\nconst diff = nowTs - lastTs;\r\n\r\n\/\/ \u6216\u8005\u66f4\u5b89\u5168\u7684\u65b9\u5f0f\r\nconst lastTs = parseInt(task.lastHeartbeat, 10);\r\nconst nowTs = Date.now();\r\nconst diff = nowTs - lastTs;\r\n\r\n\/\/ \u6beb\u79d2\u9608\u503c\u4e5f\u8981\u786e\u4fdd\u662f\u6570\u5b57\r\nconst frozenThreshold = Number(config.frozenThresholdMs) || 300000;\r\n<\/code><\/pre>\n<p>Python\uff1a<\/p>\n<pre><code class=\"language-python\">import time\r\n\r\n# \u8bfb\u53d6\u65f6\u7acb\u5373\u8f6c int\r\nlast_ts = int(task_data[&#39;lastHeartbeat&#39;])\r\nnow_ts = int(time.time() * 1000)\r\ndiff_ms = now_ts - last_ts\r\n\r\n# \u9608\u503c\u540c\u6837\u5904\u7406\r\nfrozen_threshold = int(os.environ.get(&#39;FROZEN_THRESHOLD_MS&#39;, 300000))\r\n<\/code><\/pre>\n<p>Shell \u811a\u672c\uff1a<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\r\n# \u4ece\u547d\u4ee4\u8f93\u51fa\u6216\u6587\u4ef6\u8bfb\u53d6\u65f6\u95f4\u6233\u65f6\uff0c\u7528 $(()) \u5f3a\u5236\u7b97\u672f\u6c42\u503c\r\nLAST_TS=$(grep &quot;lastHeartbeat&quot; task.json | jq -r &#39;.lastHeartbeat&#39;)\r\nNOW_TS=$(date +%s%3N)  # \u6beb\u79d2\u7ea7\u65f6\u95f4\u6233\r\nTHRESHOLD=300000\r\n\r\n# \u7b97\u672f\u6bd4\u8f83\u7528 -gt\uff0c\u4e0d\u662f\u5b57\u7b26\u4e32\u6bd4\u8f83\r\nDIFF=$((NOW_TS - LAST_TS))\r\nif [ $DIFF -gt $THRESHOLD ]; then\r\n  echo &quot;Task Frozen&quot;\r\nfi\r\n<\/code><\/pre>\n<p>\u5173\u952e\u70b9\uff1a\u5728 Shell \u91cc\uff0c\u6574\u6570\u6bd4\u8f83\u7528 <code>-gt<\/code>\u3001<code>-lt<\/code>\u3001<code>-ge<\/code>\u3001<code>-le<\/code>\uff0c\u4e0d\u80fd\u76f4\u63a5\u7528 <code>&gt;<\/code>\u3001<code>&lt;<\/code>\uff08\u90a3\u662f\u5b57\u7b26\u4e32\u6bd4\u8f83\uff09\u3002<code>[ &quot;$a&quot; &gt; &quot;$b&quot; ]<\/code> \u662f\u5b57\u7b26\u4e32\u6bd4\u8f83\uff0c\u4e0d\u662f\u6570\u503c\u6bd4\u8f83\u3002<\/p>\n<p>\u4e94\u3001\u5982\u4f55\u5feb\u901f\u6392\u67e5<\/p>\n<p>\u5982\u679c\u4f60\u7684\u76d1\u63a7\u7cfb\u7edf\u5df2\u7ecf\u4e0a\u7ebf\uff0c\u6000\u7591\u8e29\u4e86\u8fd9\u4e2a\u5751\uff0c\u7528\u4ee5\u4e0b\u6b65\u9aa4\u5feb\u901f\u5b9a\u4f4d\uff1a<\/p>\n<p>\u9996\u5148\u786e\u8ba4\u544a\u8b66\u7684\u4efb\u52a1\u65f6\u95f4\u6233\u7c7b\u578b\u3002\u5728\u76d1\u63a7\u811a\u672c\u91cc\u52a0\u4e00\u884c\u65e5\u5fd7\uff0c\u6253\u5370 <code>typeof task.lastHeartbeat<\/code>\uff08JS\uff09\u6216 <code>type(task.lastHeartbeat)<\/code>\uff08Python\uff09\u3002\u5982\u679c\u662f <code>string<\/code>\uff0c\u5c31\u5df2\u7ecf\u627e\u5230\u4e86\u95ee\u9898\u7684\u4e00\u534a\u3002<\/p>\n<p>\u7136\u540e\u786e\u8ba4\u6bd4\u8f83\u65f6\u4e24\u4fa7\u7c7b\u578b\u662f\u5426\u4e00\u81f4\u3002\u5728\u544a\u8b66\u89e6\u53d1\u524d\u6253\u65e5\u5fd7\uff1a<code>console.log(&#39;lastTs type:&#39;, typeof lastTs, &#39;value:&#39;, lastTs, &#39;threshold type:&#39;, typeof threshold, &#39;value:&#39;, threshold)<\/code>\u3002\u7c7b\u578b\u4e0d\u4e00\u81f4\uff0c\u5c31\u662f\u6839\u56e0\u3002<\/p>\n<p>\u6700\u540e grep \u5168\u5c40\u641c\u7d22\u6240\u6709\u65f6\u95f4\u6233\u6bd4\u8f83\u903b\u8f91\uff1a<\/p>\n<pre><code class=\"language-bash\"># \u641c\u7d22\u5b57\u7b26\u4e32\u6bd4\u8f83\u65f6\u95f4\u6233\u7684\u6a21\u5f0f\uff08JS\uff09\r\ngrep -rn &quot;lastTs\\|lastHeartbeat\\|timestamp&quot; --include=&quot;*.js&quot; monitor\/ | grep -E &quot;if.*&gt;|if.*&lt;|&lt; |&gt; &quot;\r\n\r\n# \u641c\u7d22 Python \u91cc\u5b57\u7b26\u4e32\u548c\u6570\u5b57\u76f4\u63a5\u6bd4\u8f83\r\ngrep -rn &quot;if.*&gt;.*[0-9]&quot; --include=&quot;*.py&quot; monitor\/\r\n<\/code><\/pre>\n<p>\u627e\u5230\u53ef\u7591\u4ee3\u7801\u540e\uff0c\u6309\u4e0a\u6587\u7b2c\u56db\u8282\u7684\u6b63\u786e\u5199\u6cd5\u9010\u4e2a\u4fee\u590d\u3002<\/p>\n<p>\u516d\u3001\u4f01\u4e1a\u6587\u4ef6\u76d1\u63a7\u7cfb\u7edf\u7684\u7279\u6b8a\u6027<\/p>\n<p>\u8bf4\u5b8c\u901a\u7528\u573a\u666f\uff0c\u987a\u4fbf\u63d0\u4e00\u4e0b\u4f01\u4e1a\u7f51\u76d8\u548c\u79c1\u6709\u5316\u90e8\u7f72\u573a\u666f\u4e0b\uff0c\u4efb\u52a1\u51bb\u7ed3\u544a\u8b66\u7684\u53e6\u4e00\u4e2a\u5e38\u89c1\u539f\u56e0\uff1a\u8fdb\u7a0b\u672c\u8eab\u6ca1\u6302\uff0c\u4f46\u4efb\u52a1\u961f\u5217\u56e0\u4e3a\u5b58\u50a8 I\/O \u963b\u585e\u800c\u5047\u6b7b\u3002<\/p>\n<p>\u5df4\u522b\u9e1f\u79c1\u6709\u5316\u90e8\u7f72\u7684\u81ea\u52a8\u5316\u4efb\u52a1\u5f15\u64ce\uff0c\u4f1a\u5728\u6587\u4ef6\u4e0a\u4f20\u3001\u683c\u5f0f\u8f6c\u6362\u3001\u6279\u91cf\u6574\u7406\u7b49\u573a\u666f\u4e0b\u89e6\u53d1\u957f\u65f6\u4efb\u52a1\u3002\u5982\u679c\u76d1\u63a7\u811a\u672c\u53ea\u68c0\u67e5\u8fdb\u7a0b\u662f\u5426\u5b58\u5728\uff0c\u800c\u4e0d\u68c0\u67e5\u4efb\u52a1\u961f\u5217\u7684\u5b9e\u9645\u5fc3\u8df3\uff0c\u5f88\u5bb9\u6613\u8bef\u62a5&quot;\u4efb\u52a1\u51b7\u51bb&quot;\u3002\u6b63\u786e\u7684\u505a\u6cd5\u662f\u540c\u65f6\u76d1\u63a7\uff1a<\/p>\n<p>\u8fdb\u7a0b\u5b58\u6d3b\u72b6\u6001\uff08systemd\/supervisor\uff09<br \/>\n\u4efb\u52a1\u961f\u5217\u7684\u5fc3\u8df3\u65f6\u95f4\u6233\uff08\u6570\u636e\u5e93\u6216 Redis\uff09<br \/>\n\u78c1\u76d8 I\/O \u548c\u5b58\u50a8\u540e\u7aef\u54cd\u5e94\u65f6\u95f4<br \/>\n\u81ea\u52a8\u5316\u4efb\u52a1\u5f15\u64ce\u7684 6 \u5927\u4efb\u52a1\u72b6\u6001\uff08\u6e05\u7406\u3001\u89e3\u538b\u7f29\u3001\u91cd\u547d\u540d\u3001\u8f6cPDF\u3001\u6574\u7406\u3001\u521b\u5efa\u7b7e\u7ae0\uff09<\/p>\n<p>\u5df4\u522b\u9e1f\u7684\u81ea\u52a8\u5316\u4efb\u52a1\u5f15\u64ce\u8bbe\u8ba1\u672c\u8eab\u6709\u72b6\u6001\u6301\u4e45\u5316\u548c\u5fc3\u8df3\u673a\u5236\uff0c\u5982\u679c\u4efb\u52a1\u771f\u6b63\u5361\u4f4f\uff08\u6bd4\u5982\u540e\u7aef\u5b58\u50a8\u65ad\u5f00\uff09\uff0c\u5fc3\u8df3\u4f1a\u505c\u6b62\uff0c\u76d1\u63a7\u80fd\u51c6\u786e\u6355\u83b7\u3002\u5982\u679c\u5fc3\u8df3\u6b63\u5e38\u4f46\u544a\u8b66\u8fd8\u5728\u89e6\u53d1\uff0c\u57fa\u672c\u5c31\u662f\u65f6\u95f4\u6233\u6bd4\u8f83\u7c7b\u578b\u7684\u95ee\u9898\u3002<\/p>\n<p>\u603b\u7ed3\uff1a\u65f6\u95f4\u6233\u6bd4\u8f83\u662f\u76d1\u63a7\u7cfb\u7edf\u91cc\u6700\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u7ec6\u8282\uff0c\u9519\u8bef\u5199\u6cd5\u5728 JS\/Python\/Shell \u91cc\u5404\u6709\u5404\u7684\u5751\uff0c\u6839\u56e0\u90fd\u662f\u7c7b\u578b\u4e0d\u4e00\u81f4\u3002\u4e00\u65e6\u786e\u8ba4\u662f\u5b57\u7b26\u4e32\u6bd4\u8f83\u95ee\u9898\uff0c\u4fee\u590d\u6210\u672c\u6781\u4f4e\u2014\u2014\u5728\u8bfb\u53d6\u548c\u6bd4\u8f83\u65f6\u52a0\u4e00\u4e2a\u7c7b\u578b\u8f6c\u6362\u5373\u53ef\u3002\u6392\u67e5\u65f6\u4f18\u5148\u6253\u65e5\u5fd7\u786e\u8ba4\u7c7b\u578b\uff0c\u80fd\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f01\u4e1a\u6c38\u52a8\u673a\u76d1\u63a7\u811a\u672c\u603b\u62a5\u8b66&quot;\u4efb\u52a1\u51b7\u51bb&quot;\uff1f\u5148&#8230; <a class=\"read-more\" href=\"https:\/\/www.babel.cc\/blog\/?p=7818\">[Continue Reading]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-7818","post","type-post","status-publish","format-standard","hentry","category-12","no-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7818"}],"version-history":[{"count":1,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7818\/revisions"}],"predecessor-version":[{"id":7819,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7818\/revisions\/7819"}],"wp:attachment":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}