Django not reusing connections to MySQL with CONN_MAX_AGE=60
I am using Django 1.9.2 in development (DEBUG=True
) with MySQL 5.6.23. Below is my database settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': "django",
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
'CONN_MAX_AGE': 60,
}
}
I am querying MySQL to get the number of active connections with the command below:
show status where `variable_name` = 'Threads_connected';
It yield result like this
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 10 |
+-------------------+-------+
1 row in set (0,00 sec)
Every time I make a new request to Django, the number of connected threads increase until I get (1040, 'Too many connections')
when the number Threads_connected=151
. Furthermore, connections are not closed after 60s.
This behavior does not seem to happen in production (DEBUG=False
).
python mysql django
add a comment |
I am using Django 1.9.2 in development (DEBUG=True
) with MySQL 5.6.23. Below is my database settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': "django",
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
'CONN_MAX_AGE': 60,
}
}
I am querying MySQL to get the number of active connections with the command below:
show status where `variable_name` = 'Threads_connected';
It yield result like this
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 10 |
+-------------------+-------+
1 row in set (0,00 sec)
Every time I make a new request to Django, the number of connected threads increase until I get (1040, 'Too many connections')
when the number Threads_connected=151
. Furthermore, connections are not closed after 60s.
This behavior does not seem to happen in production (DEBUG=False
).
python mysql django
Is this solved ? I also hit the problem
– Wesley
Jun 3 '16 at 13:45
how you lanunched Django? And Django process request in per-thread-per-request model or per-greenlet-per-request model?
– Jcyrss
Jun 4 '16 at 1:54
add a comment |
I am using Django 1.9.2 in development (DEBUG=True
) with MySQL 5.6.23. Below is my database settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': "django",
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
'CONN_MAX_AGE': 60,
}
}
I am querying MySQL to get the number of active connections with the command below:
show status where `variable_name` = 'Threads_connected';
It yield result like this
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 10 |
+-------------------+-------+
1 row in set (0,00 sec)
Every time I make a new request to Django, the number of connected threads increase until I get (1040, 'Too many connections')
when the number Threads_connected=151
. Furthermore, connections are not closed after 60s.
This behavior does not seem to happen in production (DEBUG=False
).
python mysql django
I am using Django 1.9.2 in development (DEBUG=True
) with MySQL 5.6.23. Below is my database settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': "django",
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
'CONN_MAX_AGE': 60,
}
}
I am querying MySQL to get the number of active connections with the command below:
show status where `variable_name` = 'Threads_connected';
It yield result like this
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 10 |
+-------------------+-------+
1 row in set (0,00 sec)
Every time I make a new request to Django, the number of connected threads increase until I get (1040, 'Too many connections')
when the number Threads_connected=151
. Furthermore, connections are not closed after 60s.
This behavior does not seem to happen in production (DEBUG=False
).
python mysql django
python mysql django
asked Apr 25 '16 at 9:53
Benoit GuigalBenoit Guigal
3581417
3581417
Is this solved ? I also hit the problem
– Wesley
Jun 3 '16 at 13:45
how you lanunched Django? And Django process request in per-thread-per-request model or per-greenlet-per-request model?
– Jcyrss
Jun 4 '16 at 1:54
add a comment |
Is this solved ? I also hit the problem
– Wesley
Jun 3 '16 at 13:45
how you lanunched Django? And Django process request in per-thread-per-request model or per-greenlet-per-request model?
– Jcyrss
Jun 4 '16 at 1:54
Is this solved ? I also hit the problem
– Wesley
Jun 3 '16 at 13:45
Is this solved ? I also hit the problem
– Wesley
Jun 3 '16 at 13:45
how you lanunched Django? And Django process request in per-thread-per-request model or per-greenlet-per-request model?
– Jcyrss
Jun 4 '16 at 1:54
how you lanunched Django? And Django process request in per-thread-per-request model or per-greenlet-per-request model?
– Jcyrss
Jun 4 '16 at 1:54
add a comment |
1 Answer
1
active
oldest
votes
You are running Django in development mode, so the CONN_MAX_AGE
is not effective because each request is served by a different thread.
From the docs:
The development server creates a new thread for each request it handles, negating the effect of persistent connections. Don’t enable them during development
About the connection not being closed after 60 seconds: timed out connections are closed on the next request, so just make a new request to django after more than 60 seconds, it should detect the obsolete connection and close it.
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',
autoActivateHeartbeat: false,
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%2f36837216%2fdjango-not-reusing-connections-to-mysql-with-conn-max-age-60%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are running Django in development mode, so the CONN_MAX_AGE
is not effective because each request is served by a different thread.
From the docs:
The development server creates a new thread for each request it handles, negating the effect of persistent connections. Don’t enable them during development
About the connection not being closed after 60 seconds: timed out connections are closed on the next request, so just make a new request to django after more than 60 seconds, it should detect the obsolete connection and close it.
add a comment |
You are running Django in development mode, so the CONN_MAX_AGE
is not effective because each request is served by a different thread.
From the docs:
The development server creates a new thread for each request it handles, negating the effect of persistent connections. Don’t enable them during development
About the connection not being closed after 60 seconds: timed out connections are closed on the next request, so just make a new request to django after more than 60 seconds, it should detect the obsolete connection and close it.
add a comment |
You are running Django in development mode, so the CONN_MAX_AGE
is not effective because each request is served by a different thread.
From the docs:
The development server creates a new thread for each request it handles, negating the effect of persistent connections. Don’t enable them during development
About the connection not being closed after 60 seconds: timed out connections are closed on the next request, so just make a new request to django after more than 60 seconds, it should detect the obsolete connection and close it.
You are running Django in development mode, so the CONN_MAX_AGE
is not effective because each request is served by a different thread.
From the docs:
The development server creates a new thread for each request it handles, negating the effect of persistent connections. Don’t enable them during development
About the connection not being closed after 60 seconds: timed out connections are closed on the next request, so just make a new request to django after more than 60 seconds, it should detect the obsolete connection and close it.
answered Nov 21 '18 at 17:04
soxsox
137214
137214
add a comment |
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.
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%2f36837216%2fdjango-not-reusing-connections-to-mysql-with-conn-max-age-60%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
Is this solved ? I also hit the problem
– Wesley
Jun 3 '16 at 13:45
how you lanunched Django? And Django process request in per-thread-per-request model or per-greenlet-per-request model?
– Jcyrss
Jun 4 '16 at 1:54