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

zlib affects queries performance #42

Closed
dbalabka opened this issue Sep 7, 2017 · 5 comments
Closed

zlib affects queries performance #42

dbalabka opened this issue Sep 7, 2017 · 5 comments

Comments

@dbalabka
Copy link
Contributor

dbalabka commented Sep 7, 2017

After some benchmarking I have figure out that zlib compresion affects query performance a lot.

w/ zlib:

+------------+----------------------------+--------+--------+------+-----+------------+-----------+------------+------------+-------------+------------+---------+------------+
| benchmark  | subject                    | groups | params | revs | its | mem_peak   | best      | mean       | mode       | worst       | stdev      | rstdev  | diff       |
+------------+----------------------------+--------+--------+------+-----+------------+-----------+------------+------------+-------------+------------+---------+------------+
| QueryBench | benchPdoQueries            |        | []     | 1    | 10  | 4,439,176b | 1.17000ms | 1.87690ms  | 1.68573ms  | 3.83200ms   | 0.68067ms  | 36.27%  | 0.00%      |
| QueryBench | benchSyncQueries           |        | []     | 1    | 10  | 4,439,184b | 5.76100ms | 46.13990ms | 10.12466ms | 228.74400ms | 74.52826ms | 161.53% | +2,358.30% |
| QueryBench | benchAsyncQueries          |        | []     | 1    | 10  | 4,439,184b | 4.63700ms | 9.31360ms  | 6.30906ms  | 20.17200ms  | 4.89743ms  | 52.58%  | +396.22%   |
| QueryBench | benchAsyncQueriesUsingPool |        | []     | 1    | 10  | 6,633,522b | 3.53700ms | 4.33780ms  | 3.87706ms  | 6.75500ms   | 0.98273ms  | 22.65%  | +131.12%   |
+------------+----------------------------+--------+--------+------+-----+------------+-----------+------------+------------+-------------+------------+---------+------------+

w/o zlib:

+------------+----------------------------+--------+--------+------+-----+------------+-----------+-----------+-----------+------------+-----------+--------+----------+
| benchmark  | subject                    | groups | params | revs | its | mem_peak   | best      | mean      | mode      | worst      | stdev     | rstdev | diff     |
+------------+----------------------------+--------+--------+------+-----+------------+-----------+-----------+-----------+------------+-----------+--------+----------+
| QueryBench | benchPdoQueries            |        | []     | 1    | 10  | 4,433,944b | 1.28300ms | 1.50140ms | 1.52774ms | 1.76400ms  | 0.13752ms | 9.16%  | 0.00%    |
| QueryBench | benchSyncQueries           |        | []     | 1    | 10  | 4,433,952b | 4.29400ms | 7.52330ms | 4.86931ms | 15.60100ms | 4.11548ms | 54.70% | +401.09% |
| QueryBench | benchAsyncQueries          |        | []     | 1    | 10  | 4,433,952b | 3.94700ms | 4.96600ms | 4.40386ms | 9.93300ms  | 1.68206ms | 33.87% | +230.76% |
| QueryBench | benchAsyncQueriesUsingPool |        | []     | 1    | 10  | 6,592,336b | 2.97000ms | 3.20040ms | 3.27979ms | 3.35800ms  | 0.12980ms | 4.06%  | +113.16% |
+------------+----------------------------+--------+--------+------+-----+------------+-----------+-----------+-----------+------------+-----------+--------+----------+

Probably it must not be enabled by default when zlib is available.

Benchmark source: https://github.com/torinaki/mysql/blob/benchmarks/benchmarks/QueryBench.php

@dbalabka dbalabka changed the title zlib affects queries performance for non-pool connection zlib affects queries performance Sep 7, 2017
@bwoebi
Copy link
Member

bwoebi commented Sep 7, 2017

Probably a good point - usually you're anyway having the mysql server on the same machine or having a very high bandwidth to it, making CPU and not bandwidth the bottleneck...

@dbalabka
Copy link
Contributor Author

dbalabka commented Sep 7, 2017

@bwoebi I have take a look on compression/uncompression implementation and have following question. Have you considered possibility to use Stream Compression Filters instead of zlib_encode/zlib_decode? I just saw such approach in https://github.com/clue/php-zlib-react

@bwoebi
Copy link
Member

bwoebi commented Sep 7, 2017

It is not possible to reliably attach buffering stream filters to a non-blocking stream.

Thus: no.

@dbalabka
Copy link
Contributor Author

@bwoebi I have disabled compression and now the most time is spent on protocol parsing. Hoply when PHP JIT will be released it will perform much better.
Just A Thought. If I'm right mysqlnd already using PHP streams. It would be great if in future there will be possbile to parse MySQL protocol using mysqlnd implementation and native stream wrapper. Not sure is it possible to make it work with non-blocking streams(accoriding to your previous comment).

@bwoebi
Copy link
Member

bwoebi commented Sep 14, 2017

Yes, protocol parsing is the most CPU intensive part of this. Something like a JIT will probably indeed bring quite some benefit.

I'll look at disabling zlib compression by default.

@bwoebi bwoebi closed this as completed in 8f0bbc6 Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants