Skip to content

Instantly share code, notes, and snippets.

@aagontuk
Last active January 17, 2021 17:14
Show Gist options
  • Select an option

  • Save aagontuk/306f8972d3c4379f6742c1b511843d39 to your computer and use it in GitHub Desktop.

Select an option

Save aagontuk/306f8972d3c4379f6742c1b511843d39 to your computer and use it in GitHub Desktop.
Setup mysqld for BOLT and profile collection

Setup

  • clone mysql-server repo from github
  • Download and extract appropriate boost C++ library
  • Add following lines to CMakeLists.txt file if you are building using GCC otherwise bolt won't work.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-reorder-blocks-and-partition")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-reorder-blocks-and-partition")
  • Due to bug gold linker doesn't work with relocation flags on. Better use llvm compiler suite.

  • Build mysqld with relocation flag:

$ export LDFLAGS="-wl,-q"
$ mkdir build
$ cmake ../mysql-server -DWITH_BOOST=../boost -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_LINKER=lld
$ make
  • Initialize mysqld:
$ cd build
$ mkdir data
$ ./bin/mysqld --initialize --datadir=./data --language=./share/english --log-error=./data/error.log

Rather than providing the option you can specify them in $HOME/.my.conf file before initializing. An example of .my.conf file can be found here

  • Run the server to create default user:
$ ./bin/mysqld --console
  • Now run mysql server with root permission. So that root password can be changed:
$ ./bin/mysqld --console --skip-grant-tables
  • Log in to the mysql client and change the root password:
$ mysql -u root -p
mysql > FLUSH PRIVILEGES;
mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  • Run the server with normal privilege:
$ ./bin/mysqld --console

Now you are ready collecting profile for BOLT.

Profile collection

As an example we will collect profile for insert operation using sysbench for 180s.

  • Install sysbench. You will find instructions here. Recent version of sysbench is causing issues. Use commit from 5 May 2020. Hash 805825fa81f633a7477f15ecdc152441e4ef4c83.

  • Now create a database name 'sbtest' for the sysbench benchmark:

$ mysql -u root -p
CREATE DATABASE sbtest;
  • Prepare/Run sysbench:
$ sysbench oltp_insert --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password='MyNewPass' --mysql-db=sbtest --db-driver=mysql --tables=3 --table-size=0 --delete_inserts=10 --threads=4 --time=180 prepare
$ sysbench oltp_insert --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password='MyNewPass' --mysql-db=sbtest --db-driver=mysql --tables=3 --table-size=0 --delete_inserts=10 --threads=4 --time=180 run
  • Collect perf profile:
$ perf record -e cycles:u -j u,any -p mysqld_pid -- sleep 180
  • Do BOLT on mysqld with the profile.

You will examples for other operations(insert/delete) in the benchmark script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment