{"action":"created","comment":{"url":"https://api.github.com/repos/uber/tchannel/pulls/comments/33372960","id":33372960,"diff_hunk":"@@ -0,0 +1,91 @@\n+// Copyright (c) 2015 Uber Technologies, Inc.\n+\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the \"Software\"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in\n+// all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+// THE SOFTWARE.\n+\n+'use strict';\n+\n+var inherits = require('util').inherits;\n+var EventEmitter = require('../../lib/event_emitter.js');\n+\n+module.exports = FakeEgressNodes;\n+\n+// e.g., topology = {'alice': ['127.0.0.1:4040'], 'bob': ['127.0.0.1:4041']}, '127.0.0.1:4040'\n+function FakeEgressNodes(options) {\n+    if (!(this instanceof FakeEgressNodes)) {\n+        return new FakeEgressNodes(options);\n+    }\n+\n+    var self = this;\n+\n+    EventEmitter.call(self);\n+\n+    self.hostPort = options.hostPort;\n+\n+    // Everyone must mutate this\n+    self.topology = options.topology;\n+    self.kValue = options.kValue;\n+    self.relayChannels = options.relayChannels;\n+\n+    self.membershipChangedEvent = self.defineEvent('membershipChanged');\n+}\n+\n+inherits(FakeEgressNodes, EventEmitter);\n+\n+FakeEgressNodes.prototype.isExitFor = function isExitFor(serviceName) {\n+    var self = this;\n+\n+    return self.topology[serviceName].indexOf(self.hostPort) >= 0;\n+};\n+\n+FakeEgressNodes.prototype.getRandomNodes =\n+function getRandomNodes(serviceName) {\n+    var self = this;\n+\n+    var hosts = [];\n+\n+    for (var i = 0; i < self.kValue; i++) {","path":"node/test/lib/fake-egress-nodes.js","position":62,"original_position":62,"commit_id":"abe92d748d7b548259da3d72fe0c1c1aefc883ca","original_commit_id":"abe92d748d7b548259da3d72fe0c1c1aefc883ca","user":{"login":"jcorbin","id":49715,"avatar_url":"https://avatars.githubusercontent.com/u/49715?v=3","gravatar_id":"","url":"https://api.github.com/users/jcorbin","html_url":"https://github.com/jcorbin","followers_url":"https://api.github.com/users/jcorbin/followers","following_url":"https://api.github.com/users/jcorbin/following{/other_user}","gists_url":"https://api.github.com/users/jcorbin/gists{/gist_id}","starred_url":"https://api.github.com/users/jcorbin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcorbin/subscriptions","organizations_url":"https://api.github.com/users/jcorbin/orgs","repos_url":"https://api.github.com/users/jcorbin/repos","events_url":"https://api.github.com/users/jcorbin/events{/privacy}","received_events_url":"https://api.github.com/users/jcorbin/received_events","type":"User","site_admin":false},"body":"Not actually a good random sampler, but doesn't matter #justsayin.\r\n\r\nHow to do it right: select the top-k randomly chosen scores, e.g. this one-liner in Python:\r\n```\r\n[\r\n    letter\r\n    for score, letter in heapq.nlargest(10, (\r\n        (random.random(), letter)\r\n        for letter in string.ascii_letters))\r\n]\r\n```\r\n\r\nI.e.:\r\n- get you a min heap implementation\r\n- iterate your input array, for each item\r\n  - compute a random score\r\n  - if heap is under k in size, push score and item\r\n  - else if score is greater than head of heap, replace and sift down\r\n- strip the scores off and return just the items out of your heap","created_at":"2015-06-26T16:43:35Z","updated_at":"2015-06-26T16:43:35Z","html_url":"https://github.com/uber/tchannel/pull/798#discussion_r33372960","pull_request_url":"https://api.github.com/repos/uber/tchannel/pulls/798","_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel/pulls/comments/33372960"},"html":{"href":"https://github.com/uber/tchannel/pull/798#discussion_r33372960"},"pull_request":{"href":"https://api.github.com/repos/uber/tchannel/pulls/798"}}},"pull_request":{"url":"https://api.github.com/repos/uber/tchannel/pulls/798","id":38618629,"html_url":"https://github.com/uber/tchannel/pull/798","diff_url":"https://github.com/uber/tchannel/pull/798.diff","patch_url":"https://github.com/uber/tchannel/pull/798.patch","issue_url":"https://api.github.com/repos/uber/tchannel/issues/798","number":798,"state":"open","locked":false,"title":"Realistic benchmark","user":{"login":"Raynos","id":479538,"avatar_url":"https://avatars.githubusercontent.com/u/479538?v=3","gravatar_id":"","url":"https://api.github.com/users/Raynos","html_url":"https://github.com/Raynos","followers_url":"https://api.github.com/users/Raynos/followers","following_url":"https://api.github.com/users/Raynos/following{/other_user}","gists_url":"https://api.github.com/users/Raynos/gists{/gist_id}","starred_url":"https://api.github.com/users/Raynos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raynos/subscriptions","organizations_url":"https://api.github.com/users/Raynos/orgs","repos_url":"https://api.github.com/users/Raynos/repos","events_url":"https://api.github.com/users/Raynos/events{/privacy}","received_events_url":"https://api.github.com/users/Raynos/received_events","type":"User","site_admin":false},"body":"I \"fixed\" the benchmark to make it realistic. This means the benchmarks uses the logical retryable requests. It also uses stats and other things that were being skipped.\r\n\r\nI also added two more modes to it\r\n\r\n - `benchmarks/take_relay.sh`\r\n - `benchmarks/take_trace.sh`\r\n\r\nThese two spawn extra processes to test the relaying and tracing features of hyperbahn.\r\n\r\nr: @rf @jcorbin ","created_at":"2015-06-26T05:33:21Z","updated_at":"2015-06-26T16:43:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f23a95b73c1f8247b2e5447226eb63774725c3aa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/uber/tchannel/pulls/798/commits","review_comments_url":"https://api.github.com/repos/uber/tchannel/pulls/798/comments","review_comment_url":"https://api.github.com/repos/uber/tchannel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/tchannel/issues/798/comments","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/abe92d748d7b548259da3d72fe0c1c1aefc883ca","head":{"label":"uber:realistic-benchmark","ref":"realistic-benchmark","sha":"abe92d748d7b548259da3d72fe0c1c1aefc883ca","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":28419663,"name":"tchannel","full_name":"uber/tchannel","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel","description":"network multiplexing and framing protocol for RPC","fork":false,"url":"https://api.github.com/repos/uber/tchannel","forks_url":"https://api.github.com/repos/uber/tchannel/forks","keys_url":"https://api.github.com/repos/uber/tchannel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel/teams","hooks_url":"https://api.github.com/repos/uber/tchannel/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel/events","assignees_url":"https://api.github.com/repos/uber/tchannel/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel/tags","blobs_url":"https://api.github.com/repos/uber/tchannel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel/subscription","commits_url":"https://api.github.com/repos/uber/tchannel/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel/merges","archive_url":"https://api.github.com/repos/uber/tchannel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel/downloads","issues_url":"https://api.github.com/repos/uber/tchannel/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel/releases{/id}","created_at":"2014-12-23T21:06:57Z","updated_at":"2015-06-24T06:11:40Z","pushed_at":"2015-06-26T08:28:44Z","git_url":"git://github.com/uber/tchannel.git","ssh_url":"git@github.com:uber/tchannel.git","clone_url":"https://github.com/uber/tchannel.git","svn_url":"https://github.com/uber/tchannel","homepage":"","size":15021,"stargazers_count":78,"watchers_count":78,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":47,"forks":6,"open_issues":47,"watchers":78,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"aca415e1546e2ecba5ef43177519bbdc3e27ef27","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":28419663,"name":"tchannel","full_name":"uber/tchannel","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel","description":"network multiplexing and framing protocol for RPC","fork":false,"url":"https://api.github.com/repos/uber/tchannel","forks_url":"https://api.github.com/repos/uber/tchannel/forks","keys_url":"https://api.github.com/repos/uber/tchannel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel/teams","hooks_url":"https://api.github.com/repos/uber/tchannel/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel/events","assignees_url":"https://api.github.com/repos/uber/tchannel/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel/tags","blobs_url":"https://api.github.com/repos/uber/tchannel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel/subscription","commits_url":"https://api.github.com/repos/uber/tchannel/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel/merges","archive_url":"https://api.github.com/repos/uber/tchannel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel/downloads","issues_url":"https://api.github.com/repos/uber/tchannel/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel/releases{/id}","created_at":"2014-12-23T21:06:57Z","updated_at":"2015-06-24T06:11:40Z","pushed_at":"2015-06-26T08:28:44Z","git_url":"git://github.com/uber/tchannel.git","ssh_url":"git@github.com:uber/tchannel.git","clone_url":"https://github.com/uber/tchannel.git","svn_url":"https://github.com/uber/tchannel","homepage":"","size":15021,"stargazers_count":78,"watchers_count":78,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":47,"forks":6,"open_issues":47,"watchers":78,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel/pulls/798"},"html":{"href":"https://github.com/uber/tchannel/pull/798"},"issue":{"href":"https://api.github.com/repos/uber/tchannel/issues/798"},"comments":{"href":"https://api.github.com/repos/uber/tchannel/issues/798/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/tchannel/pulls/798/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/tchannel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/tchannel/pulls/798/commits"},"statuses":{"href":"https://api.github.com/repos/uber/tchannel/statuses/abe92d748d7b548259da3d72fe0c1c1aefc883ca"}}}}