2016-10-17 25 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应该在分离模式下调用(在我的情况下);这样做似乎使它更加稳定(但还没有弄清楚为什么)。我会尝试天文台的东西 - 谢谢! –