Skip to content

Commit 18f88d6

Browse files
committed
MDEV-7943 - pthread_getspecific() takes 0.76% in OLTP RO
Avoid calling current_thd from thd_kill_level(). This reduces number of pthread_getspecific() calls from 776 to 354. Also thd_kill_level(NULL) is not permitted anymore: this saves one condition.
1 parent f8cacd0 commit 18f88d6

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

plugin/semisync/semisync_master.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
635635
(int)is_on());
636636
}
637637

638-
while (is_on() && !thd_killed(NULL))
638+
while (is_on() && !thd_killed(current_thd))
639639
{
640640
if (reply_file_name_inited_)
641641
{
@@ -747,7 +747,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
747747
At this point, the binlog file and position of this transaction
748748
must have been removed from ActiveTranx.
749749
*/
750-
assert(thd_killed(NULL) ||
750+
assert(thd_killed(current_thd) ||
751751
!active_tranxs_->is_tranx_end_pos(trx_wait_binlog_name,
752752
trx_wait_binlog_pos));
753753

sql/sql_class.cc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4205,23 +4205,30 @@ extern "C" int thd_killed(const MYSQL_THD thd)
42054205
/*
42064206
return thd->killed status to the client,
42074207
mapped to the API enum thd_kill_levels values.
4208+
4209+
@note Since this function is called quite frequently thd_kill_level(NULL) is
4210+
forbidden for performance reasons (saves one conditional branch). If your ever
4211+
need to call thd_kill_level() when THD is not available, you options are (most
4212+
to least preferred):
4213+
- try to pass THD through to thd_kill_level()
4214+
- add current_thd to some service and use thd_killed(current_thd)
4215+
- add thd_killed_current() function to kill statement service
4216+
- add if (!thd) thd= current_thd here
42084217
*/
42094218
extern "C" enum thd_kill_levels thd_kill_level(const MYSQL_THD thd)
42104219
{
4211-
THD* current= current_thd;
4212-
4213-
if (!thd)
4214-
thd= current;
4215-
4216-
if (thd == current)
4217-
{
4218-
Apc_target *apc_target= (Apc_target*)&thd->apc_target;
4219-
if (apc_target->have_apc_requests())
4220-
apc_target->process_apc_requests();
4221-
}
4220+
DBUG_ASSERT(thd);
42224221

42234222
if (likely(thd->killed == NOT_KILLED))
4223+
{
4224+
Apc_target *apc_target= (Apc_target*) &thd->apc_target;
4225+
if (unlikely(apc_target->have_apc_requests()))
4226+
{
4227+
if (thd == current_thd)
4228+
apc_target->process_apc_requests();
4229+
}
42244230
return THD_IS_NOT_KILLED;
4231+
}
42254232

42264233
return thd->killed & KILL_HARD_BIT ? THD_ABORT_ASAP : THD_ABORT_SOFTLY;
42274234
}

0 commit comments

Comments
 (0)