Rate This Document
Findability
Accuracy
Completeness
Readability

Sysbench 0.5

Before the compilation and installation, modify the drv_mysql.c code to avoid initialization timeout in high concurrency scenarios.

  1. Modify the drv_mysql.c file.

    You can modify the drv_mysql.c code to solve the initialization timeout problem when 512 concurrent threads are used in the mix scenario. The error information is as follows:

    1
    FATAL: Worker threads failed to initialize within 30 seconds!
    

    You can add a timeout parameter when the client initiates a connection request so that a response is returned when the connection times out. Then, the client initiates a connection request again. In this way, the initialization timeout problem can be avoided to ensure the normal running of the program.

    1. Open the drv_mysql.c file.
      1
      vi /home/sysbench-0.5/sysbench/drivers/mysql/drv_mysql.c
      
    2. Find "return mysql_real_connect(....) == NULL;" at the end of the mysql_drv_real_connect function.

    3. Press i to enter the insert mode. Replace return mysql_real_connect(....) == NULL with the following code:
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      #if 0
        return mysql_real_connect(con,
                                  db_mysql_con->host,
                                  db_mysql_con->user,
                                  db_mysql_con->password,
                                  db_mysql_con->db,
                                  db_mysql_con->port,
                                  db_mysql_con->socket,
      #if MYSQL_VERSION_ID >= 50000
                                  CLIENT_MULTI_STATEMENTS
      #else
                                  0
      #endif
                                  ) == NULL;
      #else
        unsigned int timeout = 5;
       
        if (mysql_options(con, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&timeout)) {
          DEBUG("0x%p mysql_options MYSQL_OPT_CONNECT_TIMEOUT failed", con);
        }
        
        int ret = 0;
        int i = 0;
        for (; i < 5; i++) {
          ret = (mysql_real_connect(con,
                                  db_mysql_con->host,
                                  db_mysql_con->user,
                                  db_mysql_con->password,
                                  db_mysql_con->db,
                                  db_mysql_con->port,
                                  db_mysql_con->socket,
      #if MYSQL_VERSION_ID >= 50000
                                  CLIENT_MULTI_STATEMENTS
      #else
                                  0
      #endif
                                  ) == NULL);
          if (ret == 0) {
            DEBUG("0x%p mysql_options succeed", con);
            break;
          }
       
          DEBUG("0x%p mysql_options MYSQL_OPT_CONNECT_TIMEOUT timeout", con);
          usleep(1000);
        }
       
        return ret;
      #endif
      
    4. Press Esc, type :wq!, and press Enter to save the file and exit.
  2. Go to the directory where the Sysbench source code is located.
    1
    cd /home/sysbench-0.5
    
  3. Perform compilation and installation.
    1
    2
    3
    4
    ./autogen.sh
    ./configure
    make -j128
    make -j128 install
    

    The number following -j indicates the number of CPU cores needed for parallel compilation. The value must be less than or equal to the number of CPU cores. You can run the following command to view the number of CPU cores:

    1
    cat /proc/cpuinfo | grep processor | wc -l
    
  4. View the Sysbench version.
    1
    sysbench --version
    

    Expected result:

    1
    sysbench 0.5