skip to Main Content

I tested a mysql cluster using sysbench to figure out a sweet spot to set maximum threads to. In my endevours I came across the threads option in sysbench.

–threads=N

I also came across the thread_pool_size in Mysql Thread pool operations.

thread_pool_size: The number of thread groups in the thread pool. This is the most important parameter controlling thread pool performance.

So the question that plagues me is are the threads for sysbench similar to the thread_pool_size for mysql?

Here is an example of a command that I used.
sysbench oltp_read_write.lua --threads=26 --time=30 --mysql-user='root' --mysql-password='password' --table-size=10000 --mysql-host=10.100.100.64 --mysql-port=6033 run

This is an image to show my current configuration:
CNFfiles

2

Answers


  1. Sysbench is a client of MySQL. It can start a number of threads, one per connection.

    When not using a thread pool in MySQL Server, every client connection starts its own thread. So there’s a one-to-one correspondence between sysbench threads and MySQL Server threads.

    It’s typical that a client connection is not running a query every second. Normally a client application runs other code in between waiting for queries. So on the MySQL Server side, some threads exist, but they aren’t doing anything. This appears as "Sleep" in the processlist.

    It’s pretty common to have hundreds of client connections open, but only one or two dozen of these connections doing any query at any given moment. The others are all sleeping.

    As a metaphor, I would compare this to customers in a bank, where they approach a teller’s window and do transactions. The customer blocks others from using the same teller, even if the customer is signing a form or something else that is not talking directly to the teller.

    When using a thread pool, threads are handled differently in MySQL Server. The thread pool feature exists so that a smaller number of threads in the MySQL Server can be shared by a greater number of client connections. The threads in MySQL Server are no longer corresponding one-to-one with client connections. They switch when a client connection requests to execute an SQL query. This is done to reduce resource usage when your clients open a large number of connections.

    A metaphor for this is a restaurant where a single server can handle a whole section with customers. The customers only need attention from time to time, and the server can therefore keep track of multiple tables of customers.

    In the case of sysbench, this is probably not a typical workload. The client threads are running SQL queries more rapidly than a typical application. If you try to use a thread pool in this case, you might have more client requests than the number of threads in the thread pool, and in this case the client requests might queue up.

    In the restaurant metaphor, this would be the infrequent times when more than one table wants something at the same time. Then all but one of the tables must wait, but hopefully not for long since most customer requests are brief.

    Using the thread pool in MySQL Server while testing with sysbench might not be the best way to measure the maximum throughput of queries.

    Login or Signup to reply.
  2. OUCH!

    thread_cache_size is the number of "threads" to hang onto. It is a simpleminded pooling. It is a number not bytes!! 10 is a reasonable number. Anything more than max_connections is unnecessary.

    max_connections refers to "concurrent" connections, not total over time. The default of 151 is fine for most systems. 1000 is "high" but is warranted for some systems; 10K is too high.

    Check these:

    SHOW GLOBAL STATUS LIKE 'Max_used_connections';
    SHOW GLOBAL STATUS LIKE 'Threads_running';
    

    The former is a high-water mark (since startup). If it is close to max_connections, then maybe max_connections should be increased.

    The latter says how many of the current connections are actually doing anything. If it is over 100, the connections are stumbling over each other. We will need more details to discuss what to do next. (1 is common; a ‘busy’ system might say no more than 10, and change rapidly.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search