4

When I run 'show processlist;', then I get so many sleep processes.

show processlist;

I set wait_timeout and interactive_timeout to 60 in my.cnf. But, sleep process is not died when time 60 on processlist. I found that sleep process is died when time is 7900. What happend?? How can I decrease sleep process's time out?

If you need other information, I will give information as I possible.

UPDATE

I use root, read_only and deploy account on mysql. And I found root and read_only accounts run correct. Query -> Sleep -(60sec)-> release process.

But deploy account, using to connect between rails server and mysql, run wrong. Query -> Sleep -(7900sec)-> release. So, I think that deploy account or Rails is problem. However, I dont have any idea to fix this.

1
  • which web server are you using? puma, unicorn? passenger?
    – Ryan Lyu
    Commented Dec 26, 2018 at 7:58

2 Answers 2

1

What does sleep mean?

MySQL process has completed the execution of query, but the client(Rails) doesn't exit.

Why does it happen?

Either puma or unicorn, they are using persistent connections to database, then it's normal to have lots of idle connection, the state of which is sleep.

Should I worry about it?

If those sleep connections come from Rails web application and less than the configuration of database connection pool size, there is nothing to worry.

How to fix it?

set global wait_timeout=XXX; // wait_timeout is for non-interactive sessions.
set global interactive_timeout=XXX;  // interactive_time is for interactive sessions

Reference

  1. Should I worry about mysql sleep status process in processlist?

  2. Mysql show processlist lists many processes sleep and info = null?

0

to check your idle process timeout you can connect to MySQL then execute the following command:

show variables like "%timeout%";

you need to check wait_timeout and interactive_timeout from the results based on those values you can execute the following commands from MySQL to set them:

set global wait_timeout=XXX; -- where XXX equal value less than the original one
set global interactive_timeout=XXX;  -- where XXX equal value less than the original one
2
  • Those settings will take effect only as new connections occur; existing connections will run until the old timeout. (Or you could kill them.)
    – Rick James
    Commented Dec 4, 2015 at 5:34
  • These settings are good as long as application is written in such a way if there is threadpooling, these timeouts might cause errors and they should have logic to respawn the threads upon demand.
    – Mannoj
    Commented Jun 2, 2017 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.