{"action":"created","comment":{"url":"https://api.github.com/repos/zalando/nakadi/pulls/comments/60201685","id":60201685,"diff_hunk":"@@ -0,0 +1,150 @@\n+package de.zalando.aruha.nakadi.repository.kafka;\n+\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+import com.google.common.annotations.VisibleForTesting;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.util.Arrays;\n+import java.util.Map;\n+import java.util.NavigableMap;\n+import java.util.Objects;\n+import java.util.TreeMap;\n+import java.util.stream.Stream;\n+\n+public class KafkaPartitionsCalculator {\n+    // Contains mapping from message size (in bytes) to list of throughput of kafka with (index + 1) as partition count.\n+    private final NavigableMap<Integer, float[]> stats = new TreeMap<>();\n+\n+    private KafkaPartitionsCalculator(InstanceInfo instanceInfo) {\n+        for (SpeedStatistics ss : instanceInfo.getStats()) {\n+            stats.put(ss.getMessageSize(), ss.getSpeed());\n+        }\n+    }\n+\n+    public int getBestPartitionsCount(int messageSize, float mbsPerSecond) {\n+        final Map.Entry<Integer, float[]> floor = stats.floorEntry(messageSize);\n+        final Map.Entry<Integer, float[]> ceil = stats.ceilingEntry(messageSize);\n+        if (floor == null) {\n+            return getBestPartitionsCount(ceil.getValue(), mbsPerSecond);\n+        } else if (ceil == null) {\n+            return getBestPartitionsCount(floor.getValue(), mbsPerSecond);\n+        } else {\n+            final int floorResult = getBestPartitionsCount(floor.getValue(), mbsPerSecond);\n+            if (Objects.equals(floor.getKey(), ceil.getKey())) {\n+                return floorResult;\n+            }\n+            final int ceilResult = getBestPartitionsCount(ceil.getValue(), mbsPerSecond);\n+            return floorResult + (ceilResult - floorResult) * (messageSize - floor.getKey()) / (ceil.getKey() - floor.getKey());","path":"src/main/java/de/zalando/aruha/nakadi/repository/kafka/KafkaPartitionsCalculator.java","position":37,"original_position":37,"commit_id":"16c0de700a0052cccfc24ced3a9ef10bab4fbf06","original_commit_id":"16c0de700a0052cccfc24ced3a9ef10bab4fbf06","user":{"login":"rcillo","id":344648,"avatar_url":"https://avatars.githubusercontent.com/u/344648?v=3","gravatar_id":"","url":"https://api.github.com/users/rcillo","html_url":"https://github.com/rcillo","followers_url":"https://api.github.com/users/rcillo/followers","following_url":"https://api.github.com/users/rcillo/following{/other_user}","gists_url":"https://api.github.com/users/rcillo/gists{/gist_id}","starred_url":"https://api.github.com/users/rcillo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rcillo/subscriptions","organizations_url":"https://api.github.com/users/rcillo/orgs","repos_url":"https://api.github.com/users/rcillo/repos","events_url":"https://api.github.com/users/rcillo/events{/privacy}","received_events_url":"https://api.github.com/users/rcillo/received_events","type":"User","site_admin":false},"body":"Have you considered other rounding strategies? Do you think it would be worth checking?","created_at":"2016-04-19T09:44:14Z","updated_at":"2016-04-19T09:44:14Z","html_url":"https://github.com/zalando/nakadi/pull/217#discussion_r60201685","pull_request_url":"https://api.github.com/repos/zalando/nakadi/pulls/217","_links":{"self":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/comments/60201685"},"html":{"href":"https://github.com/zalando/nakadi/pull/217#discussion_r60201685"},"pull_request":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/217"}}},"pull_request":{"url":"https://api.github.com/repos/zalando/nakadi/pulls/217","id":66828685,"html_url":"https://github.com/zalando/nakadi/pull/217","diff_url":"https://github.com/zalando/nakadi/pull/217.diff","patch_url":"https://github.com/zalando/nakadi/pull/217.patch","issue_url":"https://api.github.com/repos/zalando/nakadi/issues/217","number":217,"state":"open","locked":false,"title":"Calculate partition count using statistics object","user":{"login":"antban","id":2656223,"avatar_url":"https://avatars.githubusercontent.com/u/2656223?v=3","gravatar_id":"","url":"https://api.github.com/users/antban","html_url":"https://github.com/antban","followers_url":"https://api.github.com/users/antban/followers","following_url":"https://api.github.com/users/antban/following{/other_user}","gists_url":"https://api.github.com/users/antban/gists{/gist_id}","starred_url":"https://api.github.com/users/antban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antban/subscriptions","organizations_url":"https://api.github.com/users/antban/orgs","repos_url":"https://api.github.com/users/antban/repos","events_url":"https://api.github.com/users/antban/events{/privacy}","received_events_url":"https://api.github.com/users/antban/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-18T10:13:37Z","updated_at":"2016-04-19T09:44:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3dc5b08fbc5ef9b3c91f9c463fec18dc93391973","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zalando/nakadi/pulls/217/commits","review_comments_url":"https://api.github.com/repos/zalando/nakadi/pulls/217/comments","review_comment_url":"https://api.github.com/repos/zalando/nakadi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando/nakadi/issues/217/comments","statuses_url":"https://api.github.com/repos/zalando/nakadi/statuses/16c0de700a0052cccfc24ced3a9ef10bab4fbf06","head":{"label":"zalando:ARUHA-117","ref":"ARUHA-117","sha":"16c0de700a0052cccfc24ced3a9ef10bab4fbf06","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":44234368,"name":"nakadi","full_name":"zalando/nakadi","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/nakadi","description":"A distributed event bus that implements a RESTful API abstraction instead of Kafka-like queues","fork":false,"url":"https://api.github.com/repos/zalando/nakadi","forks_url":"https://api.github.com/repos/zalando/nakadi/forks","keys_url":"https://api.github.com/repos/zalando/nakadi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/nakadi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/nakadi/teams","hooks_url":"https://api.github.com/repos/zalando/nakadi/hooks","issue_events_url":"https://api.github.com/repos/zalando/nakadi/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/nakadi/events","assignees_url":"https://api.github.com/repos/zalando/nakadi/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/nakadi/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/nakadi/tags","blobs_url":"https://api.github.com/repos/zalando/nakadi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/nakadi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/nakadi/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/nakadi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/nakadi/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/nakadi/languages","stargazers_url":"https://api.github.com/repos/zalando/nakadi/stargazers","contributors_url":"https://api.github.com/repos/zalando/nakadi/contributors","subscribers_url":"https://api.github.com/repos/zalando/nakadi/subscribers","subscription_url":"https://api.github.com/repos/zalando/nakadi/subscription","commits_url":"https://api.github.com/repos/zalando/nakadi/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/nakadi/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/nakadi/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/nakadi/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/nakadi/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/nakadi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/nakadi/merges","archive_url":"https://api.github.com/repos/zalando/nakadi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/nakadi/downloads","issues_url":"https://api.github.com/repos/zalando/nakadi/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/nakadi/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/nakadi/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/nakadi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/nakadi/labels{/name}","releases_url":"https://api.github.com/repos/zalando/nakadi/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/nakadi/deployments","created_at":"2015-10-14T08:30:17Z","updated_at":"2016-04-15T10:41:29Z","pushed_at":"2016-04-18T10:13:37Z","git_url":"git://github.com/zalando/nakadi.git","ssh_url":"git@github.com:zalando/nakadi.git","clone_url":"https://github.com/zalando/nakadi.git","svn_url":"https://github.com/zalando/nakadi","homepage":"","size":2138,"stargazers_count":12,"watchers_count":12,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":11,"forks":9,"open_issues":11,"watchers":12,"default_branch":"nakadi-jvm"}},"base":{"label":"zalando:nakadi-jvm","ref":"nakadi-jvm","sha":"713f9cab561eb86578cc23e30b0cff2e63153fd0","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":44234368,"name":"nakadi","full_name":"zalando/nakadi","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/nakadi","description":"A distributed event bus that implements a RESTful API abstraction instead of Kafka-like queues","fork":false,"url":"https://api.github.com/repos/zalando/nakadi","forks_url":"https://api.github.com/repos/zalando/nakadi/forks","keys_url":"https://api.github.com/repos/zalando/nakadi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/nakadi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/nakadi/teams","hooks_url":"https://api.github.com/repos/zalando/nakadi/hooks","issue_events_url":"https://api.github.com/repos/zalando/nakadi/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/nakadi/events","assignees_url":"https://api.github.com/repos/zalando/nakadi/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/nakadi/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/nakadi/tags","blobs_url":"https://api.github.com/repos/zalando/nakadi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/nakadi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/nakadi/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/nakadi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/nakadi/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/nakadi/languages","stargazers_url":"https://api.github.com/repos/zalando/nakadi/stargazers","contributors_url":"https://api.github.com/repos/zalando/nakadi/contributors","subscribers_url":"https://api.github.com/repos/zalando/nakadi/subscribers","subscription_url":"https://api.github.com/repos/zalando/nakadi/subscription","commits_url":"https://api.github.com/repos/zalando/nakadi/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/nakadi/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/nakadi/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/nakadi/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/nakadi/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/nakadi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/nakadi/merges","archive_url":"https://api.github.com/repos/zalando/nakadi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/nakadi/downloads","issues_url":"https://api.github.com/repos/zalando/nakadi/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/nakadi/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/nakadi/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/nakadi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/nakadi/labels{/name}","releases_url":"https://api.github.com/repos/zalando/nakadi/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/nakadi/deployments","created_at":"2015-10-14T08:30:17Z","updated_at":"2016-04-15T10:41:29Z","pushed_at":"2016-04-18T10:13:37Z","git_url":"git://github.com/zalando/nakadi.git","ssh_url":"git@github.com:zalando/nakadi.git","clone_url":"https://github.com/zalando/nakadi.git","svn_url":"https://github.com/zalando/nakadi","homepage":"","size":2138,"stargazers_count":12,"watchers_count":12,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":11,"forks":9,"open_issues":11,"watchers":12,"default_branch":"nakadi-jvm"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/217"},"html":{"href":"https://github.com/zalando/nakadi/pull/217"},"issue":{"href":"https://api.github.com/repos/zalando/nakadi/issues/217"},"comments":{"href":"https://api.github.com/repos/zalando/nakadi/issues/217/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/217/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando/nakadi/pulls/217/commits"},"statuses":{"href":"https://api.github.com/repos/zalando/nakadi/statuses/16c0de700a0052cccfc24ced3a9ef10bab4fbf06"}}}}