The server experiences a continuous rise in active handles, leading to a slowdown in server performance

I created a basic node API that simply notifies the user about internet connectivity. Everything runs smoothly when hitting this API every 3 seconds as long as the active handles are under 4000. However, once it goes beyond that limit, my server becomes unresponsive until I restart it. The server is managed through pm2, and below is an image link showing its status when using "pm2 monit".

   const express = require('express');
    const app = express();
    app.get('/users', (req, res) => {
        res.send({status:200, message:'request received'});
        return; // assuming res.send terminates the request 
    });

    app.listen(5005, () => {
      console.log('Listening on port 5005');
    });

https://i.stack.imgur.com/zEgUd.png

Answer №1

Haruki, I believe that utilizing express for this task may be unnecessary. Instead, you could experiment with the built-in http module to achieve the same results. Here is a simple ping-pong server code snippet for your reference:

const http = require("http");

http.createServer((request, response) => {
    response.setHeader("Content-Type", "application/json");
    response.write(JSON.stringify({ status: 200, message: "pong" }));
    response.end();
}).listen(8080);

In addition, using pm2 clustering may lead to issues in this scenario. Consider native clustering as an alternative solution to pm2 for this specific use case.

If you encounter any challenges when implementing the above code with pm2, I recommend exploring native clustering with the cluster module.

Below is a load test illustration using siege for evaluating the performance of the code. It has shown satisfactory results on my system.

https://i.stack.imgur.com/qf4kj.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I pass function arguments dynamically to a nested function in Node.js?

Currently using Node 6.11.0, I am attempting to accomplish the following dynamically: const parentFunc = (arg1, arg2, arg3, arg4) => { childFunc('foo', arg1, arg2, arg3, arg4); }; I have attempted this method (without success): const pare ...

Executing code after sending a response in NodeJS with Graphql: Is it possible?

I have a unique endpoint that receives special files and automatically initiates a background task for uploading those files to our secure cloud storage system. In order to efficiently handle the file uploads in the background, we are utilizing advanced t ...

Comparing JSON files in JavaScript to identify and extract only the new objects

I need a way to identify and output the newly added objects from two JSON files based on their "Id" values. It's important for me to disregard changes in object positions within the files and also ignore specific key-value changes, like Greg's ag ...

What is the best way to utilize Protractor to comb through a specific class, locate a p tag within that class, and validate certain text within it?

My current task involves using Protractor to locate a specific class and then search through all the p tags within that class to identify any containing the text "Glennville, GA". In my spec file, I have attempted the following steps: it('should fil ...

Implementing specifications throughout the entire nodejs route

In my Nodejs app, I have a RESTful API where I need to check for a user's role before sending a response with data or 404 error. apiRouter.route('/users') .get(function (req, res) { var currentUser = req.decoded; if(curr ...

JavaScript heap exhausted while running Docker container

Typically, I start my application by running npm run dev. The package.json file contains a script like the one below: "scripts": { "dev": "nodemon server.ts", } Everything is working fine in this setup. I have cr ...

What is the process of connecting two models in Mongoose?

In this scenario, we have two models - ProductModel and CategoryModel. The goal here is to establish a connection between creating a product (ProductModel) and assigning it to a category. The issue arises when the category field is not getting filled in t ...

Is it possible to transfer a property between components without relying on the props object?

I created a component that showcases a variety of cafes. Inside this component ( CafeList.jsx), an axios request is triggered to fetch a list of cafes, which is then mapped over and displayed on the browser. I envision users being able to click on a spe ...

Managing multiple versions of a document in a blog storage system with MongoDB and Node.js

In the process of developing a blog site, I want to incorporate a feature that keeps track of the changes made in previous and current versions of a blog post. One method is to create a separate history collection, but how should I manage the document? S ...

Encountered an issue while setting up Laravel Elixir: node-sass installation error - unable to establish tunneling socket, reason being getaddrinfo ENOTFOUND ip ip:80

Encountering an issue while attempting to install the node dependencies for a Laravel project. The error message received is: Error installing node-sass: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND ip ip:80 Despite not being ...

Tips for resolving the error message "EADDRINUSE: address already in use" during integration tests

I recently started learning Node.js through an online course on Udemy. While running integration tests multiple times, I encountered an issue with listen EADDRINUSE: address already in use :::4000. The first run is successful, but subsequent runs result in ...

Implementing a rate limit on the login API that is specific to individual IP addresses rather than being

I have successfully implemented the [email protected] module, but I am facing an issue where it is blocking the API globally instead of for a specific API that is receiving hits. This is my current code: const limiter = new RateLimit({ windo ...

Understanding the scope of variables in a JavaScript callback function

I am attempting to send an object variable to a callback function const sql = require('mssql'); const asset_update = function (connection, addr) { this.connection = connection; this.addr = addr; this.addr_long = parseInt(addr, 16); } ...

Issue with storing a SQL time(7) field in a database using Node.js

I am currently utilizing the nodemssql package to interact with a SQL Server Azure database. Field time(7) > RecurrenceType.columns.add('StartTime', mssql.Time(7)); > RecurrenceType.columns.add('EndTime', mssql.Time(7)); ...

Guide to creating a dynamic node package that updates itself autonomously

We currently have a node_module known as bookiza, which serves as a command line tool that users install globally and utilize to create and publish books online. While we generally adhere to semver conventions for versioning, I anticipate stricter adherenc ...

Error: Unable to connect to http://registry.npmjs.org/express after a timeout

Whenever I attempt to install express or any npm packages, I encounter the following error (without a proxy) with Node version 10.14.2 and npm version 6.4.1: npm ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! network request to http://registry.npmjs ...

The error occurred in async JavaScript parallel code because the task is not recognized as a function

I am attempting to upload an image and update the image URL in the database collection using the code provided below. Controller.prototype.handle = function (req, res, next) { var id = req.params.id, controller = req.params.controller, optio ...

Having trouble with eslint in create-react-app because of a parent folder that also has another app with its own node_modules folder?

I have a git repository with two projects inside: a loopback app (named app) and a create-react-app react app (named client). Here is the directory structure: ├─┬app │ ├──node_modules │ ├─┬client ├─node_modules The loopback ...

Retrieving inquiries associated with a specific tag on Stack Overflow

I'm part of a team of developers in my Discord community who are dedicated to helping others with their problems on Stack Overflow. Is there a way to create a bot that can automatically gather the latest question tagged with a specific keyword and s ...

Guide for launching Electron on a local host server during development and for production builds

I have a project using Next.js + Electron + Typescript. I used the npx create-next-app --example with-electron-typescript command to generate the initial code. When I run npm run dev (which actually runs npm run build-electron && electron . ), the ...