{"action":"opened","number":10,"pull_request":{"url":"https://api.github.com/repos/lyft/gostats/pulls/10","id":116425929,"html_url":"https://github.com/lyft/gostats/pull/10","diff_url":"https://github.com/lyft/gostats/pull/10.diff","patch_url":"https://github.com/lyft/gostats/pull/10.patch","issue_url":"https://api.github.com/repos/lyft/gostats/issues/10","number":10,"state":"open","locked":false,"title":"Finer-grained mutex locking on Store","user":{"login":"rodaine","id":1268580,"avatar_url":"https://avatars0.githubusercontent.com/u/1268580?v=3","gravatar_id":"","url":"https://api.github.com/users/rodaine","html_url":"https://github.com/rodaine","followers_url":"https://api.github.com/users/rodaine/followers","following_url":"https://api.github.com/users/rodaine/following{/other_user}","gists_url":"https://api.github.com/users/rodaine/gists{/gist_id}","starred_url":"https://api.github.com/users/rodaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rodaine/subscriptions","organizations_url":"https://api.github.com/users/rodaine/orgs","repos_url":"https://api.github.com/users/rodaine/repos","events_url":"https://api.github.com/users/rodaine/events{/privacy}","received_events_url":"https://api.github.com/users/rodaine/received_events","type":"User","site_admin":false},"body":"The `Store` implementation was using a single `sync.Mutex` to control access to the individual metrics and generators. While this simplifies bookkeeping, it can run into problems with contention\r\nin high-throughput circumstances. This mutex locked the `Flush` method, `StatGenerator` slice, and `Timer`/`Counter`/`Gauge` maps.\r\n\r\nOne method of improving this is to use a `sync.RWMutex` instead, which permits multiple simultaneous reads, as is often the case a metric is simply being read (with the `New*` methods) or looped over (with `Flush`). Now `Lock` only needs to be called when adding new metrics to the slice/maps, using `RLock` everywhere else.\r\n\r\nThis still means though that the lock is shared across each of the different metric types despite them living in separate maps. By splitting up this mutex into multiple, we can now have per-metric type locks, further reducing contention. This does make the bookkeeping slightly more painful, though, but significantly improves throughput, as can be seen in the following benchmarks.\r\n\r\nWith the single `sync.Mutex`:\r\n```\r\n→ go test -bench=. -benchtime=5s\r\nBenchmarkStore_MutexContention-8   \t30000000\t       260 ns/op\r\n```\r\nWith per metric-type `sync.RWMutex`:\r\n```\r\n→ go test -bench=. -benchtime=5s\r\nBenchmarkStore_MutexContention-8   \t50000000\t       183 ns/op\r\n```\r\nThat's about a 40% improvement. ","created_at":"2017-04-18T21:35:12Z","updated_at":"2017-04-18T21:35:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/lyft/gostats/pulls/10/commits","review_comments_url":"https://api.github.com/repos/lyft/gostats/pulls/10/comments","review_comment_url":"https://api.github.com/repos/lyft/gostats/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lyft/gostats/issues/10/comments","statuses_url":"https://api.github.com/repos/lyft/gostats/statuses/02a9d322ef9b23c8eeec25e6ab0ef487791dbc59","head":{"label":"lyft:mutex-contention","ref":"mutex-contention","sha":"02a9d322ef9b23c8eeec25e6ab0ef487791dbc59","user":{"login":"lyft","id":4269340,"avatar_url":"https://avatars1.githubusercontent.com/u/4269340?v=3","gravatar_id":"","url":"https://api.github.com/users/lyft","html_url":"https://github.com/lyft","followers_url":"https://api.github.com/users/lyft/followers","following_url":"https://api.github.com/users/lyft/following{/other_user}","gists_url":"https://api.github.com/users/lyft/gists{/gist_id}","starred_url":"https://api.github.com/users/lyft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyft/subscriptions","organizations_url":"https://api.github.com/users/lyft/orgs","repos_url":"https://api.github.com/users/lyft/repos","events_url":"https://api.github.com/users/lyft/events{/privacy}","received_events_url":"https://api.github.com/users/lyft/received_events","type":"Organization","site_admin":false},"repo":{"id":77485113,"name":"gostats","full_name":"lyft/gostats","owner":{"login":"lyft","id":4269340,"avatar_url":"https://avatars1.githubusercontent.com/u/4269340?v=3","gravatar_id":"","url":"https://api.github.com/users/lyft","html_url":"https://github.com/lyft","followers_url":"https://api.github.com/users/lyft/followers","following_url":"https://api.github.com/users/lyft/following{/other_user}","gists_url":"https://api.github.com/users/lyft/gists{/gist_id}","starred_url":"https://api.github.com/users/lyft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyft/subscriptions","organizations_url":"https://api.github.com/users/lyft/orgs","repos_url":"https://api.github.com/users/lyft/repos","events_url":"https://api.github.com/users/lyft/events{/privacy}","received_events_url":"https://api.github.com/users/lyft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lyft/gostats","description":"Go client for Stats","fork":false,"url":"https://api.github.com/repos/lyft/gostats","forks_url":"https://api.github.com/repos/lyft/gostats/forks","keys_url":"https://api.github.com/repos/lyft/gostats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lyft/gostats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lyft/gostats/teams","hooks_url":"https://api.github.com/repos/lyft/gostats/hooks","issue_events_url":"https://api.github.com/repos/lyft/gostats/issues/events{/number}","events_url":"https://api.github.com/repos/lyft/gostats/events","assignees_url":"https://api.github.com/repos/lyft/gostats/assignees{/user}","branches_url":"https://api.github.com/repos/lyft/gostats/branches{/branch}","tags_url":"https://api.github.com/repos/lyft/gostats/tags","blobs_url":"https://api.github.com/repos/lyft/gostats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lyft/gostats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lyft/gostats/git/refs{/sha}","trees_url":"https://api.github.com/repos/lyft/gostats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lyft/gostats/statuses/{sha}","languages_url":"https://api.github.com/repos/lyft/gostats/languages","stargazers_url":"https://api.github.com/repos/lyft/gostats/stargazers","contributors_url":"https://api.github.com/repos/lyft/gostats/contributors","subscribers_url":"https://api.github.com/repos/lyft/gostats/subscribers","subscription_url":"https://api.github.com/repos/lyft/gostats/subscription","commits_url":"https://api.github.com/repos/lyft/gostats/commits{/sha}","git_commits_url":"https://api.github.com/repos/lyft/gostats/git/commits{/sha}","comments_url":"https://api.github.com/repos/lyft/gostats/comments{/number}","issue_comment_url":"https://api.github.com/repos/lyft/gostats/issues/comments{/number}","contents_url":"https://api.github.com/repos/lyft/gostats/contents/{+path}","compare_url":"https://api.github.com/repos/lyft/gostats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lyft/gostats/merges","archive_url":"https://api.github.com/repos/lyft/gostats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lyft/gostats/downloads","issues_url":"https://api.github.com/repos/lyft/gostats/issues{/number}","pulls_url":"https://api.github.com/repos/lyft/gostats/pulls{/number}","milestones_url":"https://api.github.com/repos/lyft/gostats/milestones{/number}","notifications_url":"https://api.github.com/repos/lyft/gostats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lyft/gostats/labels{/name}","releases_url":"https://api.github.com/repos/lyft/gostats/releases{/id}","deployments_url":"https://api.github.com/repos/lyft/gostats/deployments","created_at":"2016-12-27T22:01:18Z","updated_at":"2017-02-24T00:46:09Z","pushed_at":"2017-04-18T21:02:21Z","git_url":"git://github.com/lyft/gostats.git","ssh_url":"git@github.com:lyft/gostats.git","clone_url":"https://github.com/lyft/gostats.git","svn_url":"https://github.com/lyft/gostats","homepage":null,"size":22,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"lyft:master","ref":"master","sha":"337067091fb897f15958ba8821323ba25f00e400","user":{"login":"lyft","id":4269340,"avatar_url":"https://avatars1.githubusercontent.com/u/4269340?v=3","gravatar_id":"","url":"https://api.github.com/users/lyft","html_url":"https://github.com/lyft","followers_url":"https://api.github.com/users/lyft/followers","following_url":"https://api.github.com/users/lyft/following{/other_user}","gists_url":"https://api.github.com/users/lyft/gists{/gist_id}","starred_url":"https://api.github.com/users/lyft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyft/subscriptions","organizations_url":"https://api.github.com/users/lyft/orgs","repos_url":"https://api.github.com/users/lyft/repos","events_url":"https://api.github.com/users/lyft/events{/privacy}","received_events_url":"https://api.github.com/users/lyft/received_events","type":"Organization","site_admin":false},"repo":{"id":77485113,"name":"gostats","full_name":"lyft/gostats","owner":{"login":"lyft","id":4269340,"avatar_url":"https://avatars1.githubusercontent.com/u/4269340?v=3","gravatar_id":"","url":"https://api.github.com/users/lyft","html_url":"https://github.com/lyft","followers_url":"https://api.github.com/users/lyft/followers","following_url":"https://api.github.com/users/lyft/following{/other_user}","gists_url":"https://api.github.com/users/lyft/gists{/gist_id}","starred_url":"https://api.github.com/users/lyft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyft/subscriptions","organizations_url":"https://api.github.com/users/lyft/orgs","repos_url":"https://api.github.com/users/lyft/repos","events_url":"https://api.github.com/users/lyft/events{/privacy}","received_events_url":"https://api.github.com/users/lyft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lyft/gostats","description":"Go client for Stats","fork":false,"url":"https://api.github.com/repos/lyft/gostats","forks_url":"https://api.github.com/repos/lyft/gostats/forks","keys_url":"https://api.github.com/repos/lyft/gostats/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lyft/gostats/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lyft/gostats/teams","hooks_url":"https://api.github.com/repos/lyft/gostats/hooks","issue_events_url":"https://api.github.com/repos/lyft/gostats/issues/events{/number}","events_url":"https://api.github.com/repos/lyft/gostats/events","assignees_url":"https://api.github.com/repos/lyft/gostats/assignees{/user}","branches_url":"https://api.github.com/repos/lyft/gostats/branches{/branch}","tags_url":"https://api.github.com/repos/lyft/gostats/tags","blobs_url":"https://api.github.com/repos/lyft/gostats/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lyft/gostats/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lyft/gostats/git/refs{/sha}","trees_url":"https://api.github.com/repos/lyft/gostats/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lyft/gostats/statuses/{sha}","languages_url":"https://api.github.com/repos/lyft/gostats/languages","stargazers_url":"https://api.github.com/repos/lyft/gostats/stargazers","contributors_url":"https://api.github.com/repos/lyft/gostats/contributors","subscribers_url":"https://api.github.com/repos/lyft/gostats/subscribers","subscription_url":"https://api.github.com/repos/lyft/gostats/subscription","commits_url":"https://api.github.com/repos/lyft/gostats/commits{/sha}","git_commits_url":"https://api.github.com/repos/lyft/gostats/git/commits{/sha}","comments_url":"https://api.github.com/repos/lyft/gostats/comments{/number}","issue_comment_url":"https://api.github.com/repos/lyft/gostats/issues/comments{/number}","contents_url":"https://api.github.com/repos/lyft/gostats/contents/{+path}","compare_url":"https://api.github.com/repos/lyft/gostats/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lyft/gostats/merges","archive_url":"https://api.github.com/repos/lyft/gostats/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lyft/gostats/downloads","issues_url":"https://api.github.com/repos/lyft/gostats/issues{/number}","pulls_url":"https://api.github.com/repos/lyft/gostats/pulls{/number}","milestones_url":"https://api.github.com/repos/lyft/gostats/milestones{/number}","notifications_url":"https://api.github.com/repos/lyft/gostats/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lyft/gostats/labels{/name}","releases_url":"https://api.github.com/repos/lyft/gostats/releases{/id}","deployments_url":"https://api.github.com/repos/lyft/gostats/deployments","created_at":"2016-12-27T22:01:18Z","updated_at":"2017-02-24T00:46:09Z","pushed_at":"2017-04-18T21:02:21Z","git_url":"git://github.com/lyft/gostats.git","ssh_url":"git@github.com:lyft/gostats.git","clone_url":"https://github.com/lyft/gostats.git","svn_url":"https://github.com/lyft/gostats","homepage":null,"size":22,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lyft/gostats/pulls/10"},"html":{"href":"https://github.com/lyft/gostats/pull/10"},"issue":{"href":"https://api.github.com/repos/lyft/gostats/issues/10"},"comments":{"href":"https://api.github.com/repos/lyft/gostats/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/lyft/gostats/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/lyft/gostats/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lyft/gostats/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/lyft/gostats/statuses/02a9d322ef9b23c8eeec25e6ab0ef487791dbc59"}},"merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":false,"commits":1,"additions":114,"deletions":62,"changed_files":4}}
{"actor":{"display_login":"rodaine"}}