mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Getting terrible performance. I must be doing something wrong.

Open kswope opened this issue 3 years ago • 5 comments

I was getting much worse performance than node/mysql2 in a web app benchmarked by k6. The problem seemed to be this driver, so I made a crude benchmark which seems to agree with what I was seeing.

https://github.com/kswope/deno-mysql-bench

Here's a preview of the kind of results I'm getting

deno-mysql-bench> deno run --allow-net ./deno/index.ts
INFO connecting localhost:3306
INFO connected to localhost:3306
default: 7402ms
INFO close connection

deno-mysql-bench> node node/index.js
default: 996.609ms

kswope avatar Jan 15 '22 09:01 kswope

Because node-mysql2 is "with focus on performance" (as first sentence in its readme). It generates JS code per query at runtime for parser performance. So it's no surprise that deno-mysql is 7x slower.

lideming avatar Jan 17 '22 12:01 lideming

That's fine and I appreciate it, but I'm getting 8x to 10x slower. In my experience that's a sign something is wrong.

kswope avatar Jan 17 '22 14:01 kswope

I should add I'm getting 10x worse performance from queries that return large data sets, which would indicate its not the upfront parsing costs at all but the problem is maybe more likely how results from the db are being processed.

kswope avatar Jan 17 '22 14:01 kswope

how results from the db are being processed

It's what their generated JS code do, which read and parse result rows from the db.

lideming avatar Jan 18 '22 02:01 lideming

I added a mysql version (not mysql2) in the form of promise-mysql.

Its entirely possible that this benchmark is not benchmarking the right thing and I screwed something up (it just uses console.time, nothing fancy), but I tried to keep the code identical (allowing for driver differences), and I'm still seeing something noteworthy

Here's a snippet of whats over at the benchmark repo

bash-3.2$ node node/index.js # using promise-mysql
time: 1.115s

bash-3.2$ node node/index2.js # using mysql2
time: 745.972ms

bash-3.2$ deno run --allow-net ./deno/index.ts
time: 7064ms

kswope avatar Jan 18 '22 06:01 kswope