Django not reusing connections to MySQL with CONN_MAX_AGE=60












3















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










share|improve this question























  • 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
















3















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










share|improve this question























  • 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














3












3








3








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 17:04









        soxsox

        137214




        137214
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?