{"action":"created","comment":{"url":"https://api.github.com/repos/open-falcon/agent/pulls/comments/53728114","id":53728114,"diff_hunk":"@@ -0,0 +1,55 @@\n+package g\n+\n+import (\n+\t\"log\"\n+\t\"math/rand\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/open-falcon/common/model\"\n+)\n+\n+var (\n+\tTransferLock    *sync.RWMutex                   = new(sync.RWMutex)\n+\tTransferClients map[string]*SingleConnRpcClient = map[string]*SingleConnRpcClient{}\n+)\n+\n+func SendMetrics(metrics []*model.MetricValue, resp model.TransferResponse) {\n+\trand.Seed(time.Now().UnixNano())\n+\tfor _, i := range rand.Perm(len(Config().Transfer.Addrs)) {\n+\t\taddr := Config().Transfer.Addrs[i]\n+\t\tif _, ok := TransferClients[addr]; !ok {\n+\t\t\tinitTransferClient(addr)\n+\t\t}\n+\t\tif updateMetrics(addr, metrics, resp) {\n+\t\t\tbreak\n+\t\t}\n+\t\tcloseTransferClient(addr)\n+\t}\n+}\n+\n+func initTransferClient(addr string) {\n+\tTransferLock.Lock()\n+\tdefer TransferLock.Unlock()\n+\tTransferClients[addr] = &SingleConnRpcClient{\n+\t\tRpcServer: addr,\n+\t\tTimeout:   time.Duration(Config().Transfer.Timeout) * time.Millisecond,\n+\t}\n+}\n+\n+func closeTransferClient(addr string) {\n+\tTransferLock.Lock()\n+\tdefer TransferLock.Unlock()\n+\tdelete(TransferClients, addr)","path":"g/transfer.go","position":43,"original_position":43,"commit_id":"ecd07405e76f988b196b64f23c2e394bae720414","original_commit_id":"ecd07405e76f988b196b64f23c2e394bae720414","user":{"login":"laiwei","id":792850,"avatar_url":"https://avatars.githubusercontent.com/u/792850?v=3","gravatar_id":"","url":"https://api.github.com/users/laiwei","html_url":"https://github.com/laiwei","followers_url":"https://api.github.com/users/laiwei/followers","following_url":"https://api.github.com/users/laiwei/following{/other_user}","gists_url":"https://api.github.com/users/laiwei/gists{/gist_id}","starred_url":"https://api.github.com/users/laiwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laiwei/subscriptions","organizations_url":"https://api.github.com/users/laiwei/orgs","repos_url":"https://api.github.com/users/laiwei/repos","events_url":"https://api.github.com/users/laiwei/events{/privacy}","received_events_url":"https://api.github.com/users/laiwei/received_events","type":"User","site_admin":false},"body":"在delete的时候，是不是close一下这个连接，否则会让连接无法释放，造成泄露","created_at":"2016-02-23T02:20:39Z","updated_at":"2016-02-23T02:20:39Z","html_url":"https://github.com/open-falcon/agent/pull/37#discussion_r53728114","pull_request_url":"https://api.github.com/repos/open-falcon/agent/pulls/37","_links":{"self":{"href":"https://api.github.com/repos/open-falcon/agent/pulls/comments/53728114"},"html":{"href":"https://github.com/open-falcon/agent/pull/37#discussion_r53728114"},"pull_request":{"href":"https://api.github.com/repos/open-falcon/agent/pulls/37"}}},"pull_request":{"url":"https://api.github.com/repos/open-falcon/agent/pulls/37","id":60133833,"html_url":"https://github.com/open-falcon/agent/pull/37","diff_url":"https://github.com/open-falcon/agent/pull/37.diff","patch_url":"https://github.com/open-falcon/agent/pull/37.patch","issue_url":"https://api.github.com/repos/open-falcon/agent/issues/37","number":37,"state":"open","locked":false,"title":"Transfer HA","user":{"login":"CMGS","id":506216,"avatar_url":"https://avatars.githubusercontent.com/u/506216?v=3","gravatar_id":"","url":"https://api.github.com/users/CMGS","html_url":"https://github.com/CMGS","followers_url":"https://api.github.com/users/CMGS/followers","following_url":"https://api.github.com/users/CMGS/following{/other_user}","gists_url":"https://api.github.com/users/CMGS/gists{/gist_id}","starred_url":"https://api.github.com/users/CMGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CMGS/subscriptions","organizations_url":"https://api.github.com/users/CMGS/orgs","repos_url":"https://api.github.com/users/CMGS/repos","events_url":"https://api.github.com/users/CMGS/events{/privacy}","received_events_url":"https://api.github.com/users/CMGS/received_events","type":"User","site_admin":false},"body":"随机打乱 transfer 列表然后发送数据到其中一个 transfer","created_at":"2016-02-22T07:16:34Z","updated_at":"2016-02-23T02:20:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2a3b92432d8cedd4b7a2027ea575dfcca8624be9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/open-falcon/agent/pulls/37/commits","review_comments_url":"https://api.github.com/repos/open-falcon/agent/pulls/37/comments","review_comment_url":"https://api.github.com/repos/open-falcon/agent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/open-falcon/agent/issues/37/comments","statuses_url":"https://api.github.com/repos/open-falcon/agent/statuses/ecd07405e76f988b196b64f23c2e394bae720414","head":{"label":"CMGS:master","ref":"master","sha":"ecd07405e76f988b196b64f23c2e394bae720414","user":{"login":"CMGS","id":506216,"avatar_url":"https://avatars.githubusercontent.com/u/506216?v=3","gravatar_id":"","url":"https://api.github.com/users/CMGS","html_url":"https://github.com/CMGS","followers_url":"https://api.github.com/users/CMGS/followers","following_url":"https://api.github.com/users/CMGS/following{/other_user}","gists_url":"https://api.github.com/users/CMGS/gists{/gist_id}","starred_url":"https://api.github.com/users/CMGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CMGS/subscriptions","organizations_url":"https://api.github.com/users/CMGS/orgs","repos_url":"https://api.github.com/users/CMGS/repos","events_url":"https://api.github.com/users/CMGS/events{/privacy}","received_events_url":"https://api.github.com/users/CMGS/received_events","type":"User","site_admin":false},"repo":{"id":50497576,"name":"agent","full_name":"CMGS/agent","owner":{"login":"CMGS","id":506216,"avatar_url":"https://avatars.githubusercontent.com/u/506216?v=3","gravatar_id":"","url":"https://api.github.com/users/CMGS","html_url":"https://github.com/CMGS","followers_url":"https://api.github.com/users/CMGS/followers","following_url":"https://api.github.com/users/CMGS/following{/other_user}","gists_url":"https://api.github.com/users/CMGS/gists{/gist_id}","starred_url":"https://api.github.com/users/CMGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CMGS/subscriptions","organizations_url":"https://api.github.com/users/CMGS/orgs","repos_url":"https://api.github.com/users/CMGS/repos","events_url":"https://api.github.com/users/CMGS/events{/privacy}","received_events_url":"https://api.github.com/users/CMGS/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CMGS/agent","description":"linux monitor agent","fork":true,"url":"https://api.github.com/repos/CMGS/agent","forks_url":"https://api.github.com/repos/CMGS/agent/forks","keys_url":"https://api.github.com/repos/CMGS/agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CMGS/agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CMGS/agent/teams","hooks_url":"https://api.github.com/repos/CMGS/agent/hooks","issue_events_url":"https://api.github.com/repos/CMGS/agent/issues/events{/number}","events_url":"https://api.github.com/repos/CMGS/agent/events","assignees_url":"https://api.github.com/repos/CMGS/agent/assignees{/user}","branches_url":"https://api.github.com/repos/CMGS/agent/branches{/branch}","tags_url":"https://api.github.com/repos/CMGS/agent/tags","blobs_url":"https://api.github.com/repos/CMGS/agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CMGS/agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CMGS/agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/CMGS/agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CMGS/agent/statuses/{sha}","languages_url":"https://api.github.com/repos/CMGS/agent/languages","stargazers_url":"https://api.github.com/repos/CMGS/agent/stargazers","contributors_url":"https://api.github.com/repos/CMGS/agent/contributors","subscribers_url":"https://api.github.com/repos/CMGS/agent/subscribers","subscription_url":"https://api.github.com/repos/CMGS/agent/subscription","commits_url":"https://api.github.com/repos/CMGS/agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/CMGS/agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/CMGS/agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/CMGS/agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/CMGS/agent/contents/{+path}","compare_url":"https://api.github.com/repos/CMGS/agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CMGS/agent/merges","archive_url":"https://api.github.com/repos/CMGS/agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CMGS/agent/downloads","issues_url":"https://api.github.com/repos/CMGS/agent/issues{/number}","pulls_url":"https://api.github.com/repos/CMGS/agent/pulls{/number}","milestones_url":"https://api.github.com/repos/CMGS/agent/milestones{/number}","notifications_url":"https://api.github.com/repos/CMGS/agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CMGS/agent/labels{/name}","releases_url":"https://api.github.com/repos/CMGS/agent/releases{/id}","deployments_url":"https://api.github.com/repos/CMGS/agent/deployments","created_at":"2016-01-27T09:47:28Z","updated_at":"2016-01-27T09:47:29Z","pushed_at":"2016-02-22T07:15:27Z","git_url":"git://github.com/CMGS/agent.git","ssh_url":"git@github.com:CMGS/agent.git","clone_url":"https://github.com/CMGS/agent.git","svn_url":"https://github.com/CMGS/agent","homepage":"","size":799,"stargazers_count":0,"watchers_count":0,"language":"CSS","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":0,"default_branch":"master"}},"base":{"label":"open-falcon:master","ref":"master","sha":"58445549b81a4b9dffb795687041cab5ccd86507","user":{"login":"open-falcon","id":9738246,"avatar_url":"https://avatars.githubusercontent.com/u/9738246?v=3","gravatar_id":"","url":"https://api.github.com/users/open-falcon","html_url":"https://github.com/open-falcon","followers_url":"https://api.github.com/users/open-falcon/followers","following_url":"https://api.github.com/users/open-falcon/following{/other_user}","gists_url":"https://api.github.com/users/open-falcon/gists{/gist_id}","starred_url":"https://api.github.com/users/open-falcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-falcon/subscriptions","organizations_url":"https://api.github.com/users/open-falcon/orgs","repos_url":"https://api.github.com/users/open-falcon/repos","events_url":"https://api.github.com/users/open-falcon/events{/privacy}","received_events_url":"https://api.github.com/users/open-falcon/received_events","type":"Organization","site_admin":false},"repo":{"id":27964902,"name":"agent","full_name":"open-falcon/agent","owner":{"login":"open-falcon","id":9738246,"avatar_url":"https://avatars.githubusercontent.com/u/9738246?v=3","gravatar_id":"","url":"https://api.github.com/users/open-falcon","html_url":"https://github.com/open-falcon","followers_url":"https://api.github.com/users/open-falcon/followers","following_url":"https://api.github.com/users/open-falcon/following{/other_user}","gists_url":"https://api.github.com/users/open-falcon/gists{/gist_id}","starred_url":"https://api.github.com/users/open-falcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-falcon/subscriptions","organizations_url":"https://api.github.com/users/open-falcon/orgs","repos_url":"https://api.github.com/users/open-falcon/repos","events_url":"https://api.github.com/users/open-falcon/events{/privacy}","received_events_url":"https://api.github.com/users/open-falcon/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-falcon/agent","description":"linux monitor agent","fork":false,"url":"https://api.github.com/repos/open-falcon/agent","forks_url":"https://api.github.com/repos/open-falcon/agent/forks","keys_url":"https://api.github.com/repos/open-falcon/agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-falcon/agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-falcon/agent/teams","hooks_url":"https://api.github.com/repos/open-falcon/agent/hooks","issue_events_url":"https://api.github.com/repos/open-falcon/agent/issues/events{/number}","events_url":"https://api.github.com/repos/open-falcon/agent/events","assignees_url":"https://api.github.com/repos/open-falcon/agent/assignees{/user}","branches_url":"https://api.github.com/repos/open-falcon/agent/branches{/branch}","tags_url":"https://api.github.com/repos/open-falcon/agent/tags","blobs_url":"https://api.github.com/repos/open-falcon/agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-falcon/agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-falcon/agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-falcon/agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-falcon/agent/statuses/{sha}","languages_url":"https://api.github.com/repos/open-falcon/agent/languages","stargazers_url":"https://api.github.com/repos/open-falcon/agent/stargazers","contributors_url":"https://api.github.com/repos/open-falcon/agent/contributors","subscribers_url":"https://api.github.com/repos/open-falcon/agent/subscribers","subscription_url":"https://api.github.com/repos/open-falcon/agent/subscription","commits_url":"https://api.github.com/repos/open-falcon/agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-falcon/agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-falcon/agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-falcon/agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-falcon/agent/contents/{+path}","compare_url":"https://api.github.com/repos/open-falcon/agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-falcon/agent/merges","archive_url":"https://api.github.com/repos/open-falcon/agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-falcon/agent/downloads","issues_url":"https://api.github.com/repos/open-falcon/agent/issues{/number}","pulls_url":"https://api.github.com/repos/open-falcon/agent/pulls{/number}","milestones_url":"https://api.github.com/repos/open-falcon/agent/milestones{/number}","notifications_url":"https://api.github.com/repos/open-falcon/agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-falcon/agent/labels{/name}","releases_url":"https://api.github.com/repos/open-falcon/agent/releases{/id}","deployments_url":"https://api.github.com/repos/open-falcon/agent/deployments","created_at":"2014-12-13T15:35:51Z","updated_at":"2016-02-23T00:11:27Z","pushed_at":"2016-02-22T07:16:34Z","git_url":"git://github.com/open-falcon/agent.git","ssh_url":"git@github.com:open-falcon/agent.git","clone_url":"https://github.com/open-falcon/agent.git","svn_url":"https://github.com/open-falcon/agent","homepage":"","size":847,"stargazers_count":376,"watchers_count":376,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":135,"mirror_url":null,"open_issues_count":7,"forks":135,"open_issues":7,"watchers":376,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/open-falcon/agent/pulls/37"},"html":{"href":"https://github.com/open-falcon/agent/pull/37"},"issue":{"href":"https://api.github.com/repos/open-falcon/agent/issues/37"},"comments":{"href":"https://api.github.com/repos/open-falcon/agent/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/open-falcon/agent/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/open-falcon/agent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/open-falcon/agent/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/open-falcon/agent/statuses/ecd07405e76f988b196b64f23c2e394bae720414"}}}}