Does Mysql (MariaDB) wait_timeout exclude query execution time?
up vote
2
down vote
favorite
I'm tuning my project MYSQL database, as many people I got suggestion to reduce
wait_timeout
, but it is unclear for me, does this session variable exclude query execution time, or it includes it? I have set it for 5 seconds, taking into account that I may have queries which are being executed for 3-5 seconds sometimes (yea that is slow there are few of them, but they still exist), so mysql connections have at least 1-2 seconds to be taken by PHP scripts before they are closed by MYSQL.
In MySQL docs there is no clear explanation about how it starts counting that timeout and if it includes execution time. Perhaps your experience may help. Thanks.
php mysql
add a comment |
up vote
2
down vote
favorite
I'm tuning my project MYSQL database, as many people I got suggestion to reduce
wait_timeout
, but it is unclear for me, does this session variable exclude query execution time, or it includes it? I have set it for 5 seconds, taking into account that I may have queries which are being executed for 3-5 seconds sometimes (yea that is slow there are few of them, but they still exist), so mysql connections have at least 1-2 seconds to be taken by PHP scripts before they are closed by MYSQL.
In MySQL docs there is no clear explanation about how it starts counting that timeout and if it includes execution time. Perhaps your experience may help. Thanks.
php mysql
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm tuning my project MYSQL database, as many people I got suggestion to reduce
wait_timeout
, but it is unclear for me, does this session variable exclude query execution time, or it includes it? I have set it for 5 seconds, taking into account that I may have queries which are being executed for 3-5 seconds sometimes (yea that is slow there are few of them, but they still exist), so mysql connections have at least 1-2 seconds to be taken by PHP scripts before they are closed by MYSQL.
In MySQL docs there is no clear explanation about how it starts counting that timeout and if it includes execution time. Perhaps your experience may help. Thanks.
php mysql
I'm tuning my project MYSQL database, as many people I got suggestion to reduce
wait_timeout
, but it is unclear for me, does this session variable exclude query execution time, or it includes it? I have set it for 5 seconds, taking into account that I may have queries which are being executed for 3-5 seconds sometimes (yea that is slow there are few of them, but they still exist), so mysql connections have at least 1-2 seconds to be taken by PHP scripts before they are closed by MYSQL.
In MySQL docs there is no clear explanation about how it starts counting that timeout and if it includes execution time. Perhaps your experience may help. Thanks.
php mysql
php mysql
edited Nov 24 at 18:56
O. Jones
59.1k971106
59.1k971106
asked Nov 20 at 12:54
NIck
3711
3711
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
Does the
wait_timeout
session variable exclude query execution time?
Yes, it excludes query time.
max_execution_time
controls how long the server will keep a long-running query alive before stopping it.
Do you use php connection pools? If so 5 seconds is an extremely short wait_time
. Make it longer. 60 seconds might be good. Why? the whole point of connection pools is to hold some idle connections open from php to MySQL, so php can handle requests from users without the overhead of opening connections.
Here's how it works.
- php sits there listening for incoming requests.
- A request arrives, and the php script starts running.
- The php script asks for a database connection.
- php (the mysqli or PDO module) looks to see whether it has an idle connection waiting in the connection pool. If so it passes the connection to the php script to use.
- If there's no idle connection php creates one and passes it to the php script to use. This connection creation starts the
wait_timeout
countdown. - The php script uses the connection for a query. This stops the
wait_timeout
countdown, and starts themax_execution_time
countdown. - The query completes. This stops the
max_execution_time
countdown and restarts thewait_timeout
countdown. Repeat 6 and 7 as often as needed. - The php script releases the connection, and php inserts it into the connection pool. Go back to step 1. The
wait_time
is now counting down for that connection while it is in the pool. - If the connection's
wait_time
expires, php removes it from the connection pool.
If step 9 happens a lot, then step 5 also must happen a lot and php will respond more slowly to requests. You can make step 9 happen less often by increasing wait_timeout
.
(Note: this is simplified: there's also provision for a maximum number of connections in the connection pool.)
MySQL also has an interactive_timeout
variable. It's like wait_timeout
but used for interactive sessions via the mysql
command line program.
What happens when a web user makes a request and then abandons it before completion? For example, a user might stop waiting for a report and go to another page. In some cases, the host language processor detects the closing of the user connection, kills the MySQL query, and returns the connection to the pool. In other cases the query either completes or hits the max_execution_timeout
barrier. Then the connection is returned to the pool. In all cases the wait_timeout
countdown only is active when a connection is open but has no query active on it.
Yes, and FWIW an "interactive session" is currently only a session run by themysql
CLI. That's the only code that sets the interactive option.
– Bill Karwin
Nov 24 at 19:10
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
See my edit. Coping with an abandoned query relates tomax_execution_time
, notwait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)
– O. Jones
Nov 25 at 20:03
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?
– NIck
Nov 26 at 7:19
add a comment |
up vote
0
down vote
A MySQL server timeout can occur for many reasons, but happens most often when a command is sent to MySQL over a closed connection. The connection could have been closed by the MySQL server because of an idle-timeout; however, in most cases it is caused by either an application bug, a network timeout issue (on a firewall, router, etc.), or due to the MySQL server restarting.
It is clear from the documentation that it does not include the query execution time. It is basically the maximum idle-time allowed between two activities. If it crosses that limit, server closes the connection automatically.
The number of seconds the server waits for activity on a
noninteractive connection before closing it.
From https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql :
- Configure the wait_timeout to be slightly longer than the application connection pool's expected connection lifetime. This is a good safety check.
- Consider changing the waittimeout value online. This does not require a MySQL restart, and the waittimeout can be adjusted in the running server without incurring downtime. You would issue set global waittimeout=60 and any new sessions created would inherit this value. Be sure to preserve the setting in my.cnf. Any existing connections will need to hit the old value of waittimeout if the application abandoned the connection. If you do have reporting jobs that will do longer local processing while in a transaction, you might consider having such jobs issue set session wait_timeout=3600 upon connecting.
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
add a comment |
up vote
0
down vote
From the reference manual,
Time in seconds that the server waits for a connection to become active before closing it.
In elementary terms, How many SECONDS will you tolerate someone reserving your resources and doing nothing? It is likely your 'think time' before you decide which action to take is frequently more than 5 seconds. Be liberal. For a web application, some processes take more than 5 seconds to run a query and you are causing them to be terminated at 5 seconds. The default is 28800 seconds which is not reasonable. 60 seconds could be a reasonable time to expect any web based process to be completed. If your application is also used in a traditional workplace environment, a 15 minute break is not unreasonable. be liberal to avoid 'bad feedback'.
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393451%2fdoes-mysql-mariadb-wait-timeout-exclude-query-execution-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Does the
wait_timeout
session variable exclude query execution time?
Yes, it excludes query time.
max_execution_time
controls how long the server will keep a long-running query alive before stopping it.
Do you use php connection pools? If so 5 seconds is an extremely short wait_time
. Make it longer. 60 seconds might be good. Why? the whole point of connection pools is to hold some idle connections open from php to MySQL, so php can handle requests from users without the overhead of opening connections.
Here's how it works.
- php sits there listening for incoming requests.
- A request arrives, and the php script starts running.
- The php script asks for a database connection.
- php (the mysqli or PDO module) looks to see whether it has an idle connection waiting in the connection pool. If so it passes the connection to the php script to use.
- If there's no idle connection php creates one and passes it to the php script to use. This connection creation starts the
wait_timeout
countdown. - The php script uses the connection for a query. This stops the
wait_timeout
countdown, and starts themax_execution_time
countdown. - The query completes. This stops the
max_execution_time
countdown and restarts thewait_timeout
countdown. Repeat 6 and 7 as often as needed. - The php script releases the connection, and php inserts it into the connection pool. Go back to step 1. The
wait_time
is now counting down for that connection while it is in the pool. - If the connection's
wait_time
expires, php removes it from the connection pool.
If step 9 happens a lot, then step 5 also must happen a lot and php will respond more slowly to requests. You can make step 9 happen less often by increasing wait_timeout
.
(Note: this is simplified: there's also provision for a maximum number of connections in the connection pool.)
MySQL also has an interactive_timeout
variable. It's like wait_timeout
but used for interactive sessions via the mysql
command line program.
What happens when a web user makes a request and then abandons it before completion? For example, a user might stop waiting for a report and go to another page. In some cases, the host language processor detects the closing of the user connection, kills the MySQL query, and returns the connection to the pool. In other cases the query either completes or hits the max_execution_timeout
barrier. Then the connection is returned to the pool. In all cases the wait_timeout
countdown only is active when a connection is open but has no query active on it.
Yes, and FWIW an "interactive session" is currently only a session run by themysql
CLI. That's the only code that sets the interactive option.
– Bill Karwin
Nov 24 at 19:10
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
See my edit. Coping with an abandoned query relates tomax_execution_time
, notwait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)
– O. Jones
Nov 25 at 20:03
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?
– NIck
Nov 26 at 7:19
add a comment |
up vote
1
down vote
Does the
wait_timeout
session variable exclude query execution time?
Yes, it excludes query time.
max_execution_time
controls how long the server will keep a long-running query alive before stopping it.
Do you use php connection pools? If so 5 seconds is an extremely short wait_time
. Make it longer. 60 seconds might be good. Why? the whole point of connection pools is to hold some idle connections open from php to MySQL, so php can handle requests from users without the overhead of opening connections.
Here's how it works.
- php sits there listening for incoming requests.
- A request arrives, and the php script starts running.
- The php script asks for a database connection.
- php (the mysqli or PDO module) looks to see whether it has an idle connection waiting in the connection pool. If so it passes the connection to the php script to use.
- If there's no idle connection php creates one and passes it to the php script to use. This connection creation starts the
wait_timeout
countdown. - The php script uses the connection for a query. This stops the
wait_timeout
countdown, and starts themax_execution_time
countdown. - The query completes. This stops the
max_execution_time
countdown and restarts thewait_timeout
countdown. Repeat 6 and 7 as often as needed. - The php script releases the connection, and php inserts it into the connection pool. Go back to step 1. The
wait_time
is now counting down for that connection while it is in the pool. - If the connection's
wait_time
expires, php removes it from the connection pool.
If step 9 happens a lot, then step 5 also must happen a lot and php will respond more slowly to requests. You can make step 9 happen less often by increasing wait_timeout
.
(Note: this is simplified: there's also provision for a maximum number of connections in the connection pool.)
MySQL also has an interactive_timeout
variable. It's like wait_timeout
but used for interactive sessions via the mysql
command line program.
What happens when a web user makes a request and then abandons it before completion? For example, a user might stop waiting for a report and go to another page. In some cases, the host language processor detects the closing of the user connection, kills the MySQL query, and returns the connection to the pool. In other cases the query either completes or hits the max_execution_timeout
barrier. Then the connection is returned to the pool. In all cases the wait_timeout
countdown only is active when a connection is open but has no query active on it.
Yes, and FWIW an "interactive session" is currently only a session run by themysql
CLI. That's the only code that sets the interactive option.
– Bill Karwin
Nov 24 at 19:10
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
See my edit. Coping with an abandoned query relates tomax_execution_time
, notwait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)
– O. Jones
Nov 25 at 20:03
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?
– NIck
Nov 26 at 7:19
add a comment |
up vote
1
down vote
up vote
1
down vote
Does the
wait_timeout
session variable exclude query execution time?
Yes, it excludes query time.
max_execution_time
controls how long the server will keep a long-running query alive before stopping it.
Do you use php connection pools? If so 5 seconds is an extremely short wait_time
. Make it longer. 60 seconds might be good. Why? the whole point of connection pools is to hold some idle connections open from php to MySQL, so php can handle requests from users without the overhead of opening connections.
Here's how it works.
- php sits there listening for incoming requests.
- A request arrives, and the php script starts running.
- The php script asks for a database connection.
- php (the mysqli or PDO module) looks to see whether it has an idle connection waiting in the connection pool. If so it passes the connection to the php script to use.
- If there's no idle connection php creates one and passes it to the php script to use. This connection creation starts the
wait_timeout
countdown. - The php script uses the connection for a query. This stops the
wait_timeout
countdown, and starts themax_execution_time
countdown. - The query completes. This stops the
max_execution_time
countdown and restarts thewait_timeout
countdown. Repeat 6 and 7 as often as needed. - The php script releases the connection, and php inserts it into the connection pool. Go back to step 1. The
wait_time
is now counting down for that connection while it is in the pool. - If the connection's
wait_time
expires, php removes it from the connection pool.
If step 9 happens a lot, then step 5 also must happen a lot and php will respond more slowly to requests. You can make step 9 happen less often by increasing wait_timeout
.
(Note: this is simplified: there's also provision for a maximum number of connections in the connection pool.)
MySQL also has an interactive_timeout
variable. It's like wait_timeout
but used for interactive sessions via the mysql
command line program.
What happens when a web user makes a request and then abandons it before completion? For example, a user might stop waiting for a report and go to another page. In some cases, the host language processor detects the closing of the user connection, kills the MySQL query, and returns the connection to the pool. In other cases the query either completes or hits the max_execution_timeout
barrier. Then the connection is returned to the pool. In all cases the wait_timeout
countdown only is active when a connection is open but has no query active on it.
Does the
wait_timeout
session variable exclude query execution time?
Yes, it excludes query time.
max_execution_time
controls how long the server will keep a long-running query alive before stopping it.
Do you use php connection pools? If so 5 seconds is an extremely short wait_time
. Make it longer. 60 seconds might be good. Why? the whole point of connection pools is to hold some idle connections open from php to MySQL, so php can handle requests from users without the overhead of opening connections.
Here's how it works.
- php sits there listening for incoming requests.
- A request arrives, and the php script starts running.
- The php script asks for a database connection.
- php (the mysqli or PDO module) looks to see whether it has an idle connection waiting in the connection pool. If so it passes the connection to the php script to use.
- If there's no idle connection php creates one and passes it to the php script to use. This connection creation starts the
wait_timeout
countdown. - The php script uses the connection for a query. This stops the
wait_timeout
countdown, and starts themax_execution_time
countdown. - The query completes. This stops the
max_execution_time
countdown and restarts thewait_timeout
countdown. Repeat 6 and 7 as often as needed. - The php script releases the connection, and php inserts it into the connection pool. Go back to step 1. The
wait_time
is now counting down for that connection while it is in the pool. - If the connection's
wait_time
expires, php removes it from the connection pool.
If step 9 happens a lot, then step 5 also must happen a lot and php will respond more slowly to requests. You can make step 9 happen less often by increasing wait_timeout
.
(Note: this is simplified: there's also provision for a maximum number of connections in the connection pool.)
MySQL also has an interactive_timeout
variable. It's like wait_timeout
but used for interactive sessions via the mysql
command line program.
What happens when a web user makes a request and then abandons it before completion? For example, a user might stop waiting for a report and go to another page. In some cases, the host language processor detects the closing of the user connection, kills the MySQL query, and returns the connection to the pool. In other cases the query either completes or hits the max_execution_timeout
barrier. Then the connection is returned to the pool. In all cases the wait_timeout
countdown only is active when a connection is open but has no query active on it.
edited Nov 25 at 20:00
answered Nov 24 at 19:06
O. Jones
59.1k971106
59.1k971106
Yes, and FWIW an "interactive session" is currently only a session run by themysql
CLI. That's the only code that sets the interactive option.
– Bill Karwin
Nov 24 at 19:10
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
See my edit. Coping with an abandoned query relates tomax_execution_time
, notwait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)
– O. Jones
Nov 25 at 20:03
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?
– NIck
Nov 26 at 7:19
add a comment |
Yes, and FWIW an "interactive session" is currently only a session run by themysql
CLI. That's the only code that sets the interactive option.
– Bill Karwin
Nov 24 at 19:10
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
See my edit. Coping with an abandoned query relates tomax_execution_time
, notwait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)
– O. Jones
Nov 25 at 20:03
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?
– NIck
Nov 26 at 7:19
Yes, and FWIW an "interactive session" is currently only a session run by the
mysql
CLI. That's the only code that sets the interactive option.– Bill Karwin
Nov 24 at 19:10
Yes, and FWIW an "interactive session" is currently only a session run by the
mysql
CLI. That's the only code that sets the interactive option.– Bill Karwin
Nov 24 at 19:10
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Thanks for detailed answer. Many tuning scripts suggest to reduce wait_timeout and to remove persistent connections. I configured my server to have persistent connections and made wait_timeout to 5 seconds. As it seems to me that should be enough to process long queries and to eliminate creation of new connection. Isn't this right? And yes, I use a pool of connections which is default config in many LAMP systems
– NIck
Nov 25 at 19:09
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
Since you answered very detailed, may I ask you well that question which I asked a person below you answer: Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
See my edit. Coping with an abandoned query relates to
max_execution_time
, not wait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)– O. Jones
Nov 25 at 20:03
See my edit. Coping with an abandoned query relates to
max_execution_time
, not wait_time
. Any, you should know that the re-use of persistent connections is absolutely vital to the performance of high-traffic web sites, intertoobz advice to the contrary notwithstanding. Creating new dbms connections is expensive, and it's expensive for a shared resource (dbms server) rather that one that can be scaled out (web server)– O. Jones
Nov 25 at 20:03
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.
max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?– NIck
Nov 26 at 7:19
Thank you, I have set it to 60 seconds, 'Threads_connected' did not change much since that moment, so it seems ok.
max_execution_time
is php parameter, in my case it is default 30 seconds, it still seems to me that 30 seconds of possible connection use could become performance bottleneck or even a reason of system instability, if some robots/parsers come and send many requests to site, it will use all connections very quick and server can't respond to normal requests. When they are limited to 5 seconds there is less possibility of such scenario... Am I wrong?– NIck
Nov 26 at 7:19
add a comment |
up vote
0
down vote
A MySQL server timeout can occur for many reasons, but happens most often when a command is sent to MySQL over a closed connection. The connection could have been closed by the MySQL server because of an idle-timeout; however, in most cases it is caused by either an application bug, a network timeout issue (on a firewall, router, etc.), or due to the MySQL server restarting.
It is clear from the documentation that it does not include the query execution time. It is basically the maximum idle-time allowed between two activities. If it crosses that limit, server closes the connection automatically.
The number of seconds the server waits for activity on a
noninteractive connection before closing it.
From https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql :
- Configure the wait_timeout to be slightly longer than the application connection pool's expected connection lifetime. This is a good safety check.
- Consider changing the waittimeout value online. This does not require a MySQL restart, and the waittimeout can be adjusted in the running server without incurring downtime. You would issue set global waittimeout=60 and any new sessions created would inherit this value. Be sure to preserve the setting in my.cnf. Any existing connections will need to hit the old value of waittimeout if the application abandoned the connection. If you do have reporting jobs that will do longer local processing while in a transaction, you might consider having such jobs issue set session wait_timeout=3600 upon connecting.
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
add a comment |
up vote
0
down vote
A MySQL server timeout can occur for many reasons, but happens most often when a command is sent to MySQL over a closed connection. The connection could have been closed by the MySQL server because of an idle-timeout; however, in most cases it is caused by either an application bug, a network timeout issue (on a firewall, router, etc.), or due to the MySQL server restarting.
It is clear from the documentation that it does not include the query execution time. It is basically the maximum idle-time allowed between two activities. If it crosses that limit, server closes the connection automatically.
The number of seconds the server waits for activity on a
noninteractive connection before closing it.
From https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql :
- Configure the wait_timeout to be slightly longer than the application connection pool's expected connection lifetime. This is a good safety check.
- Consider changing the waittimeout value online. This does not require a MySQL restart, and the waittimeout can be adjusted in the running server without incurring downtime. You would issue set global waittimeout=60 and any new sessions created would inherit this value. Be sure to preserve the setting in my.cnf. Any existing connections will need to hit the old value of waittimeout if the application abandoned the connection. If you do have reporting jobs that will do longer local processing while in a transaction, you might consider having such jobs issue set session wait_timeout=3600 upon connecting.
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
add a comment |
up vote
0
down vote
up vote
0
down vote
A MySQL server timeout can occur for many reasons, but happens most often when a command is sent to MySQL over a closed connection. The connection could have been closed by the MySQL server because of an idle-timeout; however, in most cases it is caused by either an application bug, a network timeout issue (on a firewall, router, etc.), or due to the MySQL server restarting.
It is clear from the documentation that it does not include the query execution time. It is basically the maximum idle-time allowed between two activities. If it crosses that limit, server closes the connection automatically.
The number of seconds the server waits for activity on a
noninteractive connection before closing it.
From https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql :
- Configure the wait_timeout to be slightly longer than the application connection pool's expected connection lifetime. This is a good safety check.
- Consider changing the waittimeout value online. This does not require a MySQL restart, and the waittimeout can be adjusted in the running server without incurring downtime. You would issue set global waittimeout=60 and any new sessions created would inherit this value. Be sure to preserve the setting in my.cnf. Any existing connections will need to hit the old value of waittimeout if the application abandoned the connection. If you do have reporting jobs that will do longer local processing while in a transaction, you might consider having such jobs issue set session wait_timeout=3600 upon connecting.
A MySQL server timeout can occur for many reasons, but happens most often when a command is sent to MySQL over a closed connection. The connection could have been closed by the MySQL server because of an idle-timeout; however, in most cases it is caused by either an application bug, a network timeout issue (on a firewall, router, etc.), or due to the MySQL server restarting.
It is clear from the documentation that it does not include the query execution time. It is basically the maximum idle-time allowed between two activities. If it crosses that limit, server closes the connection automatically.
The number of seconds the server waits for activity on a
noninteractive connection before closing it.
From https://www.digitalocean.com/community/questions/how-to-set-no-timeout-to-mysql :
- Configure the wait_timeout to be slightly longer than the application connection pool's expected connection lifetime. This is a good safety check.
- Consider changing the waittimeout value online. This does not require a MySQL restart, and the waittimeout can be adjusted in the running server without incurring downtime. You would issue set global waittimeout=60 and any new sessions created would inherit this value. Be sure to preserve the setting in my.cnf. Any existing connections will need to hit the old value of waittimeout if the application abandoned the connection. If you do have reporting jobs that will do longer local processing while in a transaction, you might consider having such jobs issue set session wait_timeout=3600 upon connecting.
answered Nov 20 at 13:03
Madhur Bhaiya
19.3k62236
19.3k62236
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
add a comment |
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
Thanks for you answer, I have read it, but it was unclear what it counts as activity. That could be many factors, as it is, in my opinion execution time had to be excluded from that variable, or there must another timeout for 'clean kill' of abandon requests
– NIck
Nov 20 at 13:11
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
@NIck you can very easily experiment it. Take for example a php code. Create a database connection. Fire some queries. Use sleep() to let application wait for some time. Keep on increasing this until you hit the wait time out
– Madhur Bhaiya
Nov 20 at 13:21
add a comment |
up vote
0
down vote
From the reference manual,
Time in seconds that the server waits for a connection to become active before closing it.
In elementary terms, How many SECONDS will you tolerate someone reserving your resources and doing nothing? It is likely your 'think time' before you decide which action to take is frequently more than 5 seconds. Be liberal. For a web application, some processes take more than 5 seconds to run a query and you are causing them to be terminated at 5 seconds. The default is 28800 seconds which is not reasonable. 60 seconds could be a reasonable time to expect any web based process to be completed. If your application is also used in a traditional workplace environment, a 15 minute break is not unreasonable. be liberal to avoid 'bad feedback'.
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
add a comment |
up vote
0
down vote
From the reference manual,
Time in seconds that the server waits for a connection to become active before closing it.
In elementary terms, How many SECONDS will you tolerate someone reserving your resources and doing nothing? It is likely your 'think time' before you decide which action to take is frequently more than 5 seconds. Be liberal. For a web application, some processes take more than 5 seconds to run a query and you are causing them to be terminated at 5 seconds. The default is 28800 seconds which is not reasonable. 60 seconds could be a reasonable time to expect any web based process to be completed. If your application is also used in a traditional workplace environment, a 15 minute break is not unreasonable. be liberal to avoid 'bad feedback'.
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
add a comment |
up vote
0
down vote
up vote
0
down vote
From the reference manual,
Time in seconds that the server waits for a connection to become active before closing it.
In elementary terms, How many SECONDS will you tolerate someone reserving your resources and doing nothing? It is likely your 'think time' before you decide which action to take is frequently more than 5 seconds. Be liberal. For a web application, some processes take more than 5 seconds to run a query and you are causing them to be terminated at 5 seconds. The default is 28800 seconds which is not reasonable. 60 seconds could be a reasonable time to expect any web based process to be completed. If your application is also used in a traditional workplace environment, a 15 minute break is not unreasonable. be liberal to avoid 'bad feedback'.
From the reference manual,
Time in seconds that the server waits for a connection to become active before closing it.
In elementary terms, How many SECONDS will you tolerate someone reserving your resources and doing nothing? It is likely your 'think time' before you decide which action to take is frequently more than 5 seconds. Be liberal. For a web application, some processes take more than 5 seconds to run a query and you are causing them to be terminated at 5 seconds. The default is 28800 seconds which is not reasonable. 60 seconds could be a reasonable time to expect any web based process to be completed. If your application is also used in a traditional workplace environment, a 15 minute break is not unreasonable. be liberal to avoid 'bad feedback'.
answered Nov 24 at 18:52
Wilson Hauck
640511
640511
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
add a comment |
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
Doesn't those 60 seconds mean that is some query was made by a request which does not use it (a person left page, request was not finished properly whatever else but it is not used) it will be hanged for 60 seconds taking of precious connections? They are limited as well
– NIck
Nov 25 at 19:16
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
@nick Yes, 60 seconds means I will keep your connection for 60 seconds. SHOW GLOBAL STATUS LIKE 'threads_connected'; allows you to monitor the count of active connections and they are limited.
– Wilson Hauck
Nov 25 at 20:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393451%2fdoes-mysql-mariadb-wait-timeout-exclude-query-execution-time%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown