We want to have multiple concurrent requests without using node cluster i.e. if we requests 3 times then we should have the execution ending almost at the same time.
This is sample code:
const execute_select = async () => {
const jdbcres = new Driver(Conn.MySQL, {host, port, database})
const d = await jdbcres.sql(‘SELECT * from db.maindb’); // takes 10 seconds to complete
}
app.post(‘/select, (request, response) => {
execute_select();
response.send(‘200’);
});
If we execute http://localhost/select 3 times (at the same time), what happens is the following:
- We immediately get a response back.
- Each of the requests are blocked at the following line
const d = await jdbcres.sql(‘SELECT * from db.maindb’)
- First one ends within 10 seconds followed by the next one which ends in 10s followed by the next one for a total of about 30seconds.
Is there a way to have calls to /select not waiting for the previous request to end i.e. the total time should be around 10seconds?
My other attempt was to have this in place of the following line: const d = await jdbcres.sql(‘SELECT * from db.maindb’); // takes 10 seconds to complete
/* const result = await new Promise((resolve, reject) => {
setTimeout(() => {
const d = jdbcres.sql('SELECT * from db.maindb')
resolve(d);
}, 20000);
});
*/
Please find a list of related pages that I have read: