Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the max number of MySQL processes or threads?

ps axuw| grep mysql indicates only MySQL process, but if I run htop I can see 10 rows each one of them with a separate PID. So I wonder if they are threads or processes that for some reason I cannot see using ps.

Would it make any sense to try to limit them to two on my development machine, where I don't need concurrent access of many clients.

BTW Running on Ubuntu 8.10

like image 223
szabgab Avatar asked Mar 07 '09 08:03

szabgab


People also ask

How many threads can MySQL handle?

The maximum number of threads per group is 4096 (or 4095 on some systems where one thread is used internally). The thread pool separates connections and threads, so there is no fixed relationship between connections and the threads that execute statements received from those connections.

Is MySQL single threaded or multithreaded?

MySQL is fully multithreaded, and makes use of all CPUs made available to it. Not all CPUs may be available; modern operating systems should be able to utilize all underlying CPUs, but also make it possible to restrict a process to a specific CPU or sets of CPUs.

How do I see what MySQL threads are running?

The 'SHOW processlist' command can be used to display the running thread related to only your MySQL account. We can see almost all running threads if we have process privileges. It shows which threads are running.

What is thread pool in MySQL?

The MySQL Thread Pool is a MySQL server plugin that extends the default connection-handling capabilities of the MySQL server to limit the number of concurrently executing statements/queries and transactions to ensure that each has sufficient CPU and memory resources to fulfill its task.


2 Answers

You can set the max number of threads in your my.ini like this:

max_connections=2 

However you might also want to set this:

thread_cache_size=1 

The thread cache controls how many it keeps open even when nothing is happening.

like image 80
Greg Avatar answered Oct 04 '22 16:10

Greg


MySQL does use threads, ps can see them if you run ps -eLf.

That said, I wouldn't worry about it - dormant threads use almost no resources whatsoever, and if you constrain the server too much it's bound to come back and bite you on the backside sometime later when you've forgotten that you did it.

like image 44
Alnitak Avatar answered Oct 04 '22 15:10

Alnitak