Tuesday 29 September 2020

How to handle sending multiple mysql queries from an endpoint and avoid crashing my node app?

I have intermediate experience with Node. So I am trying to display query results on one of my webpages, and there are 8 queries total fetching results from 4 different tables. I am currently sending 8 queries simultaneously, and I think it might be causing a performance issue.When I try to add an additional query along with the 8 already there, my node app crashes. I get the error "Server is down due to capacity problems". If I stick with 8 queries, the node app works fine.I believe sending multiple SQL queries simultaneously might be the issue. I need to add more queries to this endpoint for my next feature, and currently, I am not able to do so.​This is my code below. The variable images_sql is 8 queries concatenated into 1.con.query(images_sql, [well_id, well_id, well_id, well_id, well_id, well_id, well_id, well_id], function(err, results, fields) {if (err) {throw err;} else {single_well_obj = {well: results};res.render('images', single_well_obj);}});​Should I be using async/await or Promises to solve this? Or is there way to fix this?

Submitted September 30, 2020 at 06:40AM by yungspartan0082

No comments:

Post a Comment