1

I am developing a back-end with Node.js and MySQL. Sometimes, there are a huge number of queries to be done on the database > 50,000, and I'm using connection pooling. My question is what happens to a query after it is rejected due to the pool being exhausted? Will it be queued until a connection becomes available and then executed? Or it will simply never be executed?

There are indeed similar questions but the answers didn't highlight my point, they just recommended increasing the limit size.

Hussein Hijazi
  • 439
  • 4
  • 13

1 Answers1

1

Maybe.

There are options you can set to modify the behavior. See https://github.com/mysqljs/mysql#pool-options

The request may wait in a queue for a free connection, or not. This is based on the option waitForConnections. If you set this option to false, the request returns an error immediately instead of waiting.

If more than queueLimit requests are already waiting, the new request returns an error immediately. The default value is 0, which means there is no limit to the queue.

The request will wait for a maximum of acquireTimeout milliseconds, then if it still didn't get a free connection, returns an error.

P.S.: I don't use Node.js, I just read this in the documentation.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • Well answered,thanks, just one more question: will a queued query be executed immediately once a connection is available, or the priority is given to the new queries? – Hussein Hijazi Jul 04 '19 at 19:58
  • I haven't used it, so I don't know for sure, but I would assume by the common definition of a "queue" it works in a first-come, first-serve manner. – Bill Karwin Jul 04 '19 at 20:02
  • I have no doubt that queries in the queue will be executed in FIFO, my question is that do the queries in the queue have higher priority than the new queries that are new(issued at the same time a connection is available) and aren't queued yet? – Hussein Hijazi Jul 04 '19 at 21:14
  • You'll have to test that. Part of being a software engineer is being able to write testing code to answer these sorts of questions empirically. Write a test program that you can run in a development environment. It's your responsibility to design that test so it answers your questions unambiguously. – Bill Karwin Jul 04 '19 at 21:42
  • That's why we study computer **science** when preparing for this profession. Being a scientist is about thinking about a problem logically, so you can design a test that will eliminate other variables and answer only the question you need answered. That's the skill of being a scientist. – Bill Karwin Jul 04 '19 at 21:44