Bug #95390 | wake up log_closer background thread in log_wait_for_space_in_log_recent_closed | ||
---|---|---|---|
Submitted: | 16 May 2019 9:57 | Modified: | 16 May 2019 13:20 |
Reporter: | Fungo Wang (OCA) | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S5 (Performance) |
Version: | 8.0.16 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[16 May 2019 9:57]
Fungo Wang
[16 May 2019 12:17]
MySQL Verification Team
HI, Thank you for your bug report, dealing with the performance of the InnoDB SE. I have analysed thoroughly and based on the code analysis alone, I must admit that I agree with you. Verified as reported.
[16 May 2019 13:20]
Fungo Wang
Hi Sinisa, Thanks for the verification. After show this perf case to my colleague Weixiang, he suggest to add a check for whether log.closer_event is already set by others, instead of blindly waking up every time, to reduce the system spin lock cause by mutex. diff --git a/storage/innobase/log/log0buf.cc b/storage/innobase/log/log0buf.cc index 371596f3055..26b5c4fd85c 100644 --- a/storage/innobase/log/log0buf.cc +++ b/storage/innobase/log/log0buf.cc @@ -938,6 +938,9 @@ void log_wait_for_space_in_log_recent_closed(log_t &log, lsn_t lsn) { uint64_t wait_loops = 0; while (!log.recent_closed.has_space(lsn)) { + if (!os_event_is_set(log.closer_event)) { + os_event_set(log.closer_event); + } ++wait_loops; os_thread_sleep(20); } The perf result exactly shows spin_lock is reduced, and log_wait_for_space_in_log_recent_closed has gone away from the trace. With patch 1 ========= + 41.56% mysqld mysqld [.] ut_delay(unsigned long) - 3.57% mysqld [kernel.kallsyms] [k] _spin_lock - _spin_lock - 43.79% futex_wait_setup futex_wait do_futex sys_futex - system_call_fastpath - 88.38% __lll_lock_wait + 44.06% Stage_manager::enroll_for(Stage_manager::StageID, THD*, mysql_mutex_t*) + 34.57% Gtid_state::update_gtids_impl(THD*, bool) + 6.26% log_wait_for_space_in_log_recent_closed(log_t&, unsigned long) + 6.03% MYSQL_BIN_LOG::change_stage(THD*, Stage_manager::StageID, THD*, mysql_mutex_t*, mysql_mutex_t*) + 3.85% sync_array_reserve_cell(sync_array_t*, void*, unsigned long, char const*, unsigned long) + 2.54% MYSQL_BIN_LOG::ordered_commit(THD*, bool, bool) + 1.15% MYSQL_BIN_LOG::assign_automatic_gtids_to_flush_group(THD*) + 0.62% memo_slot_release(mtr_memo_slot_t*) + 0.51% sync_array_wait_event(sync_array_t*, sync_cell_t*&) + 11.05% pthread_cond_wait@@GLIBC_2.3.2 + 0.57% pthread_cond_timedwait@@GLIBC_2.3.2 + 29.37% futex_wake + 10.26% task_rq_lock + 4.68% try_to_wake_up + 3.15% double_lock_balance + 2.38% futex_requeue + 1.54% start_this_handle + 1.29% thread_return + 0.56% mod_timer With patch 2 ========= + 42.96% mysqld mysqld [.] ut_delay(unsigned long) - 3.25% mysqld [kernel.kallsyms] [k] _spin_lock - _spin_lock - 38.74% futex_wait_setup futex_wait do_futex sys_futex - system_call_fastpath - 64.95% __lll_lock_wait + 42.58% Gtid_state::update_gtids_impl(THD*, bool) + 36.96% Stage_manager::enroll_for(Stage_manager::StageID, THD*, mysql_mutex_t*) + 7.68% MYSQL_BIN_LOG::change_stage(THD*, Stage_manager::StageID, THD*, mysql_mutex_t*, mysql_mutex_t*) + 6.66% MYSQL_BIN_LOG::ordered_commit(THD*, bool, bool) + 2.37% memo_slot_release(mtr_memo_slot_t*) + 1.56% sync_array_wait_event(sync_array_t*, sync_cell_t*&) + 1.10% MYSQL_BIN_LOG::assign_automatic_gtids_to_flush_group(THD*) + 34.36% pthread_cond_wait@@GLIBC_2.3.2 + 0.69% pthread_cond_timedwait@@GLIBC_2.3.2 + 32.44% futex_wake + 11.13% task_rq_lock + 5.29% try_to_wake_up + 2.87% double_lock_balance + 2.86% futex_requeue + 1.53% start_this_handle + 1.36% thread_return + 0.74% mod_timer
[16 May 2019 13:25]
MySQL Verification Team
Thank you for the additional code changes.