{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/46139623","id":46139623,"diff_hunk":"@@ -1660,3 +1677,55 @@ func (r *Replica) maybeAddToSplitQueue() {\n \t\tr.store.splitQueue.MaybeAdd(r, r.store.Clock().Now())\n \t}\n }\n+\n+// processReplicaCmd get a raft command from command queue and\n+// call processRaftCommand to execute in a loop until there is\n+// not any command in the queue for 5 seconds.\n+func (r *Replica) processReplicaCmd() {\n+\tfor {\n+\t\tselect {\n+\t\tcase cmd := <-r.cmdQueueChan:\n+\t\t\terr := r.processRaftCommand(cmd.idKey, cmd.index, cmd.raftCmd)\n+\t\t\tif cmd.callback != nil {\n+\t\t\t\tcmd.callback(err)\n+\t\t\t}\n+\n+\t\tcase <-time.After(5 * time.Second):\n+\t\t\tr.stopFlagLock.Lock()\n+\t\t\tif len(r.cmdQueueChan) == 0 {\n+\t\t\t\tr.stopFlag = true\n+\t\t\t\tr.stopFlagLock.Unlock()\n+\t\t\t\treturn\n+\t\t\t}\n+\t\t\tr.stopFlagLock.Unlock()\n+\n+\t\tcase <-r.store.stopper.ShouldStop():\n+\t\t\treturn\n+\t\t}\n+\t}\n+}\n+\n+// addCmdQueue insert a raft command into command queue on each replica.\n+// If replica's process goroutine already stopped, start a new one to get\n+// and execute the command in command queue.\n+func (r *Replica) addCmdQueue(idKey cmdIDKey, index uint64, raftCmd roachpb.RaftCommand, f func(error)) {\n+\tr.cmdQueueChan <- committedCmd{\n+\t\tidKey:    idKey,\n+\t\tindex:    index,\n+\t\traftCmd:  raftCmd,\n+\t\tcallback: f,\n+\t}\n+\n+\tr.stopFlagLock.Lock()\n+\tif r.stopFlag {\n+\t\tr.stopFlag = false\n+\t\tr.stopFlagLock.Unlock()\n+\n+\t\tr.store.stopper.RunWorker(func() {","path":"storage/replica.go","position":103,"original_position":103,"commit_id":"4fa25a31ce7fe778b6465f04f3998b71bfdf5805","original_commit_id":"4fa25a31ce7fe778b6465f04f3998b71bfdf5805","user":{"login":"tamird","id":1535036,"avatar_url":"https://avatars.githubusercontent.com/u/1535036?v=3","gravatar_id":"","url":"https://api.github.com/users/tamird","html_url":"https://github.com/tamird","followers_url":"https://api.github.com/users/tamird/followers","following_url":"https://api.github.com/users/tamird/following{/other_user}","gists_url":"https://api.github.com/users/tamird/gists{/gist_id}","starred_url":"https://api.github.com/users/tamird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tamird/subscriptions","organizations_url":"https://api.github.com/users/tamird/orgs","repos_url":"https://api.github.com/users/tamird/repos","events_url":"https://api.github.com/users/tamird/events{/privacy}","received_events_url":"https://api.github.com/users/tamird/received_events","type":"User","site_admin":false},"body":"You can pass r.processReplicaCmd directly here","created_at":"2015-11-30T12:59:24Z","updated_at":"2015-11-30T12:59:24Z","html_url":"https://github.com/cockroachdb/cockroach/pull/3244#discussion_r46139623","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/46139623"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/3244#discussion_r46139623"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244","id":52094582,"html_url":"https://github.com/cockroachdb/cockroach/pull/3244","diff_url":"https://github.com/cockroachdb/cockroach/pull/3244.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/3244.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/3244","number":3244,"state":"open","locked":false,"title":"execute replica command parallely","user":{"login":"YuleiXiao","id":12639880,"avatar_url":"https://avatars.githubusercontent.com/u/12639880?v=3","gravatar_id":"","url":"https://api.github.com/users/YuleiXiao","html_url":"https://github.com/YuleiXiao","followers_url":"https://api.github.com/users/YuleiXiao/followers","following_url":"https://api.github.com/users/YuleiXiao/following{/other_user}","gists_url":"https://api.github.com/users/YuleiXiao/gists{/gist_id}","starred_url":"https://api.github.com/users/YuleiXiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YuleiXiao/subscriptions","organizations_url":"https://api.github.com/users/YuleiXiao/orgs","repos_url":"https://api.github.com/users/YuleiXiao/repos","events_url":"https://api.github.com/users/YuleiXiao/events{/privacy}","received_events_url":"https://api.github.com/users/YuleiXiao/received_events","type":"User","site_admin":false},"body":"we can execute replica command concurrency for better performance, no necessary all replicas in the store are executing in order.\r\n\r\nI benchmark it on my server. 100 ranges split with 1~100, 100 clients insert random number key and value size is 10K. The result is below:\r\n\r\nbefore modify:\r\n```\r\ntotal time(seconds): 26.001469\r\ntps: 3545.936589\r\n```\r\nafter modify\r\n```\r\ntotal time(seconds): 23.027841\r\ntps: 4342.569445\r\n```\r\n\r\n<!-- Reviewable:start -->\r\n[<img src=\"https://reviewable.io/review_button.png\" height=40 alt=\"Review on Reviewable\"/>](https://reviewable.io/reviews/cockroachdb/cockroach/3244)\r\n<!-- Reviewable:end -->\r\n","created_at":"2015-11-30T08:05:18Z","updated_at":"2015-11-30T12:59:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b7d7d667234fb243ec4cf5d46148440fcd8e0ed3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/3244/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/4fa25a31ce7fe778b6465f04f3998b71bfdf5805","head":{"label":"YuleiXiao:replica_paralle","ref":"replica_paralle","sha":"4fa25a31ce7fe778b6465f04f3998b71bfdf5805","user":{"login":"YuleiXiao","id":12639880,"avatar_url":"https://avatars.githubusercontent.com/u/12639880?v=3","gravatar_id":"","url":"https://api.github.com/users/YuleiXiao","html_url":"https://github.com/YuleiXiao","followers_url":"https://api.github.com/users/YuleiXiao/followers","following_url":"https://api.github.com/users/YuleiXiao/following{/other_user}","gists_url":"https://api.github.com/users/YuleiXiao/gists{/gist_id}","starred_url":"https://api.github.com/users/YuleiXiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YuleiXiao/subscriptions","organizations_url":"https://api.github.com/users/YuleiXiao/orgs","repos_url":"https://api.github.com/users/YuleiXiao/repos","events_url":"https://api.github.com/users/YuleiXiao/events{/privacy}","received_events_url":"https://api.github.com/users/YuleiXiao/received_events","type":"User","site_admin":false},"repo":{"id":38094705,"name":"cockroach","full_name":"YuleiXiao/cockroach","owner":{"login":"YuleiXiao","id":12639880,"avatar_url":"https://avatars.githubusercontent.com/u/12639880?v=3","gravatar_id":"","url":"https://api.github.com/users/YuleiXiao","html_url":"https://github.com/YuleiXiao","followers_url":"https://api.github.com/users/YuleiXiao/followers","following_url":"https://api.github.com/users/YuleiXiao/following{/other_user}","gists_url":"https://api.github.com/users/YuleiXiao/gists{/gist_id}","starred_url":"https://api.github.com/users/YuleiXiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YuleiXiao/subscriptions","organizations_url":"https://api.github.com/users/YuleiXiao/orgs","repos_url":"https://api.github.com/users/YuleiXiao/repos","events_url":"https://api.github.com/users/YuleiXiao/events{/privacy}","received_events_url":"https://api.github.com/users/YuleiXiao/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/YuleiXiao/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":true,"url":"https://api.github.com/repos/YuleiXiao/cockroach","forks_url":"https://api.github.com/repos/YuleiXiao/cockroach/forks","keys_url":"https://api.github.com/repos/YuleiXiao/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/YuleiXiao/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/YuleiXiao/cockroach/teams","hooks_url":"https://api.github.com/repos/YuleiXiao/cockroach/hooks","issue_events_url":"https://api.github.com/repos/YuleiXiao/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/YuleiXiao/cockroach/events","assignees_url":"https://api.github.com/repos/YuleiXiao/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/YuleiXiao/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/YuleiXiao/cockroach/tags","blobs_url":"https://api.github.com/repos/YuleiXiao/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/YuleiXiao/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/YuleiXiao/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/YuleiXiao/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/YuleiXiao/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/YuleiXiao/cockroach/languages","stargazers_url":"https://api.github.com/repos/YuleiXiao/cockroach/stargazers","contributors_url":"https://api.github.com/repos/YuleiXiao/cockroach/contributors","subscribers_url":"https://api.github.com/repos/YuleiXiao/cockroach/subscribers","subscription_url":"https://api.github.com/repos/YuleiXiao/cockroach/subscription","commits_url":"https://api.github.com/repos/YuleiXiao/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/YuleiXiao/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/YuleiXiao/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/YuleiXiao/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/YuleiXiao/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/YuleiXiao/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/YuleiXiao/cockroach/merges","archive_url":"https://api.github.com/repos/YuleiXiao/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/YuleiXiao/cockroach/downloads","issues_url":"https://api.github.com/repos/YuleiXiao/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/YuleiXiao/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/YuleiXiao/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/YuleiXiao/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/YuleiXiao/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/YuleiXiao/cockroach/releases{/id}","created_at":"2015-06-26T06:24:46Z","updated_at":"2015-08-02T19:22:19Z","pushed_at":"2015-11-30T07:41:56Z","git_url":"git://github.com/YuleiXiao/cockroach.git","ssh_url":"git@github.com:YuleiXiao/cockroach.git","clone_url":"https://github.com/YuleiXiao/cockroach.git","svn_url":"https://github.com/YuleiXiao/cockroach","homepage":null,"size":46776,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"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":1,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"b0cd7286d4adcc5e5da43d1248307e2e84d1c24a","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-11-30T10:24:39Z","pushed_at":"2015-11-30T11:57:58Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":52794,"stargazers_count":5774,"watchers_count":5774,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":485,"mirror_url":null,"open_issues_count":221,"forks":485,"open_issues":221,"watchers":5774,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/3244"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/3244"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/3244/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/3244/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/4fa25a31ce7fe778b6465f04f3998b71bfdf5805"}}}}