{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/31858064","id":31858064,"diff_hunk":"@@ -271,27 +272,64 @@ class ReceiverTracker(ssc: StreamingContext, skipReceiverLaunch: Boolean = false\n     }\n \n     /**\n-     * Get the receivers from the ReceiverInputDStreams, distributes them to the\n-     * worker nodes as a parallel collection, and runs them.\n+     * Get the list of executors excluding driver\n      */\n-    private def startReceivers() {\n-      val receivers = receiverInputStreams.map(nis => {\n-        val rcvr = nis.getReceiver()\n-        rcvr.setReceiverId(nis.id)\n-        rcvr\n-      })\n+    private def getExecutors(ssc: StreamingContext): List[String] = {\n+      val executors = ssc.sparkContext.getExecutorMemoryStatus.map(_._1.split(\":\")(0)).toList\n+      val driver = ssc.sparkContext.getConf.get(\"spark.driver.host\")\n+      executors.diff(List(driver))\n+    }\n \n-      // Right now, we only honor preferences if all receivers have them\n+    /* Schedule receivers using preferredLocation if specified\n+     * and round-robin otherwise\n+     */\n+    private def scheduleReceivers(receivers: Seq[Receiver[_]]): RDD[Receiver[_]] = {\n+      // Location preferences are honored if all receivers have them\n       val hasLocationPreferences = receivers.map(_.preferredLocation.isDefined).reduce(_ && _)\n \n-      // Create the parallel collection of receivers to distributed them on the worker nodes\n+      // If no location preferences are specified, set host location for each receiver\n+      // so as to distribute them evenly over executors in a round-robin fashion\n+      // If num_executors > num_receivers, distribute executors among receivers\n+      val locations = new Array[ArrayBuffer[String]](receivers.length)\n+      if (!hasLocationPreferences && !ssc.sparkContext.isLocal) {\n+        val executors = getExecutors(ssc)\n+        var i = 0\n+        for (i <- 0 to (receivers.length - 1)) {\n+          locations(i) = new ArrayBuffer[String]()\n+        }\n+        if (receivers.length >= executors.length) {","path":"streaming/src/main/scala/org/apache/spark/streaming/scheduler/ReceiverTracker.scala","position":null,"original_position":50,"commit_id":"4cf97b66efca1a9a97f7382fa11123de92faab98","original_commit_id":"6caeefe8b7047ab6c62dbfcab3be4b53203c13c4","user":{"login":"harishreedharan","id":1481194,"avatar_url":"https://avatars.githubusercontent.com/u/1481194?v=3","gravatar_id":"","url":"https://api.github.com/users/harishreedharan","html_url":"https://github.com/harishreedharan","followers_url":"https://api.github.com/users/harishreedharan/followers","following_url":"https://api.github.com/users/harishreedharan/following{/other_user}","gists_url":"https://api.github.com/users/harishreedharan/gists{/gist_id}","starred_url":"https://api.github.com/users/harishreedharan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harishreedharan/subscriptions","organizations_url":"https://api.github.com/users/harishreedharan/orgs","repos_url":"https://api.github.com/users/harishreedharan/repos","events_url":"https://api.github.com/users/harishreedharan/events{/privacy}","received_events_url":"https://api.github.com/users/harishreedharan/received_events","type":"User","site_admin":false},"body":"Probably not, but this code is a lot more intuitive (it is a bit more verbose, yes). In fact, this code can be refactored and you can just switch the order of buffers you are calling - though that would make the code less readable.\r\n\r\n","created_at":"2015-06-05T22:49:41Z","updated_at":"2015-06-05T22:49:41Z","html_url":"https://github.com/apache/spark/pull/6607#discussion_r31858064","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6607","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/31858064"},"html":{"href":"https://github.com/apache/spark/pull/6607#discussion_r31858064"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6607"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6607","id":36806027,"html_url":"https://github.com/apache/spark/pull/6607","diff_url":"https://github.com/apache/spark/pull/6607.diff","patch_url":"https://github.com/apache/spark/pull/6607.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6607","number":6607,"state":"open","locked":false,"title":"[SPARK-7988][STREAMING] Round-robin scheduling of receivers by default","user":{"login":"nishkamravi2","id":7054820,"avatar_url":"https://avatars.githubusercontent.com/u/7054820?v=3","gravatar_id":"","url":"https://api.github.com/users/nishkamravi2","html_url":"https://github.com/nishkamravi2","followers_url":"https://api.github.com/users/nishkamravi2/followers","following_url":"https://api.github.com/users/nishkamravi2/following{/other_user}","gists_url":"https://api.github.com/users/nishkamravi2/gists{/gist_id}","starred_url":"https://api.github.com/users/nishkamravi2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishkamravi2/subscriptions","organizations_url":"https://api.github.com/users/nishkamravi2/orgs","repos_url":"https://api.github.com/users/nishkamravi2/repos","events_url":"https://api.github.com/users/nishkamravi2/events{/privacy}","received_events_url":"https://api.github.com/users/nishkamravi2/received_events","type":"User","site_admin":false},"body":"Minimal PR for round-robin scheduling of receivers. Dense scheduling can be enabled by setting preferredLocation, so a new config parameter isn't really needed. Tested this on a cluster of 6 nodes and noticed 20-25% gain in throughput compared to random scheduling. \r\n\r\n@tdas @pwendell ","created_at":"2015-06-03T07:45:23Z","updated_at":"2015-06-05T22:49:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4979c1d036eb2bfeae65f000ca4a391c0737fa0b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6607/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6607/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6607/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/4cf97b66efca1a9a97f7382fa11123de92faab98","head":{"label":"nishkamravi2:master_nravi","ref":"master_nravi","sha":"4cf97b66efca1a9a97f7382fa11123de92faab98","user":{"login":"nishkamravi2","id":7054820,"avatar_url":"https://avatars.githubusercontent.com/u/7054820?v=3","gravatar_id":"","url":"https://api.github.com/users/nishkamravi2","html_url":"https://github.com/nishkamravi2","followers_url":"https://api.github.com/users/nishkamravi2/followers","following_url":"https://api.github.com/users/nishkamravi2/following{/other_user}","gists_url":"https://api.github.com/users/nishkamravi2/gists{/gist_id}","starred_url":"https://api.github.com/users/nishkamravi2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishkamravi2/subscriptions","organizations_url":"https://api.github.com/users/nishkamravi2/orgs","repos_url":"https://api.github.com/users/nishkamravi2/repos","events_url":"https://api.github.com/users/nishkamravi2/events{/privacy}","received_events_url":"https://api.github.com/users/nishkamravi2/received_events","type":"User","site_admin":false},"repo":{"id":36787296,"name":"spark","full_name":"nishkamravi2/spark","owner":{"login":"nishkamravi2","id":7054820,"avatar_url":"https://avatars.githubusercontent.com/u/7054820?v=3","gravatar_id":"","url":"https://api.github.com/users/nishkamravi2","html_url":"https://github.com/nishkamravi2","followers_url":"https://api.github.com/users/nishkamravi2/followers","following_url":"https://api.github.com/users/nishkamravi2/following{/other_user}","gists_url":"https://api.github.com/users/nishkamravi2/gists{/gist_id}","starred_url":"https://api.github.com/users/nishkamravi2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishkamravi2/subscriptions","organizations_url":"https://api.github.com/users/nishkamravi2/orgs","repos_url":"https://api.github.com/users/nishkamravi2/repos","events_url":"https://api.github.com/users/nishkamravi2/events{/privacy}","received_events_url":"https://api.github.com/users/nishkamravi2/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nishkamravi2/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/nishkamravi2/spark","forks_url":"https://api.github.com/repos/nishkamravi2/spark/forks","keys_url":"https://api.github.com/repos/nishkamravi2/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nishkamravi2/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nishkamravi2/spark/teams","hooks_url":"https://api.github.com/repos/nishkamravi2/spark/hooks","issue_events_url":"https://api.github.com/repos/nishkamravi2/spark/issues/events{/number}","events_url":"https://api.github.com/repos/nishkamravi2/spark/events","assignees_url":"https://api.github.com/repos/nishkamravi2/spark/assignees{/user}","branches_url":"https://api.github.com/repos/nishkamravi2/spark/branches{/branch}","tags_url":"https://api.github.com/repos/nishkamravi2/spark/tags","blobs_url":"https://api.github.com/repos/nishkamravi2/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nishkamravi2/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nishkamravi2/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/nishkamravi2/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nishkamravi2/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/nishkamravi2/spark/languages","stargazers_url":"https://api.github.com/repos/nishkamravi2/spark/stargazers","contributors_url":"https://api.github.com/repos/nishkamravi2/spark/contributors","subscribers_url":"https://api.github.com/repos/nishkamravi2/spark/subscribers","subscription_url":"https://api.github.com/repos/nishkamravi2/spark/subscription","commits_url":"https://api.github.com/repos/nishkamravi2/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/nishkamravi2/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/nishkamravi2/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/nishkamravi2/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/nishkamravi2/spark/contents/{+path}","compare_url":"https://api.github.com/repos/nishkamravi2/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nishkamravi2/spark/merges","archive_url":"https://api.github.com/repos/nishkamravi2/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nishkamravi2/spark/downloads","issues_url":"https://api.github.com/repos/nishkamravi2/spark/issues{/number}","pulls_url":"https://api.github.com/repos/nishkamravi2/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/nishkamravi2/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/nishkamravi2/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nishkamravi2/spark/labels{/name}","releases_url":"https://api.github.com/repos/nishkamravi2/spark/releases{/id}","created_at":"2015-06-03T07:30:26Z","updated_at":"2015-06-03T07:30:48Z","pushed_at":"2015-06-05T22:39:19Z","git_url":"git://github.com/nishkamravi2/spark.git","ssh_url":"git@github.com:nishkamravi2/spark.git","clone_url":"https://github.com/nishkamravi2/spark.git","svn_url":"https://github.com/nishkamravi2/spark","homepage":null,"size":107398,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"ce320cb2dbf28825f80795ce569735888f98d6e8","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-06-05T22:09:16Z","pushed_at":"2015-06-05T22:45:29Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1443859,"stargazers_count":4238,"watchers_count":4238,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3719,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":341,"forks":3719,"open_issues":341,"watchers":4238,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6607"},"html":{"href":"https://github.com/apache/spark/pull/6607"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6607"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6607/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6607/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6607/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/4cf97b66efca1a9a97f7382fa11123de92faab98"}}}}