mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 11:01:52 +01:00
MDEV-25882: Statistics used to track b-tree (non-adaptive) searches
should be updated only when adaptive hashing is turned-on Currently, btr_cur_n_non_sea is used to track the search that missed adaptive hash index. adaptive hash index is turned off by default but the said variable is updated always though the value of it makes sense only when an adaptive index is enabled. It is meant to check how many searches didn't go through an adaptive hash index. Given a global variable that is updated on each search path it causes a contention with a multi-threaded workload. Patch moves the said variables inside a loop that is now updated only when the adaptive hash index is enabled and that in theory should also, reduce the update frequency of the said variable as the majority of the request should be serviced through the adaptive hash index. Variables (btr_cur_n_non_sea and btr_cur_n_sea) are also converted to use distributed counter to avoid contention. User visible changes: This also means that user will now see Innodb_adaptive_hash_non_hash_searches (viewed as part of show status) only if code is compiled with DWITH_INNODB_AHI=ON (default) and it will be updated only if innodb_adaptive_hash_index=1 else it reported as 0.
This commit is contained in:
parent
6fbf978eec
commit
102ff4208d
7 changed files with 30 additions and 26 deletions
|
@ -101,16 +101,16 @@ operations by purge as the previous, when it seems to be growing huge.
|
|||
throughput clearly from about 100000. */
|
||||
#define BTR_CUR_FINE_HISTORY_LENGTH 100000
|
||||
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
/** Number of searches down the B-tree in btr_cur_search_to_nth_level(). */
|
||||
Atomic_counter<ulint> btr_cur_n_non_sea;
|
||||
ib_counter_t<ulint, ib_counter_element_t> btr_cur_n_non_sea;
|
||||
/** Old value of btr_cur_n_non_sea. Copied by
|
||||
srv_refresh_innodb_monitor_stats(). Referenced by
|
||||
srv_printf_innodb_monitor(). */
|
||||
ulint btr_cur_n_non_sea_old;
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
/** Number of successful adaptive hash index lookups in
|
||||
btr_cur_search_to_nth_level(). */
|
||||
ulint btr_cur_n_sea;
|
||||
ib_counter_t<ulint, ib_counter_element_t> btr_cur_n_sea;
|
||||
/** Old value of btr_cur_n_sea. Copied by
|
||||
srv_refresh_innodb_monitor_stats(). Referenced by
|
||||
srv_printf_innodb_monitor(). */
|
||||
|
@ -1403,7 +1403,8 @@ btr_cur_search_to_nth_level_func(
|
|||
# ifdef UNIV_SEARCH_PERF_STAT
|
||||
info->n_searches++;
|
||||
# endif
|
||||
if (autoinc == 0
|
||||
if (!btr_search_enabled) {
|
||||
} else if (autoinc == 0
|
||||
&& !estimate
|
||||
&& latch_mode <= BTR_MODIFY_LEAF
|
||||
&& !modify_external
|
||||
|
@ -1429,13 +1430,14 @@ btr_cur_search_to_nth_level_func(
|
|||
|| mode != PAGE_CUR_LE);
|
||||
ut_ad(cursor->low_match != ULINT_UNDEFINED
|
||||
|| mode != PAGE_CUR_LE);
|
||||
btr_cur_n_sea++;
|
||||
++btr_cur_n_sea;
|
||||
|
||||
DBUG_RETURN(err);
|
||||
} else {
|
||||
++btr_cur_n_non_sea;
|
||||
}
|
||||
# endif /* BTR_CUR_HASH_ADAPT */
|
||||
#endif /* BTR_CUR_ADAPT */
|
||||
btr_cur_n_non_sea++;
|
||||
|
||||
/* If the hash search did not succeed, do binary search down the
|
||||
tree */
|
||||
|
|
|
@ -889,8 +889,9 @@ static MYSQL_THDVAR_STR(tmpdir,
|
|||
|
||||
static SHOW_VAR innodb_status_variables[]= {
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
{"adaptive_hash_hash_searches", &btr_cur_n_sea, SHOW_SIZE_T},
|
||||
{"adaptive_hash_non_hash_searches", &btr_cur_n_non_sea, SHOW_SIZE_T},
|
||||
{"adaptive_hash_hash_searches", &export_vars.innodb_ahi_hit, SHOW_SIZE_T},
|
||||
{"adaptive_hash_non_hash_searches",
|
||||
&export_vars.innodb_ahi_miss, SHOW_SIZE_T},
|
||||
#endif
|
||||
{"background_log_sync", &srv_log_writes_and_flush, SHOW_SIZE_T},
|
||||
{"buffer_pool_dump_status",
|
||||
|
|
|
@ -969,16 +969,16 @@ earlier version of the row. In rollback we are not allowed to free an
|
|||
inherited external field. */
|
||||
#define BTR_EXTERN_INHERITED_FLAG 64U
|
||||
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
/** Number of searches down the B-tree in btr_cur_search_to_nth_level(). */
|
||||
extern Atomic_counter<ulint> btr_cur_n_non_sea;
|
||||
extern ib_counter_t<ulint, ib_counter_element_t> btr_cur_n_non_sea;
|
||||
/** Old value of btr_cur_n_non_sea. Copied by
|
||||
srv_refresh_innodb_monitor_stats(). Referenced by
|
||||
srv_printf_innodb_monitor(). */
|
||||
extern ulint btr_cur_n_non_sea_old;
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
/** Number of successful adaptive hash index lookups in
|
||||
btr_cur_search_to_nth_level(). */
|
||||
extern ulint btr_cur_n_sea;
|
||||
extern ib_counter_t<ulint, ib_counter_element_t> btr_cur_n_sea;
|
||||
/** Old value of btr_cur_n_sea. Copied by
|
||||
srv_refresh_innodb_monitor_stats(). Referenced by
|
||||
srv_printf_innodb_monitor(). */
|
||||
|
|
|
@ -345,9 +345,7 @@ enum monitor_id_t {
|
|||
/* Adaptive Hash Index related counters */
|
||||
MONITOR_MODULE_ADAPTIVE_HASH,
|
||||
MONITOR_OVLD_ADAPTIVE_HASH_SEARCH,
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE,
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
MONITOR_ADAPTIVE_HASH_PAGE_ADDED,
|
||||
MONITOR_ADAPTIVE_HASH_PAGE_REMOVED,
|
||||
MONITOR_ADAPTIVE_HASH_ROW_ADDED,
|
||||
|
|
|
@ -697,6 +697,10 @@ void srv_master_thread_enable();
|
|||
|
||||
/** Status variables to be passed to MySQL */
|
||||
struct export_var_t{
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
ulint innodb_ahi_hit;
|
||||
ulint innodb_ahi_miss;
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
char innodb_buffer_pool_dump_status[OS_FILE_MAX_PATH + 128];/*!< Buf pool dump status */
|
||||
char innodb_buffer_pool_load_status[OS_FILE_MAX_PATH + 128];/*!< Buf pool load status */
|
||||
char innodb_buffer_pool_resize_status[512];/*!< Buf pool resize status */
|
||||
|
|
|
@ -959,7 +959,6 @@ static monitor_info_t innodb_counter_info[] =
|
|||
static_cast<monitor_type_t>(
|
||||
MONITOR_EXISTING | MONITOR_DEFAULT_ON),
|
||||
MONITOR_DEFAULT_START, MONITOR_OVLD_ADAPTIVE_HASH_SEARCH},
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
|
||||
{"adaptive_hash_searches_btree", "adaptive_hash_index",
|
||||
"Number of searches using B-tree on an index search",
|
||||
|
@ -967,7 +966,6 @@ static monitor_info_t innodb_counter_info[] =
|
|||
MONITOR_EXISTING | MONITOR_DEFAULT_ON),
|
||||
MONITOR_DEFAULT_START, MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE},
|
||||
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
{"adaptive_hash_pages_added", "adaptive_hash_index",
|
||||
"Number of index pages on which the Adaptive Hash Index is built",
|
||||
MONITOR_NONE,
|
||||
|
@ -1819,11 +1817,11 @@ srv_mon_process_existing_counter(
|
|||
case MONITOR_OVLD_ADAPTIVE_HASH_SEARCH:
|
||||
value = btr_cur_n_sea;
|
||||
break;
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
|
||||
case MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE:
|
||||
value = btr_cur_n_non_sea;
|
||||
break;
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
|
||||
case MONITOR_OVLD_PAGE_COMPRESS_SAVED:
|
||||
value = srv_stats.page_compression_saved;
|
||||
|
|
|
@ -699,8 +699,8 @@ static void srv_refresh_innodb_monitor_stats(time_t current_time)
|
|||
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
btr_cur_n_sea_old = btr_cur_n_sea;
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
btr_cur_n_non_sea_old = btr_cur_n_non_sea;
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
|
||||
log_refresh_stats();
|
||||
|
||||
|
@ -839,20 +839,18 @@ srv_printf_innodb_monitor(
|
|||
part->latch.rd_unlock();
|
||||
}
|
||||
|
||||
/* btr_cur_n_sea_old and btr_cur_n_non_sea_old are protected by
|
||||
srv_innodb_monitor_mutex (srv_refresh_innodb_monitor_stats) */
|
||||
const ulint with_ahi = btr_cur_n_sea, without_ahi = btr_cur_n_non_sea;
|
||||
fprintf(file,
|
||||
"%.2f hash searches/s, %.2f non-hash searches/s\n",
|
||||
static_cast<double>(btr_cur_n_sea - btr_cur_n_sea_old)
|
||||
static_cast<double>(with_ahi - btr_cur_n_sea_old)
|
||||
/ time_elapsed,
|
||||
static_cast<double>(btr_cur_n_non_sea - btr_cur_n_non_sea_old)
|
||||
/ time_elapsed);
|
||||
btr_cur_n_sea_old = btr_cur_n_sea;
|
||||
#else /* BTR_CUR_HASH_ADAPT */
|
||||
fprintf(file,
|
||||
"%.2f non-hash searches/s\n",
|
||||
static_cast<double>(btr_cur_n_non_sea - btr_cur_n_non_sea_old)
|
||||
static_cast<double>(without_ahi - btr_cur_n_non_sea_old)
|
||||
/ time_elapsed);
|
||||
btr_cur_n_sea_old = with_ahi;
|
||||
btr_cur_n_non_sea_old = without_ahi;
|
||||
#endif /* BTR_CUR_HASH_ADAPT */
|
||||
btr_cur_n_non_sea_old = btr_cur_n_non_sea;
|
||||
|
||||
fputs("---\n"
|
||||
"LOG\n"
|
||||
|
@ -968,6 +966,9 @@ srv_export_innodb_status(void)
|
|||
}
|
||||
|
||||
#ifdef BTR_CUR_HASH_ADAPT
|
||||
export_vars.innodb_ahi_hit = btr_cur_n_sea;
|
||||
export_vars.innodb_ahi_miss = btr_cur_n_non_sea;
|
||||
|
||||
ulint mem_adaptive_hash = 0;
|
||||
for (ulong i = 0; i < btr_ahi_parts; i++) {
|
||||
const auto part= &btr_search_sys.parts[i];
|
||||
|
|
Loading…
Add table
Reference in a new issue