{"action":"created","comment":{"url":"https://api.github.com/repos/uber-go/cadence-client/pulls/comments/128345965","pull_request_review_id":51017813,"id":128345965,"diff_hunk":"@@ -121,18 +133,128 @@ func (bw *baseWorker) Start() {\n \t\treturn\n \t}\n \n-\t// Launch the routines to do work\n-\tfor i := 0; i < bw.options.routineCount; i++ {\n+\tfor i := 0; i < bw.options.pollerCount; i++ {\n \t\tbw.shutdownWG.Add(1)\n-\t\tgo bw.execute(i)\n+\t\tgo bw.runPoller()\n \t}\n+\tbw.shutdownWG.Add(1)\n+\tgo bw.runTaskDispatcher()\n \n \tbw.isWorkerStarted = true\n \ttraceLog(func() {\n-\t\tbw.logger.Info(\"Started Worker\", zap.Int(\"RoutineCount\", bw.options.routineCount))\n+\t\tbw.logger.Info(\"Started Worker\",\n+\t\t\tzap.Int(\"PollerCount\", bw.options.pollerCount),\n+\t\t\tzap.Int(\"MaxConcurrentTask\", bw.options.maxConcurrentTask),\n+\t\t\tzap.Int(\"MaxTaskRps\", bw.options.maxTaskRps),\n+\t\t)\n \t})\n }\n \n+func (bw *baseWorker) isShutdown() bool {\n+\tselect {\n+\tcase <-bw.shutdownCh:\n+\t\treturn true\n+\tdefault:\n+\t\treturn false\n+\t}\n+}\n+\n+func (bw *baseWorker) runPoller() {\n+\tdefer bw.shutdownWG.Done()\n+\n+\tbw.pollerRequestCh <- struct{}{} // initial poll request to kick off the poller loop\n+\n+\tfor {\n+\t\tselect {\n+\t\tcase <-bw.shutdownCh:\n+\t\t\treturn\n+\t\tcase <-bw.pollerRequestCh:\n+\t\t\tch := make(chan struct{})\n+\t\t\tgo func(ch chan struct{}) {\n+\t\t\t\tbw.pollTask()\n+\t\t\t\tclose(ch)\n+\t\t\t}(ch)\n+\n+\t\t\t// block until previous poll completed or return immediately when shutdown\n+\t\t\tselect {\n+\t\t\tcase <-bw.shutdownCh:\n+\t\t\t\treturn\n+\t\t\tcase <-ch:\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+func (bw *baseWorker) runTaskDispatcher() {\n+\tdefer bw.shutdownWG.Done()\n+\n+\tfor i := 0; i < bw.options.maxConcurrentTask; i++ {\n+\t\tbw.taskSemaphore <- struct{}{}\n+\t}\n+\n+\tfor {\n+\t\t// wait for new task or shutdown\n+\t\tselect {\n+\t\tcase <-bw.shutdownCh:\n+\t\t\treturn\n+\t\tcase task := <-bw.taskQueueCh:\n+\t\t\tbw.pollerRequestCh <- struct{}{}","path":"internal_worker_base.go","position":130,"original_position":130,"commit_id":"a3f02662ace024f5849b1a7322926a43cef9a7e1","original_commit_id":"a3f02662ace024f5849b1a7322926a43cef9a7e1","user":{"login":"yiminc","id":10816227,"avatar_url":"https://avatars1.githubusercontent.com/u/10816227?v=4","gravatar_id":"","url":"https://api.github.com/users/yiminc","html_url":"https://github.com/yiminc","followers_url":"https://api.github.com/users/yiminc/followers","following_url":"https://api.github.com/users/yiminc/following{/other_user}","gists_url":"https://api.github.com/users/yiminc/gists{/gist_id}","starred_url":"https://api.github.com/users/yiminc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiminc/subscriptions","organizations_url":"https://api.github.com/users/yiminc/orgs","repos_url":"https://api.github.com/users/yiminc/repos","events_url":"https://api.github.com/users/yiminc/events{/privacy}","received_events_url":"https://api.github.com/users/yiminc/received_events","type":"User","site_admin":false},"body":"We can do better by checking if the concurrent task count is still less than the max, and if so we send poller request before process task, otherwise we send poller request after process task.","created_at":"2017-07-19T19:38:32Z","updated_at":"2017-07-19T19:38:32Z","html_url":"https://github.com/uber-go/cadence-client/pull/186#discussion_r128345965","pull_request_url":"https://api.github.com/repos/uber-go/cadence-client/pulls/186","_links":{"self":{"href":"https://api.github.com/repos/uber-go/cadence-client/pulls/comments/128345965"},"html":{"href":"https://github.com/uber-go/cadence-client/pull/186#discussion_r128345965"},"pull_request":{"href":"https://api.github.com/repos/uber-go/cadence-client/pulls/186"}}},"pull_request":{"url":"https://api.github.com/repos/uber-go/cadence-client/pulls/186","id":131239862,"html_url":"https://github.com/uber-go/cadence-client/pull/186","diff_url":"https://github.com/uber-go/cadence-client/pull/186.diff","patch_url":"https://github.com/uber-go/cadence-client/pull/186.patch","issue_url":"https://api.github.com/repos/uber-go/cadence-client/issues/186","number":186,"state":"open","locked":false,"title":"threading model","user":{"login":"yiminc","id":10816227,"avatar_url":"https://avatars1.githubusercontent.com/u/10816227?v=4","gravatar_id":"","url":"https://api.github.com/users/yiminc","html_url":"https://github.com/yiminc","followers_url":"https://api.github.com/users/yiminc/followers","following_url":"https://api.github.com/users/yiminc/following{/other_user}","gists_url":"https://api.github.com/users/yiminc/gists{/gist_id}","starred_url":"https://api.github.com/users/yiminc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiminc/subscriptions","organizations_url":"https://api.github.com/users/yiminc/orgs","repos_url":"https://api.github.com/users/yiminc/repos","events_url":"https://api.github.com/users/yiminc/events{/privacy}","received_events_url":"https://api.github.com/users/yiminc/received_events","type":"User","site_admin":false},"body":"break PollAndProcessSingleTask() into 2 methods: PollTask() and ProcessTask(). Restructure the code to have poller that polls task and send task to taskQueueCh then a task dispatcher is receiving from that task queue channel and dispatch to process it. Task rate limiter is also added.","created_at":"2017-07-19T05:30:31Z","updated_at":"2017-07-19T19:38:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c3cbf42f74bc61a64214651789cb64cd8417b1ec","assignee":null,"assignees":[],"requested_reviewers":[{"login":"mfateev","id":1463622,"avatar_url":"https://avatars1.githubusercontent.com/u/1463622?v=4","gravatar_id":"","url":"https://api.github.com/users/mfateev","html_url":"https://github.com/mfateev","followers_url":"https://api.github.com/users/mfateev/followers","following_url":"https://api.github.com/users/mfateev/following{/other_user}","gists_url":"https://api.github.com/users/mfateev/gists{/gist_id}","starred_url":"https://api.github.com/users/mfateev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mfateev/subscriptions","organizations_url":"https://api.github.com/users/mfateev/orgs","repos_url":"https://api.github.com/users/mfateev/repos","events_url":"https://api.github.com/users/mfateev/events{/privacy}","received_events_url":"https://api.github.com/users/mfateev/received_events","type":"User","site_admin":false},{"login":"madhuravi","id":13949271,"avatar_url":"https://avatars2.githubusercontent.com/u/13949271?v=4","gravatar_id":"","url":"https://api.github.com/users/madhuravi","html_url":"https://github.com/madhuravi","followers_url":"https://api.github.com/users/madhuravi/followers","following_url":"https://api.github.com/users/madhuravi/following{/other_user}","gists_url":"https://api.github.com/users/madhuravi/gists{/gist_id}","starred_url":"https://api.github.com/users/madhuravi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madhuravi/subscriptions","organizations_url":"https://api.github.com/users/madhuravi/orgs","repos_url":"https://api.github.com/users/madhuravi/repos","events_url":"https://api.github.com/users/madhuravi/events{/privacy}","received_events_url":"https://api.github.com/users/madhuravi/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/uber-go/cadence-client/pulls/186/commits","review_comments_url":"https://api.github.com/repos/uber-go/cadence-client/pulls/186/comments","review_comment_url":"https://api.github.com/repos/uber-go/cadence-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber-go/cadence-client/issues/186/comments","statuses_url":"https://api.github.com/repos/uber-go/cadence-client/statuses/a3f02662ace024f5849b1a7322926a43cef9a7e1","head":{"label":"yiminc:threading_model","ref":"threading_model","sha":"a3f02662ace024f5849b1a7322926a43cef9a7e1","user":{"login":"yiminc","id":10816227,"avatar_url":"https://avatars1.githubusercontent.com/u/10816227?v=4","gravatar_id":"","url":"https://api.github.com/users/yiminc","html_url":"https://github.com/yiminc","followers_url":"https://api.github.com/users/yiminc/followers","following_url":"https://api.github.com/users/yiminc/following{/other_user}","gists_url":"https://api.github.com/users/yiminc/gists{/gist_id}","starred_url":"https://api.github.com/users/yiminc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiminc/subscriptions","organizations_url":"https://api.github.com/users/yiminc/orgs","repos_url":"https://api.github.com/users/yiminc/repos","events_url":"https://api.github.com/users/yiminc/events{/privacy}","received_events_url":"https://api.github.com/users/yiminc/received_events","type":"User","site_admin":false},"repo":{"id":93577568,"name":"cadence-client","full_name":"yiminc/cadence-client","owner":{"login":"yiminc","id":10816227,"avatar_url":"https://avatars1.githubusercontent.com/u/10816227?v=4","gravatar_id":"","url":"https://api.github.com/users/yiminc","html_url":"https://github.com/yiminc","followers_url":"https://api.github.com/users/yiminc/followers","following_url":"https://api.github.com/users/yiminc/following{/other_user}","gists_url":"https://api.github.com/users/yiminc/gists{/gist_id}","starred_url":"https://api.github.com/users/yiminc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yiminc/subscriptions","organizations_url":"https://api.github.com/users/yiminc/orgs","repos_url":"https://api.github.com/users/yiminc/repos","events_url":"https://api.github.com/users/yiminc/events{/privacy}","received_events_url":"https://api.github.com/users/yiminc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yiminc/cadence-client","description":"Framework for authoring workflows and activities running on top of the Cadence orchestration engine.","fork":true,"url":"https://api.github.com/repos/yiminc/cadence-client","forks_url":"https://api.github.com/repos/yiminc/cadence-client/forks","keys_url":"https://api.github.com/repos/yiminc/cadence-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yiminc/cadence-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yiminc/cadence-client/teams","hooks_url":"https://api.github.com/repos/yiminc/cadence-client/hooks","issue_events_url":"https://api.github.com/repos/yiminc/cadence-client/issues/events{/number}","events_url":"https://api.github.com/repos/yiminc/cadence-client/events","assignees_url":"https://api.github.com/repos/yiminc/cadence-client/assignees{/user}","branches_url":"https://api.github.com/repos/yiminc/cadence-client/branches{/branch}","tags_url":"https://api.github.com/repos/yiminc/cadence-client/tags","blobs_url":"https://api.github.com/repos/yiminc/cadence-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yiminc/cadence-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yiminc/cadence-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/yiminc/cadence-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yiminc/cadence-client/statuses/{sha}","languages_url":"https://api.github.com/repos/yiminc/cadence-client/languages","stargazers_url":"https://api.github.com/repos/yiminc/cadence-client/stargazers","contributors_url":"https://api.github.com/repos/yiminc/cadence-client/contributors","subscribers_url":"https://api.github.com/repos/yiminc/cadence-client/subscribers","subscription_url":"https://api.github.com/repos/yiminc/cadence-client/subscription","commits_url":"https://api.github.com/repos/yiminc/cadence-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/yiminc/cadence-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/yiminc/cadence-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/yiminc/cadence-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/yiminc/cadence-client/contents/{+path}","compare_url":"https://api.github.com/repos/yiminc/cadence-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yiminc/cadence-client/merges","archive_url":"https://api.github.com/repos/yiminc/cadence-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yiminc/cadence-client/downloads","issues_url":"https://api.github.com/repos/yiminc/cadence-client/issues{/number}","pulls_url":"https://api.github.com/repos/yiminc/cadence-client/pulls{/number}","milestones_url":"https://api.github.com/repos/yiminc/cadence-client/milestones{/number}","notifications_url":"https://api.github.com/repos/yiminc/cadence-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yiminc/cadence-client/labels{/name}","releases_url":"https://api.github.com/repos/yiminc/cadence-client/releases{/id}","deployments_url":"https://api.github.com/repos/yiminc/cadence-client/deployments","created_at":"2017-06-07T01:09:40Z","updated_at":"2017-06-07T01:09:42Z","pushed_at":"2017-07-19T06:40:55Z","git_url":"git://github.com/yiminc/cadence-client.git","ssh_url":"git@github.com:yiminc/cadence-client.git","clone_url":"https://github.com/yiminc/cadence-client.git","svn_url":"https://github.com/yiminc/cadence-client","homepage":"","size":1742,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"uber-go:master","ref":"master","sha":"841e5262113f39c31cdc070b68231d7d30686223","user":{"login":"uber-go","id":19262598,"avatar_url":"https://avatars2.githubusercontent.com/u/19262598?v=4","gravatar_id":"","url":"https://api.github.com/users/uber-go","html_url":"https://github.com/uber-go","followers_url":"https://api.github.com/users/uber-go/followers","following_url":"https://api.github.com/users/uber-go/following{/other_user}","gists_url":"https://api.github.com/users/uber-go/gists{/gist_id}","starred_url":"https://api.github.com/users/uber-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber-go/subscriptions","organizations_url":"https://api.github.com/users/uber-go/orgs","repos_url":"https://api.github.com/users/uber-go/repos","events_url":"https://api.github.com/users/uber-go/events{/privacy}","received_events_url":"https://api.github.com/users/uber-go/received_events","type":"Organization","site_admin":false},"repo":{"id":84307372,"name":"cadence-client","full_name":"uber-go/cadence-client","owner":{"login":"uber-go","id":19262598,"avatar_url":"https://avatars2.githubusercontent.com/u/19262598?v=4","gravatar_id":"","url":"https://api.github.com/users/uber-go","html_url":"https://github.com/uber-go","followers_url":"https://api.github.com/users/uber-go/followers","following_url":"https://api.github.com/users/uber-go/following{/other_user}","gists_url":"https://api.github.com/users/uber-go/gists{/gist_id}","starred_url":"https://api.github.com/users/uber-go/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber-go/subscriptions","organizations_url":"https://api.github.com/users/uber-go/orgs","repos_url":"https://api.github.com/users/uber-go/repos","events_url":"https://api.github.com/users/uber-go/events{/privacy}","received_events_url":"https://api.github.com/users/uber-go/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber-go/cadence-client","description":"Framework for authoring workflows and activities running on top of the Cadence orchestration engine.","fork":false,"url":"https://api.github.com/repos/uber-go/cadence-client","forks_url":"https://api.github.com/repos/uber-go/cadence-client/forks","keys_url":"https://api.github.com/repos/uber-go/cadence-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber-go/cadence-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber-go/cadence-client/teams","hooks_url":"https://api.github.com/repos/uber-go/cadence-client/hooks","issue_events_url":"https://api.github.com/repos/uber-go/cadence-client/issues/events{/number}","events_url":"https://api.github.com/repos/uber-go/cadence-client/events","assignees_url":"https://api.github.com/repos/uber-go/cadence-client/assignees{/user}","branches_url":"https://api.github.com/repos/uber-go/cadence-client/branches{/branch}","tags_url":"https://api.github.com/repos/uber-go/cadence-client/tags","blobs_url":"https://api.github.com/repos/uber-go/cadence-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber-go/cadence-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber-go/cadence-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber-go/cadence-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber-go/cadence-client/statuses/{sha}","languages_url":"https://api.github.com/repos/uber-go/cadence-client/languages","stargazers_url":"https://api.github.com/repos/uber-go/cadence-client/stargazers","contributors_url":"https://api.github.com/repos/uber-go/cadence-client/contributors","subscribers_url":"https://api.github.com/repos/uber-go/cadence-client/subscribers","subscription_url":"https://api.github.com/repos/uber-go/cadence-client/subscription","commits_url":"https://api.github.com/repos/uber-go/cadence-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber-go/cadence-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber-go/cadence-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber-go/cadence-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber-go/cadence-client/contents/{+path}","compare_url":"https://api.github.com/repos/uber-go/cadence-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber-go/cadence-client/merges","archive_url":"https://api.github.com/repos/uber-go/cadence-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber-go/cadence-client/downloads","issues_url":"https://api.github.com/repos/uber-go/cadence-client/issues{/number}","pulls_url":"https://api.github.com/repos/uber-go/cadence-client/pulls{/number}","milestones_url":"https://api.github.com/repos/uber-go/cadence-client/milestones{/number}","notifications_url":"https://api.github.com/repos/uber-go/cadence-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber-go/cadence-client/labels{/name}","releases_url":"https://api.github.com/repos/uber-go/cadence-client/releases{/id}","deployments_url":"https://api.github.com/repos/uber-go/cadence-client/deployments","created_at":"2017-03-08T10:17:42Z","updated_at":"2017-06-22T10:28:54Z","pushed_at":"2017-07-19T06:40:56Z","git_url":"git://github.com/uber-go/cadence-client.git","ssh_url":"git@github.com:uber-go/cadence-client.git","clone_url":"https://github.com/uber-go/cadence-client.git","svn_url":"https://github.com/uber-go/cadence-client","homepage":"","size":1760,"stargazers_count":7,"watchers_count":7,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":25,"forks":6,"open_issues":25,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber-go/cadence-client/pulls/186"},"html":{"href":"https://github.com/uber-go/cadence-client/pull/186"},"issue":{"href":"https://api.github.com/repos/uber-go/cadence-client/issues/186"},"comments":{"href":"https://api.github.com/repos/uber-go/cadence-client/issues/186/comments"},"review_comments":{"href":"https://api.github.com/repos/uber-go/cadence-client/pulls/186/comments"},"review_comment":{"href":"https://api.github.com/repos/uber-go/cadence-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber-go/cadence-client/pulls/186/commits"},"statuses":{"href":"https://api.github.com/repos/uber-go/cadence-client/statuses/a3f02662ace024f5849b1a7322926a43cef9a7e1"}}}}
{"actor":{"display_login":"yiminc"}}