{"action":"created","issue":{"url":"https://api.github.com/repos/coleifer/peewee/issues/608","labels_url":"https://api.github.com/repos/coleifer/peewee/issues/608/labels{/name}","comments_url":"https://api.github.com/repos/coleifer/peewee/issues/608/comments","events_url":"https://api.github.com/repos/coleifer/peewee/issues/608/events","html_url":"https://github.com/coleifer/peewee/issues/608","id":78940712,"number":608,"title":"Some issues with connection pooling","user":{"login":"arnuschky","id":179920,"avatar_url":"https://avatars.githubusercontent.com/u/179920?v=3","gravatar_id":"","url":"https://api.github.com/users/arnuschky","html_url":"https://github.com/arnuschky","followers_url":"https://api.github.com/users/arnuschky/followers","following_url":"https://api.github.com/users/arnuschky/following{/other_user}","gists_url":"https://api.github.com/users/arnuschky/gists{/gist_id}","starred_url":"https://api.github.com/users/arnuschky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arnuschky/subscriptions","organizations_url":"https://api.github.com/users/arnuschky/orgs","repos_url":"https://api.github.com/users/arnuschky/repos","events_url":"https://api.github.com/users/arnuschky/events{/privacy}","received_events_url":"https://api.github.com/users/arnuschky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-21T10:50:33Z","updated_at":"2015-05-21T14:01:39Z","closed_at":null,"body":"Using latest peewee with a pooled mysql db (I know, sorry... ;) ) It's a single-thread multi-greenlet application.\r\n\r\nWhat we see is that the size of the connections `inuse` monotonically increases, until it hits `max_connections`. Still debugging that right now...\r\n\r\n`stale_timeout` is somewhat of a misnomer, right? If I read the code correctly, it's more of a maximum age after which a connection is closed no matter its usage, right?\r\n\r\nA curious observation is that the pool seems to use multiple connections to the database but the database reports only a single connection."},"comment":{"url":"https://api.github.com/repos/coleifer/peewee/issues/comments/104286302","html_url":"https://github.com/coleifer/peewee/issues/608#issuecomment-104286302","issue_url":"https://api.github.com/repos/coleifer/peewee/issues/608","id":104286302,"user":{"login":"coleifer","id":119974,"avatar_url":"https://avatars.githubusercontent.com/u/119974?v=3","gravatar_id":"","url":"https://api.github.com/users/coleifer","html_url":"https://github.com/coleifer","followers_url":"https://api.github.com/users/coleifer/followers","following_url":"https://api.github.com/users/coleifer/following{/other_user}","gists_url":"https://api.github.com/users/coleifer/gists{/gist_id}","starred_url":"https://api.github.com/users/coleifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coleifer/subscriptions","organizations_url":"https://api.github.com/users/coleifer/orgs","repos_url":"https://api.github.com/users/coleifer/repos","events_url":"https://api.github.com/users/coleifer/events{/privacy}","received_events_url":"https://api.github.com/users/coleifer/received_events","type":"User","site_admin":false},"created_at":"2015-05-21T14:01:39Z","updated_at":"2015-05-21T14:01:39Z","body":"Ahh, actually I think this is the problem. In your code, the peewee module's instance of the `threading` module may not be patched at the time it is imported. This means that peewee's `Database` classes will use a `threading.local` instead of a *greenlet local*.\r\n\r\nTo fix this, in your WSGI script or the entry point of your application, at the very top of the module, first import, try adding:\r\n\r\n```python\r\nfrom gevent import monkey; monkey.patch_all()\r\n```\r\n\r\nLet me know if that fixes the issue."}}