{"action":"created","issue":{"url":"https://api.github.com/repos/upper/db/issues/287","repository_url":"https://api.github.com/repos/upper/db","labels_url":"https://api.github.com/repos/upper/db/issues/287/labels{/name}","comments_url":"https://api.github.com/repos/upper/db/issues/287/comments","events_url":"https://api.github.com/repos/upper/db/issues/287/events","html_url":"https://github.com/upper/db/issues/287","id":190462331,"number":287,"title":"Prepared statements cache may grow up too much under certain situations","user":{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false},"labels":[{"id":62206254,"url":"https://api.github.com/repos/upper/db/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false},"assignees":[{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false}],"milestone":null,"comments":14,"created_at":"2016-11-19T01:34:19Z","updated_at":"2016-12-05T12:50:13Z","closed_at":null,"body":"There seems to be something odd with prepared statements + MySQL which could mean we have another prepared statement leak.\r\n\r\nThis is a followup of: https://github.com/upper/db/issues/270#issuecomment-261646680\r\n\r\nIt would be ideal to find a query that gives the actual number of prepared statements on different databases, and add that query to our testing."},"comment":{"url":"https://api.github.com/repos/upper/db/issues/comments/264846158","html_url":"https://github.com/upper/db/issues/287#issuecomment-264846158","issue_url":"https://api.github.com/repos/upper/db/issues/287","id":264846158,"user":{"login":"xiam","id":385670,"avatar_url":"https://avatars.githubusercontent.com/u/385670?v=3","gravatar_id":"","url":"https://api.github.com/users/xiam","html_url":"https://github.com/xiam","followers_url":"https://api.github.com/users/xiam/followers","following_url":"https://api.github.com/users/xiam/following{/other_user}","gists_url":"https://api.github.com/users/xiam/gists{/gist_id}","starred_url":"https://api.github.com/users/xiam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiam/subscriptions","organizations_url":"https://api.github.com/users/xiam/orgs","repos_url":"https://api.github.com/users/xiam/repos","events_url":"https://api.github.com/users/xiam/events{/privacy}","received_events_url":"https://api.github.com/users/xiam/received_events","type":"User","site_admin":false},"created_at":"2016-12-05T12:50:13Z","updated_at":"2016-12-05T12:50:13Z","body":"Hello @crunchytom,\r\n\r\nYour assumption was correct, the number of connections trying to prepare statements affected the prepared statement count.\r\n\r\nWe can't control the connection pool, if Go reserves a large pool and we bash it with concurrent queries (which are prepared per-connection) we can end up preparing a lot of statements before they get evicted. This can also happen without upper-db, but it's more difficult to see it on the wild. The solution for this was not allowing PREPARE to run concurrently (which is something `database/sql` also does, see https://golang.org/src/database/sql/sql.go?s=25372:25422#L950, but we didn't). This also reduces the number of required connections when doing concurrent queries.\r\n\r\nWe're about to review and merge an update (branch `issue-287`) that will hopefully solve your problem, but it will also disable the prepared statements cache by default, if you'd like to enable it you can do it like this:\r\n\r\n```go\r\ndb.Conf.SetPreparedStatementCache(true)\r\n```\r\n\r\nAt any point during your program's life. \r\n\r\nWe also added a test that spawns 20000 concurrent selects to our regular test suite, that test was failing on the upper-db version you were using but it's fixed on `issue-287`.\r\n\r\nThanks a lot for helping us debugging this! I'll keep it open until we push a new release."}}
{"actor":{"display_login":"xiam"}}