Report this

What is the reason for this report?

Problem with server loading, Express JS API

Posted on January 15, 2021
Chirag Artani

By Chirag Artani

I am Chirag Artani - A Blogger

Hi, Hope you are doing well.

This time I have a problem with the server, Currently I am using $15 server which has 2 cores and 2gb RAM, but the performance is poor now I don’t know what is the reason here.

This is the API:

var express = require('express');
var sqlite3 = require('sqlite3').verbose();
var path = require('path');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {

    if(Object.keys(req.query).length === 0){
        res.send("No input given");
    } else {

        let query   = req.query.q;

        let SQLquery = 'SELECT * FROM recipe ';

        if(query){
            SQLquery += 'WHERE RecipeName LIKE "%' + query + '%"';
        }

        //console.log(SQLquery);

        let result = [];

        var db = new sqlite3.Database(path.resolve(__dirname, '../recipe.sqlite'));
        
        db.serialize(function() {
            db.each(SQLquery, (err, row) => {
                if (err) {
                    console.error(err.message);
                } else {
                    result.push(row); 
                }
            }, function(){
                //console.log(result);
                res.send(result);
            });
        });

        db.close();
    }
});

module.exports = router;

So basically I have stored data in Sqlite3 which would be 3 Million rows, 280 people or fewer than that, fetching data at a time, but the server is not responding - 100% CPU and RAM.

Help me with this. The structure of script is not good? or $15 server is not enough or what is the problem please explain this.

Thank You! Regards

  • Chirag Artani


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

It sounds like that you might need more CPU power as the application seems to be quite busy.

Another option I could suggest is trying to use MySQL or PostgreSQL instead of SQLite. I would personally use SQLite for local dev environments but whenever performance optimization is hard when using SQLite.

Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.