{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/47245938","id":47245938,"diff_hunk":"@@ -169,4 +178,157 @@ public void testReplicaAndPrimaryRecoveryThrottling() {\n         assertThat(routingTable.shardsWithState(INITIALIZING).size(), equalTo(0));\n         assertThat(routingTable.shardsWithState(UNASSIGNED).size(), equalTo(0));\n     }\n+\n+    public void testThrottleIncomingAndOutgoing() {\n+        Settings settings = settingsBuilder()\n+            .put(\"cluster.routing.allocation.concurrent_recoveries\", 5)\n+            .put(\"cluster.routing.allocation.node_initial_primaries_recoveries\", 5)\n+            .put(\"cluster.routing.allocation.cluster_concurrent_rebalance\", 5)\n+            .build();\n+        AllocationService strategy = createAllocationService(settings);\n+        logger.info(\"Building initial routing table\");\n+\n+        MetaData metaData = MetaData.builder()\n+            .put(IndexMetaData.builder(\"test\").settings(settings(Version.CURRENT)).numberOfShards(9).numberOfReplicas(0))\n+            .build();\n+\n+        RoutingTable routingTable = RoutingTable.builder()\n+            .addAsNew(metaData.index(\"test\"))\n+            .build();\n+\n+        ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build();\n+\n+        logger.info(\"start one node, do reroute, only 3 should initialize\");\n+        clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().put(newNode(\"node1\"))).build();\n+        routingTable = strategy.reroute(clusterState, \"reroute\").routingTable();\n+        clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();\n+        assertThat(routingTable.shardsWithState(STARTED).size(), equalTo(0));\n+        assertThat(routingTable.shardsWithState(INITIALIZING).size(), equalTo(5));\n+        assertThat(routingTable.shardsWithState(UNASSIGNED).size(), equalTo(4));\n+        assertEquals(clusterState.getRoutingNodes().getIncomingRecoveries(\"node1\"), 5);\n+\n+        logger.info(\"start initializing, all primaries should be started\");\n+        routingTable = strategy.applyStartedShards(clusterState, routingTable.shardsWithState(INITIALIZING)).routingTable();\n+        clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();\n+\n+        assertThat(routingTable.shardsWithState(STARTED).size(), equalTo(5));\n+        assertThat(routingTable.shardsWithState(INITIALIZING).size(), equalTo(4));\n+        assertThat(routingTable.shardsWithState(UNASSIGNED).size(), equalTo(0));\n+\n+        routingTable = strategy.applyStartedShards(clusterState, routingTable.shardsWithState(INITIALIZING)).routingTable();\n+        clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();\n+\n+        logger.info(\"start another node, replicas should start being allocated\");\n+        clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).put(newNode(\"node2\")).put(newNode(\"node3\"))).build();\n+        routingTable = strategy.reroute(clusterState, \"reroute\").routingTable();\n+        clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();\n+\n+        assertThat(routingTable.shardsWithState(STARTED).size(), equalTo(4));\n+        assertThat(routingTable.shardsWithState(RELOCATING).size(), equalTo(5));\n+        assertThat(routingTable.shardsWithState(INITIALIZING).size(), equalTo(5));\n+        assertThat(routingTable.shardsWithState(UNASSIGNED).size(), equalTo(0));\n+        assertEquals(clusterState.getRoutingNodes().getIncomingRecoveries(\"node2\"), 3);\n+        assertEquals(clusterState.getRoutingNodes().getIncomingRecoveries(\"node3\"), 2);\n+        assertEquals(clusterState.getRoutingNodes().getIncomingRecoveries(\"node1\"), 0);\n+        assertEquals(clusterState.getRoutingNodes().getOutgoingRecoveries(\"node1\"), 5);","path":"core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java","position":90,"original_position":90,"commit_id":"d93ff225fd7427dcb8b2885d6b61d941d3b4cb92","original_commit_id":"d93ff225fd7427dcb8b2885d6b61d941d3b4cb92","user":{"login":"dakrone","id":19060,"avatar_url":"https://avatars.githubusercontent.com/u/19060?v=3","gravatar_id":"","url":"https://api.github.com/users/dakrone","html_url":"https://github.com/dakrone","followers_url":"https://api.github.com/users/dakrone/followers","following_url":"https://api.github.com/users/dakrone/following{/other_user}","gists_url":"https://api.github.com/users/dakrone/gists{/gist_id}","starred_url":"https://api.github.com/users/dakrone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dakrone/subscriptions","organizations_url":"https://api.github.com/users/dakrone/orgs","repos_url":"https://api.github.com/users/dakrone/repos","events_url":"https://api.github.com/users/dakrone/events{/privacy}","received_events_url":"https://api.github.com/users/dakrone/received_events","type":"User","site_admin":false},"body":"Being able to assert this is really great, thanks for adding it!","created_at":"2015-12-10T16:11:51Z","updated_at":"2015-12-10T16:11:51Z","html_url":"https://github.com/elastic/elasticsearch/pull/15372#discussion_r47245938","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/47245938"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/15372#discussion_r47245938"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372","id":53273221,"html_url":"https://github.com/elastic/elasticsearch/pull/15372","diff_url":"https://github.com/elastic/elasticsearch/pull/15372.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/15372.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15372","number":15372,"state":"open","locked":false,"title":"Remove recovery threadpools and throttle outgoing recoveries on the master","user":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"body":"Today we throttle recoveries only for incoming recoveries. Nodes that have a lot\r\nof primaries can get overloaded due to too many recoveries. To still keep that at bay\r\nwe limit the number of threads that are sending files to the target to overcome this problem.\r\n\r\nThe right solution here is to also throttle the outgoing recoveries that are today unbounded on\r\nthe master and don't start the recovery until we have enough resources on both source and target nodes.\r\n\r\nThe concurrency aspects of the recovery source also added a lot of complexity and additional threadpools\r\nthat are hard to configure. This commit removes the concurrent streamns notion completely and sends files\r\nin the thread that drives the recovery simplifying the recovery code considerably.\r\nOutgoing recoveries are not throttled on the master via a allocation decider.\r\n\r\nNote: this PR is still a bit rough but all tests pass and it contains a lot of improvements. I just wanted to get a pair of eyes on it for initial feedback.","created_at":"2015-12-10T15:31:01Z","updated_at":"2015-12-10T16:11:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"34d8b577af607ecaedd3119e85416e3666f77975","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15372/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/d93ff225fd7427dcb8b2885d6b61d941d3b4cb92","head":{"label":"s1monw:trash_recovery_threads","ref":"trash_recovery_threads","sha":"d93ff225fd7427dcb8b2885d6b61d941d3b4cb92","user":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"repo":{"id":4663744,"name":"elasticsearch","full_name":"s1monw/elasticsearch","owner":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/s1monw/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/s1monw/elasticsearch","forks_url":"https://api.github.com/repos/s1monw/elasticsearch/forks","keys_url":"https://api.github.com/repos/s1monw/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/s1monw/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/s1monw/elasticsearch/teams","hooks_url":"https://api.github.com/repos/s1monw/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/s1monw/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/s1monw/elasticsearch/events","assignees_url":"https://api.github.com/repos/s1monw/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/s1monw/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/s1monw/elasticsearch/tags","blobs_url":"https://api.github.com/repos/s1monw/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/s1monw/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/s1monw/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/s1monw/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/s1monw/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/s1monw/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/s1monw/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/s1monw/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/s1monw/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/s1monw/elasticsearch/subscription","commits_url":"https://api.github.com/repos/s1monw/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/s1monw/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/s1monw/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/s1monw/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/s1monw/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/s1monw/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/s1monw/elasticsearch/merges","archive_url":"https://api.github.com/repos/s1monw/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/s1monw/elasticsearch/downloads","issues_url":"https://api.github.com/repos/s1monw/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/s1monw/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/s1monw/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/s1monw/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/s1monw/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/s1monw/elasticsearch/releases{/id}","created_at":"2012-06-14T13:44:13Z","updated_at":"2015-05-07T08:25:29Z","pushed_at":"2015-12-10T15:29:30Z","git_url":"git://github.com/s1monw/elasticsearch.git","ssh_url":"git@github.com:s1monw/elasticsearch.git","clone_url":"https://github.com/s1monw/elasticsearch.git","svn_url":"https://github.com/s1monw/elasticsearch","homepage":"http://elasticsearch.org","size":182453,"stargazers_count":1,"watchers_count":1,"language":"Java","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":1,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"09053f5c8776ef49a088a22f2c469d08c8f1954b","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-12-10T15:55:56Z","pushed_at":"2015-12-10T16:09:01Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":227713,"stargazers_count":13949,"watchers_count":13949,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4627,"mirror_url":null,"open_issues_count":1203,"forks":4627,"open_issues":1203,"watchers":13949,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/15372"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/15372"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/15372/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15372/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/d93ff225fd7427dcb8b2885d6b61d941d3b4cb92"}}}}