在 Java JVM 中,kill -3强制进程打印所有正在运行的线程的当前堆栈跟踪。我发现快速定位瓶颈非常有效。
V8 中是否有等价物?我可以让 V8 打印当前的堆栈跟踪吗?
澄清:我认为,由于节点的异步性质,它不如典型的非异步程序有用。尽管如此,如果有一种简单的方法可以访问一些堆栈跟踪,那么查看它并不需要太多时间。
根据我的经验,在您需要切换到更高级的工具之前,可以通过这种方式快速定位一些明显的瓶颈。
我正在尝试使用LearnBoost的socket.io和node-websocket-client创建一个测试.客户端和服务器之间的通信工作很好.完成所有通信后,我关闭客户端和服务器.然而程序挂起,等待一些未知的回调.两个问题:
var connect = require('connect'),
io = require('socket.io'),
WebSocket = require('websocket-client').WebSocket;
var port = 7111;
var server = connect.createServer();
var socket = io.listen(server);
socket.on('connection', function(client) {
client.send('Welcome!');
client.on('message', function(message) {
console.log(message);
});
client.on('disconnect', function() {
console.log('closing');
server.close();
});
});
server.listen(port, function() {
var ws = new WebSocket('ws://localhost:' + port + '/socket.io/websocket');
ws.onmessage = function(message) {
console.log(message.data);
};
setTimeout(function() {
ws.send('~m~3~m~Yo!');
ws.close();
}, 10);
});
Run Code Online (Sandbox Code Playgroud)
编辑:更改WebSocket的变量名称ws以避免混淆
我想为此进程添加一个小时的超时,以便在流死锁的情况下它不会永远保留.唯一的问题是如果我说setTimeout,进程没有机会提前结束.
有没有办法在大约一个小时后进入强制退出超时,而不保持进程运行?或者我在使用process.exit和没有超时之间停留?
我正在尝试从官方节点 api 文档中运行 Async Hooks 的测试代码,但Error: Cannot find module 'async_hooks'在控制台中出现错误。我已经包含const async_hooks = require('async_hooks');在我的脚本的顶部。这是我的代码:
const async_hooks = require('async_hooks');
// Return the ID of the current execution context.
const eid = async_hooks.executionAsyncId();
// Return the ID of the handle responsible for triggering the callback of the
// current execution scope to call.
const tid = async_hooks.triggerAsyncId();
// Create a new AsyncHook instance. All of these callbacks are optional.
const asyncHook =
async_hooks.createHook({ init, before, after, destroy, promiseResolve }); …Run Code Online (Sandbox Code Playgroud) node.js ×4
async-hooks ×1
asynchronous ×1
lifecycle ×1
module ×1
profiling ×1
settimeout ×1
socket.io ×1
stack-trace ×1
timeout ×1
v8 ×1