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.

node-mysql2 is running slower than node-mysql, config issue?

See original GitHub issue

Hi, I wanted to try mysql2 as a replacement for mysql for performance reasons. When I tried it in a production environment, I am actually seeing that mysql2 is slower, so I wonder if it’s a config issue on my end. Are there any settings I should try changing?

Using the profiler, I didn’t see anything out of the ordinary. The vast majority of time is spent in handlePacket -> TextRow -> wrap. The only other difference I notice between the two libraries is that mysql2 seems to invoke Readable.push in a very regular frequency time-wise, whereas mysql does it in an irregular pattern. Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:26 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
testncommented, Oct 7, 2021

I generated it using https://www.mockaroo.com/

1reaction
testncommented, Oct 6, 2021

I found a couple issues with it. It seems to be much slower due to

  1. “typeCast” code handling where it has a compatibility layer that adds a lot of overhead due to the request to just-in-time parsing of column definition’s properties (see #889)
  2. the state management + some code generation seems to make the code optimization not working as expected

For the first one, I can fix it by caching column definition attribute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is a Mysql query execution in Node JS so much slower ...
this query returns ~25k rows (500KB in total size). When I query the above query in Node.js using the node-mysql driver, it takes...
Read more >
Pool cannot detect idle connection disconnected by MySQL ...
It seems mysql2's pool implementation cannot detect this type of disconnection (ping is not sufficient). And when it happens, any queries sent ...
Read more >
How to vastly improve MySQL performance in Node.JS?
The only way to free them up is to manually close the connections via the pool instance or close the pool.
Read more >
Overloaded connection pool with bad MySQL driver ... - alxolr
In NodeJs event loop is getting stuck only in a couple of cases: Sync code that got into an infinite loop or some...
Read more >
MySQL Logging & Debugging with Node.js - databases
This can help you track down unexpected behaviour, and debug why some of your MySQL queries are running slowly. The following examples assume...
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