Skip to content

Commit

Permalink
Replace the default indexer for ib_counter_t values for performance
Browse files Browse the repository at this point in the history
Summary: The default indexer for ib_counter_t values uses the result from 'pthread_self() % 64' to index into an array.  Since pthread_self() likely returns a pointer to an internal structure on 64-bit platforms 'pthread_self() % 64' will often (always?) result in 0.  This diff switches to using a different indexer that uses the current CPU when the sched_getcpu() function is available.

Test Plan: MTR

Reviewers: yoshinorim, MarkCallaghan

Reviewed By: MarkCallaghan

Subscribers: webscalesql-eng

Differential Revision: https://reviews.facebook.net/D65427
  • Loading branch information
jkedgar committed Oct 25, 2016
1 parent 713543b commit d83fe82
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/ut0counter.h
Expand Up @@ -55,7 +55,8 @@ struct generic_indexer_t {
};

#ifdef HAVE_SCHED_GETCPU
#include <utmpx.h>
//#include <utmpx.h> // Including this causes problems with EMPTY symbol
#include <sched.h> // Include this instead
/** Use the cpu id to index into the counter array. If it fails then
use the thread id. */
template <typename Type, int N>
Expand All @@ -66,7 +67,7 @@ struct get_sched_indexer_t : public generic_indexer_t<Type, N> {
size_t get_rnd_index() const {

size_t cpu = sched_getcpu();
if (cpu == -1) {
if (cpu == (size_t) -1) {
cpu = get_curr_thread_id();
}

Expand Down
5 changes: 5 additions & 0 deletions storage/rocksdb/CMakeLists.txt
Expand Up @@ -4,6 +4,11 @@ IF (NOT EXISTS "${CMAKE_SOURCE_DIR}/rocksdb/Makefile")
MESSAGE(SEND_ERROR "Missing Makefile in rocksdb directory. Try \"git submodule update\".")
ENDIF()

CHECK_FUNCTION_EXISTS(sched_getcpu HAVE_SCHED_GETCPU)
IF(HAVE_SCHED_GETCPU)
ADD_DEFINITIONS(-DHAVE_SCHED_GETCPU=1)
ENDIF()

# get a list of rocksdb library source files
# run with env -i to avoid passing variables
EXECUTE_PROCESS(
Expand Down
12 changes: 12 additions & 0 deletions storage/rocksdb/ha_rocksdb.cc
Expand Up @@ -3641,6 +3641,18 @@ static int rocksdb_init_func(void *p)
rdb->PauseBackgroundWork();
}

// NO_LINT_DEBUG
sql_print_information("RocksDB: global statistics using %s indexer",
STRINGIFY_ARG(RDB_INDEXER));
#if defined(HAVE_SCHED_GETCPU)
if (sched_getcpu() == -1)
{
// NO_LINT_DEBUG
sql_print_information("RocksDB: sched_getcpu() failed - "
"global statistics will use thread_id_indexer_t instead");
}
#endif

sql_print_information("RocksDB instance opened");
DBUG_RETURN(0);
}
Expand Down
10 changes: 8 additions & 2 deletions storage/rocksdb/ha_rocksdb.h
Expand Up @@ -237,13 +237,19 @@ enum operation_type {
ROWS_MAX
};

#if defined(HAVE_SCHED_GETCPU)
#define RDB_INDEXER get_sched_indexer_t
#else
#define RDB_INDEXER thread_id_indexer_t
#endif

/* Global statistics struct used inside MyRocks */
struct st_global_stats {
ib_counter_t<ulonglong, 64> rows[ROWS_MAX];
ib_counter_t<ulonglong, 64, RDB_INDEXER> rows[ROWS_MAX];

// system_rows_ stats are only for system
// tables. They are not counted in rows_* stats.
ib_counter_t<ulonglong, 64> system_rows[ROWS_MAX];
ib_counter_t<ulonglong, 64, RDB_INDEXER> system_rows[ROWS_MAX];
};

/* Struct used for exporting status to MySQL */
Expand Down

0 comments on commit d83fe82

Please sign in to comment.