0

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

Amix
  • 1
  • 1
  • 1
    What do you mean by similar? Do you mean that they should be set to the same value? If so, then no, they are not similar. – Bill Karwin Dec 26 '22 at 21:51
  • What version of MySQL/MariaDB/Percona are you running? `thread_cache_size`? `max_connections`? – Rick James Dec 27 '22 at 03:41
  • @BillKarwin They do not represent the same thing? is thread_pool_size not the number of threads for the MySQL processes? And aren't threads from sysbench the number of MySQL processes created by sysbench? – Amix Jan 01 '23 at 23:06
  • @RickJames I am using MYSQL 5.7. Max_connections are set to 10000 and thread_cache_size to 16Mb – Amix Jan 01 '23 at 23:08
  • `--threads=26` -- How many cores on your server? – Rick James Jan 07 '23 at 16:41
  • 8 cores Intel(R) Xeon(R) CPU E3-1245 V2 @ 3.40GHz Little endian – Amix Jan 08 '23 at 18:51

2 Answers2

0

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.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • Thank you... What would be the best way to measure the throughput? – Amix Jan 03 '23 at 14:05
  • Sysbench measures throughput in queries per second and transactions per second. – Bill Karwin Jan 03 '23 at 17:30
  • Am still at a loss here... While using threads I was able to identify the optimum number of threads with the highest queries per second and transactions per second. I would appreciate more ideas I could use. – Amix Jan 07 '23 at 02:29
0

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.)

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Oh sorry... I can see I had not set that yet. However, thank you for the info. I have attached an image with the setting that I have used for a database-intensive application. Do you mind checking it and let me know if I will have issues with those settings? – Amix Jan 03 '23 at 14:02
  • The image says MySQL 8.0; your question says 5.7. Please fix one or the other. Meanwhile, I hope you have no MyISAM tables, do you? – Rick James Jan 03 '23 at 22:10
  • Mysql version is 5.7.. the version on image is for proxysql.. Am using it as a proxy for a master-slave architecture. The image shows the command I use to connect to the cluster through proxysql. – Amix Jan 07 '23 at 02:20