Hello Devs, This is my first post on this platform! ?
I wanted to share a surprising experience I had with Express.js and SQL. I’m a beginner developer, and while working on the API for my project, I was handling over 200k API requests per day. Initially, I set up an SQLite database (~400 MB) with an Express.js API, and used Node.js caching to speed things up.
At first, the response time for a query was around 200-300 ms, since it involved several JOINs and searches. So, I decided to run some experiments to see if I could improve performance.
Here’s what I did:
The result was surprising! After indexing, some of my more complex queries, involving multiple JOINs, were being executed in just 3-5 ms.
Previously, with Node caching:
After, with only SQLite indexes:
every requests only takes 7-10 ms without any caching.
Now the queries are consistently fast, and this also reduced the server load! Initially, I was running my app on a DigitalOcean droplet with 4 GB of RAM and 4 vCPUs. But after optimizing the SQL queries, I can comfortably handle the same workload with just 2 GB of RAM and 2 vCPUs.
I know this may sound simple, but proper SQL indexing made such a big difference in query performance that I no longer even need to rely on caching. ?
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3