{"action":"created","issue":{"url":"https://api.github.com/repos/christkv/mongodb-core/issues/69","labels_url":"https://api.github.com/repos/christkv/mongodb-core/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/christkv/mongodb-core/issues/69/comments","events_url":"https://api.github.com/repos/christkv/mongodb-core/issues/69/events","html_url":"https://github.com/christkv/mongodb-core/issues/69","id":123898599,"number":69,"title":"Improving pool performance for query interleaving better than round robin","user":{"login":"owenallenaz","id":1087603,"avatar_url":"https://avatars.githubusercontent.com/u/1087603?v=3","gravatar_id":"","url":"https://api.github.com/users/owenallenaz","html_url":"https://github.com/owenallenaz","followers_url":"https://api.github.com/users/owenallenaz/followers","following_url":"https://api.github.com/users/owenallenaz/following{/other_user}","gists_url":"https://api.github.com/users/owenallenaz/gists{/gist_id}","starred_url":"https://api.github.com/users/owenallenaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owenallenaz/subscriptions","organizations_url":"https://api.github.com/users/owenallenaz/orgs","repos_url":"https://api.github.com/users/owenallenaz/repos","events_url":"https://api.github.com/users/owenallenaz/events{/privacy}","received_events_url":"https://api.github.com/users/owenallenaz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-25T21:44:10Z","updated_at":"2016-01-03T20:24:00Z","closed_at":null,"body":"One thing we've noticed in our application is that long queries will cause back-up in pool members, even when there are other pools members available to service the request. From looking into the code, I can see that the pool is a round-robin approach. When a new command is issued it is put into a the next socket, even if that socket is busy at the moment, and there are other sockets which may not be busy.\r\n\r\nI believe we could really improve throughput and multi-query interleaving if we did one of the two following things:\r\n\r\n1. Keep track of the number of queries that each pool member has queued up, and assign the next query to the pool member with the lowest number of in-progress queries. I believe this could be done fairly easily without having to refactor too much code. The downside of this approach is that it's still not as optimal as a queue-worker system because a query could still get backed up behind a slow one, and a socket could come available before it's been serviced, leaving pool members not-working and queries still to be ran.\r\n\r\n2. Switch to a queue-worker system for the pool members. Basically, each command gets put into a queue, if there is a pool member available, it will service the request. When a pool member finishes a command, it grabs the next command off the queue and services it. The advantage of this approach is that it should ensure that all pool members are working at all times. New faster queries will still make it through. Slower queries won't stall faster queries unless you have more slow queries that total pool members. This approach could require a fair bit of refactoring to make it possible.\r\n\r\nI have some time over the Christmas break to play around with it. I just don't want to start on a pull request unless it's something you would consider at some point."},"comment":{"url":"https://api.github.com/repos/christkv/mongodb-core/issues/comments/168538433","html_url":"https://github.com/christkv/mongodb-core/issues/69#issuecomment-168538433","issue_url":"https://api.github.com/repos/christkv/mongodb-core/issues/69","id":168538433,"user":{"login":"owenallenaz","id":1087603,"avatar_url":"https://avatars.githubusercontent.com/u/1087603?v=3","gravatar_id":"","url":"https://api.github.com/users/owenallenaz","html_url":"https://github.com/owenallenaz","followers_url":"https://api.github.com/users/owenallenaz/followers","following_url":"https://api.github.com/users/owenallenaz/following{/other_user}","gists_url":"https://api.github.com/users/owenallenaz/gists{/gist_id}","starred_url":"https://api.github.com/users/owenallenaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owenallenaz/subscriptions","organizations_url":"https://api.github.com/users/owenallenaz/orgs","repos_url":"https://api.github.com/users/owenallenaz/repos","events_url":"https://api.github.com/users/owenallenaz/events{/privacy}","received_events_url":"https://api.github.com/users/owenallenaz/received_events","type":"User","site_admin":false},"created_at":"2016-01-03T20:24:00Z","updated_at":"2016-01-03T20:24:00Z","body":"I've created a pull request at #71 . Let me know your thoughts here or in the pull."}}