Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trilogy is much slower than mysql2 to connect to an IP #129

Closed

Conversation

casperisfine
Copy link
Contributor

$ script/benchmark-connect
Warming up --------------------------------------
trilogy connect/close
                       107.000  i/100ms
mysql2 connect/close   761.000  i/100ms
Calculating -------------------------------------
trilogy connect/close
                          1.022k (±73.3%) i/s -    321.000  in  19.716812s
mysql2 connect/close      7.564k (±19.0%) i/s -     37.289k in   5.246187s

Comparison:
mysql2 connect/close:     7564.4 i/s
trilogy connect/close:     1022.4 i/s - 7.40x  slower

I'll try to investigate, but opening now FYI

```
$ script/benchmark-connect
Warming up --------------------------------------
trilogy connect/close
                       107.000  i/100ms
mysql2 connect/close   761.000  i/100ms
Calculating -------------------------------------
trilogy connect/close
                          1.022k (±73.3%) i/s -    321.000  in  19.716812s
mysql2 connect/close      7.564k (±19.0%) i/s -     37.289k in   5.246187s

Comparison:
mysql2 connect/close:     7564.4 i/s
trilogy connect/close:     1022.4 i/s - 7.40x  slower
```
@casperisfine
Copy link
Contributor Author

I profiled that benchmark, and somehow the difference seem to be mostly in select:

Capture d’écran 2023-10-20 à 12 27 03

Which is weird. Perhaps trilogy is failing to flush some packet or something?

@casperisfine
Copy link
Contributor Author

Hum, actually I might be an idiot. I think in my initial benchmark mysql2 was still using the unix socket.

Now trilogy appear much faster than mysql2, but I still think something is weird:

===  Connecting to 'localhost'. 
Warming up --------------------------------------
mysql2 connect/close     1.000  i/100ms
trilogy connect/close
                        33.000  i/100ms
Calculating -------------------------------------
mysql2 connect/close    101.921  (±27.5%) i/s -    298.000  in   7.459327s
trilogy connect/close
                          2.908k (±40.4%) i/s -      2.673k in   5.761606s

Comparison:
trilogy connect/close:     2908.0 i/s
mysql2 connect/close:      101.9 i/s - 28.53x  slower

@matthewd
Copy link
Contributor

Now trilogy appear much faster than mysql2, but I still think something is weird

Huh.. yeah, while I might hope for faster, that sort of difference seems implausible. Unless perhaps it preemptively spins up OpenSSL or something? 😕

@casperisfine
Copy link
Contributor Author

Unless perhaps it preemptively spins up OpenSSL or something?

Possibly, I didn't have a SSL setup in local to check that.

For context the reason I'm digging into this is that we eagerly connect to all our shards after fork to avoid slow requests after deploy, and this was taking something like 3-4 seconds (we have a lot of shards).

I changed the code to use a thread pool with 10 threads, and it only made it ~3 times faster, so I was looking if perhaps trilogy doesn't release the GVL during some part of the connect phase, but couldn't find anything.

Unfortunately I don't have the same real world measurement with mysql2, so can't say for sure something is wrong with trilogy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants