Skip to content

Commit 8f603bc

Browse files
committed
MDEV-7952 - clock_gettime() takes 0.24% in OLTP RO
Initialize abs_timeout when it is about to be used. This saves one my_hrtime() call on hot path (when we acquire MDL lock without waiting). When filling I_S.PROCESSLIST use THD::start_utime/THD::utime_after_query instead of THD::start_time. This allows us to save 2 clock_gettime() calls. Overhead change: __clock_gettime 0.13% -> 0.11% (122 -> 76 calls per OLTP RO transaction) my_interval_timer 0.07% -> 0.06% my_hrtime 0.04% -> 0.01%
1 parent 2bc6e29 commit 8f603bc

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

sql/mdl.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,14 +1972,10 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout)
19721972
{
19731973
MDL_lock *lock;
19741974
MDL_ticket *ticket;
1975-
struct timespec abs_timeout;
19761975
MDL_wait::enum_wait_status wait_status;
19771976
DBUG_ENTER("MDL_context::acquire_lock");
19781977
DBUG_PRINT("enter", ("lock_type: %d", mdl_request->type));
19791978

1980-
/* Do some work outside the critical section. */
1981-
set_timespec(abs_timeout, lock_wait_timeout);
1982-
19831979
if (try_acquire_lock_impl(mdl_request, &ticket))
19841980
DBUG_RETURN(TRUE);
19851981

@@ -2028,7 +2024,8 @@ MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout)
20282024

20292025
find_deadlock();
20302026

2031-
struct timespec abs_shortwait;
2027+
struct timespec abs_timeout, abs_shortwait;
2028+
set_timespec(abs_timeout, lock_wait_timeout);
20322029
set_timespec(abs_shortwait, 1);
20332030
wait_status= MDL_wait::EMPTY;
20342031

sql/sql_class.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ THD::THD(bool is_wsrep_applier)
947947
// Must be reset to handle error with THD's created for init of mysqld
948948
lex->current_select= 0;
949949
user_time.val= start_time= start_time_sec_part= 0;
950-
start_utime= prior_thr_create_utime= 0L;
950+
start_utime= utime_after_query= prior_thr_create_utime= 0L;
951951
utime_after_lock= 0L;
952952
progress.arena= 0;
953953
progress.report_to_client= 0;

sql/sql_parse.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
19431943
thd->m_statement_psi= NULL;
19441944
thd->m_digest= NULL;
19451945

1946-
thd->set_time();
19471946
dec_thread_running();
19481947
thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
19491948
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));

sql/sql_show.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ class thread_info :public ilink {
23012301
{ TRASH(ptr, size); }
23022302

23032303
ulong thread_id;
2304-
time_t start_time;
2304+
ulonglong start_time;
23052305
uint command;
23062306
const char *user,*host,*db,*proc_info,*state_info;
23072307
CSET_STRING query_string;
@@ -2432,15 +2432,18 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
24322432
}
24332433
else
24342434
thd_info->progress= 0.0;
2435-
thd_info->start_time= tmp->start_time;
2435+
thd_info->start_time= tmp->start_utime;
2436+
ulonglong utime_after_query_snapshot= tmp->utime_after_query;
2437+
if (thd_info->start_time < utime_after_query_snapshot)
2438+
thd_info->start_time= utime_after_query_snapshot; // COM_SLEEP
24362439
mysql_mutex_unlock(&tmp->LOCK_thd_data);
24372440
thread_infos.append(thd_info);
24382441
}
24392442
}
24402443
mysql_mutex_unlock(&LOCK_thread_count);
24412444

24422445
thread_info *thd_info;
2443-
time_t now= my_time(0);
2446+
ulonglong now= microsecond_interval_timer();
24442447
char buff[20]; // For progress
24452448
String store_buffer(buff, sizeof(buff), system_charset_info);
24462449

@@ -2455,8 +2458,8 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
24552458
protocol->store(thd_info->proc_info, system_charset_info);
24562459
else
24572460
protocol->store(command_name[thd_info->command].str, system_charset_info);
2458-
if (thd_info->start_time)
2459-
protocol->store_long ((longlong) (now - thd_info->start_time));
2461+
if (thd_info->start_time && now > thd_info->start_time)
2462+
protocol->store_long(now - thd_info->start_time);
24602463
else
24612464
protocol->store_null();
24622465
protocol->store(thd_info->state_info, system_charset_info);
@@ -2730,7 +2733,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
27302733
TABLE *table= tables->table;
27312734
CHARSET_INFO *cs= system_charset_info;
27322735
char *user;
2733-
my_hrtime_t unow= my_hrtime();
2736+
ulonglong unow= microsecond_interval_timer();
27342737
DBUG_ENTER("fill_schema_processlist");
27352738

27362739
DEBUG_SYNC(thd,"fill_schema_processlist_after_unow");
@@ -2793,9 +2796,12 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
27932796
table->field[4]->store(command_name[tmp->get_command()].str,
27942797
command_name[tmp->get_command()].length, cs);
27952798
/* MYSQL_TIME */
2796-
ulonglong start_utime= tmp->start_time * HRTIME_RESOLUTION + tmp->start_time_sec_part;
2797-
ulonglong utime= start_utime && start_utime < unow.val
2798-
? unow.val - start_utime : 0;
2799+
ulonglong utime= tmp->start_utime;
2800+
ulonglong utime_after_query_snapshot= tmp->utime_after_query;
2801+
if (utime < utime_after_query_snapshot)
2802+
utime= utime_after_query_snapshot; // COM_SLEEP
2803+
utime= utime && utime < unow ? unow - utime : 0;
2804+
27992805
table->field[5]->store(utime / HRTIME_RESOLUTION, TRUE);
28002806
/* STATE */
28012807
if ((val= thread_state_info(tmp)))

0 commit comments

Comments
 (0)