denodrivers / mysql

MySQL driver for Deno
https://deno-mysql.netlify.com/
MIT License
259 stars 65 forks source link

Getting terrible performance. I must be doing something wrong. #125

Open kswope opened 2 years ago

kswope commented 2 years ago

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
lideming commented 2 years ago

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.

kswope commented 2 years ago

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 commented 2 years ago

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.

lideming commented 2 years ago

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.

kswope commented 2 years ago

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