[MDEV-16264] Implement a common work queue for InnoDB background tasks Created: 2018-05-23 Updated: 2023-12-11 Resolved: 2019-11-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Fix Version/s: | 10.5.0 |
| Type: | Task | Priority: | Critical |
| Reporter: | Marko Mäkelä | Assignee: | Vladislav Vaintroub |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | performance, thread, threadpool | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
InnoDB creates a large number of threads that are specializing on a single task. This makes debugging hard, because core dumps contain stack traces for a large number of threads. It also causes unnecessary thread stack allocation and increases the complexity of scheduling threads. Many of the threads are waking up periodically, polling for work(for those, we can introduce a timer task , for example OS timers would submit work to common pool). A lot of CPU and context switching is nowadays spent on "coordinator" threads(purge, page-cleaner). We should make InnoDB use a pool of threads, and scale the size of this pool based on the workload. There should be a common work queue for all the threads. All of the following background threads would be replaced by the common thread pool, listed in roughly descending order of impact/difficulty ratio:
Some of the following might still need dedicated threads:
I/O cleanupWe should implement native asynchronous I/O on BSD systems using kevent(), and remove the support for simulated asynchronous I/O threads. Pending read requests can be directly waited for by buf_page_get_gen(). If read-ahead is desired, that can be implemented by adding a read completion request when handling the I/O completion. High level overview of what was done so farA library tpool that encapsulated the threadpool implementation.Threadpool is capable of
Changes in server
Changes in InnodbThe "ticker" (srv_master_thread, lock_wait_timeout_thread, srv_error_monitor_thread,srv_monitor_thread) threads are mapped to periodic timers. IO handler threads are gone, substituted with thread_pool::submit_io() and passing the callback on completion. Al others threads with exception of buf_flush_page_cleaner_coordinator, recv_writer_thread, fil_crypt_thread, log_scrub_thread are gone and replaced by either tasks, timers or, as in case of purge threads, with combination of tasks and timers . The purge coordinator has idle state, where it sleeps a little and rechecks if work is still there, and for that timer was used. Purge preallocates/caches background THDs, and purge task attach these THDs when they start, and detach when they are finished. Sometimes there were threads that did fork/join type of work (fts_parallel..., purge), where one tasks waits for others to complete, for that special "waitable" tasks were used. Except AIO, there were no big changes in existing logic . Some things can be improved and simplified later. The limits for different kind of tasks are still in place, i.e innodb_purge_threads are still there, only that they limit concurrency of a specific task. |
| Comments |
| Comment by Marko Mäkelä [ 2019-11-15 ] |
|
I pushed some suggested cleanups to bb-10.5-wlad. OK to push to 10.5. I spotted some future cleanup opportunity, which I will note in other tasks:
|
| Comment by Marko Mäkelä [ 2022-12-16 ] |
|
SRV_MAX_N_IO_THREADS was removed in |