2016-10-17 87 views
3

我有兩個飛鏢應用程序可以在亞馬遜(AWS Ubuntu的),它運行的是:如何檢測飛鏢VM崩潰的原因

  1. 自託管的HTTP API
  2. 工人來處理一個定時器
  3. 後臺任務

這兩個應用程序都使用PostgreSQL。他們偶爾會崩潰,除了試圖找到根本原因之外,我還實施了一個超級用戶腳本,它只是檢測這兩個主要應用程序是否正在運行並根據需要重新啓動它們。

現在我需要解決的問題是監督腳本崩潰或虛擬機崩潰。它每隔幾天發生一次。

我不認爲這是內存泄漏,因爲如果我把投票率從10秒提高到更常(1納秒),它在Dart天文臺正確顯示它耗盡了30MB,然後垃圾收集並啓動低內存使用率,並保持騎自行車。

我不會認爲這是一個未捕獲的異常,因爲無限循環完全封閉在try/catch中。

我不知道還有什麼可嘗試的。是否有虛擬機轉儲文件,可以檢查虛擬機是否真的崩潰?有沒有其他技術來調試根本原因? Dart不夠穩定,無法一次運行幾天的應用程序?

這是主管腳本代碼的主要部分:

///never ending function checks the state of the other processes 
Future pulse() async { 
    while (true) { 
    sleep(new Duration(milliseconds: 100)); //DEBUG - was seconds:10 
    try { 
     //detect restart (as signaled from existence of restart.txt) 
     File f_restart = new File('restart.txt'); 
     if (await f_restart.exists()) { 
     log("supervisor: restart detected"); 
     await f_restart.delete(); 
     await endBoth(); 
     sleep(new Duration(seconds: 10)); 
     } 

     //if restarting or either proc crashed, restart it 
     bool apiAlive = await isRunning('api_alive.txt', 3); 
     if (!apiAlive) await startApi(); 
     bool workerAlive = await isRunning('worker_alive.txt', 8); 
     if (!workerAlive) await startWorker(); 

     //if it's time to send mail, run that process 
     if (utcNow().isAfter(_nextMailUtc)) { 
     log("supervisor: starting sendmail"); 
     Process.start('dart', [rootPath() + '/sendmail.dart'], workingDirectory: rootPath()); 
     _nextMailUtc = utcNow().add(_mailInterval); 
     } 

    } catch (ex) {} 
    } 
} 
+0

您沒有得到任何包含有關崩潰信息的控制檯輸出?您可以在AWS外部複製(在本地機器的外殼中)嗎? –

+0

我試圖在本地運行大大增加時間重現,但不能。主管腳本將stdout寫入文件,該文件沒有任何內容超出了我明確寫的範圍。就好像它正常退出一樣。 –

+0

我假設你也將stderr重定向到文件中? –

回答

1

如果你有天文臺起來,你可以得到一個崩潰轉儲: curl localhost:<your obseratory port>/_getCrashDump

我不能完全肯定如果這是相關的但Process.start返回一個未來,我不相信如果它完成一個錯誤將被您的try/catch抓住...

+0

Process.start應該在分離模式下調用(在我的情況下);這樣做似乎使它更加穩定(但還沒有弄清楚爲什麼)。我會嘗試天文臺的東西 - 謝謝! –