Node.js net.Socket TCP连接随机获取>;4K毫秒

Node.js net.Socket TCP连接随机获取>;4K毫秒,node.js,sockets,kubernetes,tcp,Node.js,Sockets,Kubernetes,Tcp,我正在编写一个网络监控实用程序,它作为Node.js应用程序运行在Kubernetes上运行的Linux容器中。该实用工具使用节点的net.Socket定期(每30秒)为一组URI(例如URI.org)创建一个TCP套接字。调用connect()方法返回后,我测量建立连接所用的时间,记录此信息,然后使用destroy()关闭套接字 一切运行正常(建立套接字大约需要30毫秒),但偶尔(每隔大约一分钟左右),建立套接字将需要>4000毫秒 为了从图片中删除Node.js,我在LinuxPod上对同一

我正在编写一个网络监控实用程序,它作为Node.js应用程序运行在Kubernetes上运行的Linux容器中。该实用工具使用节点的net.Socket定期(每30秒)为一组URI(例如URI.org)创建一个TCP套接字。调用
connect()
方法返回后,我测量建立连接所用的时间,记录此信息,然后使用
destroy()
关闭套接字

一切运行正常(建立套接字大约需要30毫秒),但偶尔(每隔大约一分钟左右),建立套接字将需要>4000毫秒

为了从图片中删除Node.js,我在LinuxPod上对同一URI运行了nping,但没有看到这种行为(我确实看到了偶尔的慢速ping,但这大约是1000毫秒)

你知道我做错了什么吗,或者这只是Node的网络库的问题

const client: net.Socket = new net.Socket();
const stopwatch: Stopwatch = new Stopwatch();
stopwatch.start();

// Wrapping net.Socket.connect in a promise so that we can await
// until we have results from the TCP socket fired
await new Promise((resolve, reject) => {

    // Register event handlers
    client.on('connect', () => {
        tcpSuccess = true;
        tcpLatency = this.calculateLatencyAndCleanup(client, stopwatch);
        resolve();
    });

    client.on('error', (err) => {
        tcpLatency = this.calculateLatencyAndCleanup(client, stopwatch);
        reject('Socket error for: `' + hostString + ':' + tcpPort + '`');
    });

    client.on('timeout', () => {
        tcpLatency = this.calculateLatencyAndCleanup(client, stopwatch);
        reject('Socket timeout for: `' + hostString + '`');
    });

    // Attempt to create TCP socket
    client.connect(tcpPort, hostString);

另外,对clinet.destroy的调用是在
calculateLatencyAndCleanup
方法中进行的。

我无法理解这一点,因此我编写了一个简单的.Net核心客户端,以查看.Net的网络API的性能与Node的相比如何。Net应用程序中的TCP ping要比Node应用程序快得多,我没有看到那些零星的四秒钟ping。我不明白为什么我的节点应用程序表现出如此糟糕的性能。我一直在.Net应用程序中看到2-3毫秒的ping。我无法理解这一点,所以我编写了一个简单的.Net核心客户端,以查看.Net的网络API的性能与Node的性能相比如何。Net应用程序中的TCP ping要比Node应用程序快得多,我没有看到那些零星的四秒钟ping。我不明白为什么我的节点应用程序表现出如此糟糕的性能。我一直在.Net应用程序中看到2-3毫秒的ping。