question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

parallelity of queries (multiple queries at once)?

See original GitHub issue

I wrote a program, which requests n-queries (for instance 20,000) at once to my postgres database.

When I do this with several clients who want to query 20,000 at once too, there is no parallelity. That means, the requests of the second client will be queued until the first client finished all his queries.

Is this a normal behavior for postgres? If yes, how can I prevent that one user gets all the ressources (and the others have to wait) if there is no parallelity?

This is my code:

const express = require('express');
const app = express();
const { Pool } = require("pg");
const pool = new Pool();


benchmark(){
    pool.connect((err, client, done) => {
      if (err) throw err;
      client.query("SELECT * from member where m_id = $1", [1], (err, res) => {
        done();
        if (err) {
          console.log(err.stack);
        } else {
          console.log(res.rows[0]);
        }
      });
    }); 
}


app.get('/', function(req, res) {
  for(let i=0;i<20000;i++){
    benchmark();
  }
});

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ghostcommented, Aug 21, 2019

Thank you for your replies you were very helpful!

0reactions
charmandercommented, Aug 20, 2019

Pool doesn’t use pg.defaults. Pass options:

const pool = new pg.Pool({ max: 20 });

documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parallel Queries | TanStack Query Docs
"Parallel" queries are queries that are executed in parallel, or at the same time so as to maximize fetching concurrency. Manual Parallel Queries....
Read more >
PostgreSQL Multiple Queries in one statement can be done ...
No, what you show is not run in parallel between the queries. You could submit the queries with dblink_send_query over different dblink ...
Read more >
Documentation: 15: Chapter 15. Parallel Query - PostgreSQL
PostgreSQL can devise query plans that can leverage multiple CPUs in order to answer queries faster. This feature is known as parallel query....
Read more >
Does two SQL server execute two queries in parallel? - MSDN
Scenario 1: two queries together in one editor, it takes about 2 minutes. Scenario 2: each query in a separate window, the running...
Read more >
MS SQL Server: Do multiple queries in a batch ever execute in ...
Batch statements are only ever executed serially in the order they appear in the batch. Now, if you have two statements sent to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found