Bug #113482 | innodb_parallel_read_threads>1 makes simple select count more expensive | ||
---|---|---|---|
Submitted: | 21 Dec 2023 9:23 | Modified: | 24 Jun 20:52 |
Reporter: | Przemyslaw Malkowski | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S5 (Performance) |
Version: | 8.0.35, 8.2.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | innodb_parallel_read_threads, select count |
[21 Dec 2023 9:23]
Przemyslaw Malkowski
[21 Dec 2023 20:35]
MySQL Verification Team
Hi, Thank you for the report.
[28 Dec 2023 17:51]
Marcin Babij
Posted by developer: Thank you Przemek for the report. Indeed there is a problem and it was not found during development, as the testing was using data cached in the Buffer Pool, leading to no IO read requests. The most of the work was with processing data so it was nicely parallelized and gave good results. However, once the data is not in the buffer pool, it gets read in. And in comparison to a single threaded scan, the linear read ahead was not used, leading to much worse performance. There is a lot more waiting for data to be read in as these next 64 pages of linear read ahead are not being read in background. This is especilly visible on data stored on an old HDD, where threads=1 on your data takes 13.5s, while for threads=2 it takes 62s. If the code is modified to use linear readahead for parallel scan, the performance improves a lot. However, while one thread with read ahead is enough to saturate a single HDD with ~125MB/s, it only gets worse if multiple threads are used, exactly two times slower in my case. The fix will be evaluated more. Could you confirm that you have a small BufferPool (smaller than the 2GB that the input data file has), or start with empty BP before each test? What type of drive do you use for tests?
[29 Dec 2023 7:03]
Przemyslaw Malkowski
Hi Marcin, > Could you confirm that you have a small BufferPool (smaller than the 2GB that the input data file has), or start with empty BP before each test? Yes, I used default BP, so 128MB. > What type of drive do you use for tests? It's NVMe drive, it does ~8.8k read IOPS during the select count.
[15 Apr 17:41]
Philip Olson
Posted by developer: Fixed as of the upcoming MySQL Server 8.0.37 and 8.4.0 releases, and here's the proposed changelog entry from the documentation team: When using innodb_parallel_read_threads values greater than 1, InnoDB would unnecessarily disable read-ahead heuristics which resulted in stalls when pages were not already in the buffer pool. Thank you for the detailed bug report.
[24 Jun 20:52]
Przemyslaw Malkowski
Excellent, great job! Now 8.0.37 is much faster in my quick test in both single-thread and multi-threaded mode! mysql > select @@version,@@innodb_buffer_pool_size,@@innodb_parallel_read_threads; +-----------+---------------------------+--------------------------------+ | @@version | @@innodb_buffer_pool_size | @@innodb_parallel_read_threads | +-----------+---------------------------+--------------------------------+ | 8.0.37 | 134217728 | 2 | +-----------+---------------------------+--------------------------------+ 1 row in set (0.00 sec) mysql > select count(*) from sbtest1; +----------+ | count(*) | +----------+ | 10000000 | +----------+ 1 row in set (1.64 sec) Thanks for fixing this one quickly!