{"action":"created","comment":{"url":"https://api.github.com/repos/linkedin/ambry/pulls/comments/78651695","id":78651695,"diff_hunk":"@@ -120,35 +137,39 @@ protected int sizeExcludingBlobSize() {\n   @Override\n   public long writeTo(WritableByteChannel channel)\n       throws IOException {\n-    long totalWritten = 0;\n-    if (bufferToSend == null) {\n-      bufferToSend = ByteBuffer.allocate(sizeExcludingBlobSize());\n-      writeHeader();\n-      bufferToSend.put(blobId.toBytes());\n-      BlobPropertiesSerDe.putBlobPropertiesToBuffer(bufferToSend, properties);\n-      bufferToSend.putInt(usermetadata.capacity());\n-      bufferToSend.put(usermetadata);\n-      bufferToSend.putShort((short) blobType.ordinal());\n-      bufferToSend.putLong(blobSize);\n-      bufferToSend.flip();\n+    if (materializedBlobBuffer == null) {\n+      // This PutRequest was constructed from a stream and cannot be written out.\n+      throw new IllegalStateException(\"Attempt to write out a PutRequest that cannot be written out.\");\n     }\n-    while (sentBytes < sizeInBytes()) {\n-      if (bufferToSend.remaining() > 0) {\n-        int toWrite = bufferToSend.remaining();\n-        int written = channel.write(bufferToSend);\n-        totalWritten += written;\n-        sentBytes += written;\n-        if (toWrite != written || sentBytes == sizeInBytes()) {\n-          break;\n-        }\n+    long written = 0;\n+    if (sentBytes < sizeInBytes()) {","path":"ambry-protocol/src/main/java/com.github.ambry.protocol/PutRequest.java","position":118,"original_position":118,"commit_id":"aa6c2db1b6db42e44531f7edb5e78d32195dc3d4","original_commit_id":"aa6c2db1b6db42e44531f7edb5e78d32195dc3d4","user":{"login":"xiahome","id":8271368,"avatar_url":"https://avatars.githubusercontent.com/u/8271368?v=3","gravatar_id":"","url":"https://api.github.com/users/xiahome","html_url":"https://github.com/xiahome","followers_url":"https://api.github.com/users/xiahome/followers","following_url":"https://api.github.com/users/xiahome/following{/other_user}","gists_url":"https://api.github.com/users/xiahome/gists{/gist_id}","starred_url":"https://api.github.com/users/xiahome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiahome/subscriptions","organizations_url":"https://api.github.com/users/xiahome/orgs","repos_url":"https://api.github.com/users/xiahome/repos","events_url":"https://api.github.com/users/xiahome/events{/privacy}","received_events_url":"https://api.github.com/users/xiahome/received_events","type":"User","site_admin":false},"body":"Would it be an overhead to calculate sizeInBytes() for every call?","created_at":"2016-09-13T21:52:46Z","updated_at":"2016-09-13T21:52:46Z","html_url":"https://github.com/linkedin/ambry/pull/445#discussion_r78651695","pull_request_url":"https://api.github.com/repos/linkedin/ambry/pulls/445","_links":{"self":{"href":"https://api.github.com/repos/linkedin/ambry/pulls/comments/78651695"},"html":{"href":"https://github.com/linkedin/ambry/pull/445#discussion_r78651695"},"pull_request":{"href":"https://api.github.com/repos/linkedin/ambry/pulls/445"}}},"pull_request":{"url":"https://api.github.com/repos/linkedin/ambry/pulls/445","id":85105899,"html_url":"https://github.com/linkedin/ambry/pull/445","diff_url":"https://github.com/linkedin/ambry/pull/445.diff","patch_url":"https://github.com/linkedin/ambry/pull/445.patch","issue_url":"https://api.github.com/repos/linkedin/ambry/issues/445","number":445,"state":"open","locked":false,"title":"Write out put requests efficiently","user":{"login":"pnarayanan","id":1454915,"avatar_url":"https://avatars.githubusercontent.com/u/1454915?v=3","gravatar_id":"","url":"https://api.github.com/users/pnarayanan","html_url":"https://github.com/pnarayanan","followers_url":"https://api.github.com/users/pnarayanan/followers","following_url":"https://api.github.com/users/pnarayanan/following{/other_user}","gists_url":"https://api.github.com/users/pnarayanan/gists{/gist_id}","starred_url":"https://api.github.com/users/pnarayanan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnarayanan/subscriptions","organizations_url":"https://api.github.com/users/pnarayanan/orgs","repos_url":"https://api.github.com/users/pnarayanan/repos","events_url":"https://api.github.com/users/pnarayanan/events{/privacy}","received_events_url":"https://api.github.com/users/pnarayanan/received_events","type":"User","site_admin":false},"body":"Put Requests are written out inefficiently today - by creating a buffer\r\nthat is only large enough to hold the request header, blob properties and\r\nuser metadata and then reusing the same buffer to read in the blob data\r\npart by part from the InputStream and writing it out iteratively.\r\nThis is particularly inefficient now, as the router uses a selector and all\r\nPutRequests get written out iteratively. This is also unnecessary now as\r\nthe data is already available in a ByteBuffer, so it can be written out\r\nefficiently without any extra memory allocations.\r\n\r\nConsiderable latency improvements were seen in perf tests with this change.\r\n\r\n--\r\n\r\nExisting tests cover the new change. Added a missing scenario where `PutRequest::writeTo()` is not always given a channel that can take in all the content at once.","created_at":"2016-09-13T19:01:39Z","updated_at":"2016-09-13T21:52:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58d6e9fb9f232bfa340b4eeb64034b76293ddbe3","assignee":{"login":"vgkholla","id":288834,"avatar_url":"https://avatars.githubusercontent.com/u/288834?v=3","gravatar_id":"","url":"https://api.github.com/users/vgkholla","html_url":"https://github.com/vgkholla","followers_url":"https://api.github.com/users/vgkholla/followers","following_url":"https://api.github.com/users/vgkholla/following{/other_user}","gists_url":"https://api.github.com/users/vgkholla/gists{/gist_id}","starred_url":"https://api.github.com/users/vgkholla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vgkholla/subscriptions","organizations_url":"https://api.github.com/users/vgkholla/orgs","repos_url":"https://api.github.com/users/vgkholla/repos","events_url":"https://api.github.com/users/vgkholla/events{/privacy}","received_events_url":"https://api.github.com/users/vgkholla/received_events","type":"User","site_admin":false},"assignees":[{"login":"vgkholla","id":288834,"avatar_url":"https://avatars.githubusercontent.com/u/288834?v=3","gravatar_id":"","url":"https://api.github.com/users/vgkholla","html_url":"https://github.com/vgkholla","followers_url":"https://api.github.com/users/vgkholla/followers","following_url":"https://api.github.com/users/vgkholla/following{/other_user}","gists_url":"https://api.github.com/users/vgkholla/gists{/gist_id}","starred_url":"https://api.github.com/users/vgkholla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vgkholla/subscriptions","organizations_url":"https://api.github.com/users/vgkholla/orgs","repos_url":"https://api.github.com/users/vgkholla/repos","events_url":"https://api.github.com/users/vgkholla/events{/privacy}","received_events_url":"https://api.github.com/users/vgkholla/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/linkedin/ambry/pulls/445/commits","review_comments_url":"https://api.github.com/repos/linkedin/ambry/pulls/445/comments","review_comment_url":"https://api.github.com/repos/linkedin/ambry/pulls/comments{/number}","comments_url":"https://api.github.com/repos/linkedin/ambry/issues/445/comments","statuses_url":"https://api.github.com/repos/linkedin/ambry/statuses/aa6c2db1b6db42e44531f7edb5e78d32195dc3d4","head":{"label":"pnarayanan:PutRequestImprovement","ref":"PutRequestImprovement","sha":"aa6c2db1b6db42e44531f7edb5e78d32195dc3d4","user":{"login":"pnarayanan","id":1454915,"avatar_url":"https://avatars.githubusercontent.com/u/1454915?v=3","gravatar_id":"","url":"https://api.github.com/users/pnarayanan","html_url":"https://github.com/pnarayanan","followers_url":"https://api.github.com/users/pnarayanan/followers","following_url":"https://api.github.com/users/pnarayanan/following{/other_user}","gists_url":"https://api.github.com/users/pnarayanan/gists{/gist_id}","starred_url":"https://api.github.com/users/pnarayanan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnarayanan/subscriptions","organizations_url":"https://api.github.com/users/pnarayanan/orgs","repos_url":"https://api.github.com/users/pnarayanan/repos","events_url":"https://api.github.com/users/pnarayanan/events{/privacy}","received_events_url":"https://api.github.com/users/pnarayanan/received_events","type":"User","site_admin":false},"repo":{"id":25383889,"name":"ambry","full_name":"pnarayanan/ambry","owner":{"login":"pnarayanan","id":1454915,"avatar_url":"https://avatars.githubusercontent.com/u/1454915?v=3","gravatar_id":"","url":"https://api.github.com/users/pnarayanan","html_url":"https://github.com/pnarayanan","followers_url":"https://api.github.com/users/pnarayanan/followers","following_url":"https://api.github.com/users/pnarayanan/following{/other_user}","gists_url":"https://api.github.com/users/pnarayanan/gists{/gist_id}","starred_url":"https://api.github.com/users/pnarayanan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnarayanan/subscriptions","organizations_url":"https://api.github.com/users/pnarayanan/orgs","repos_url":"https://api.github.com/users/pnarayanan/repos","events_url":"https://api.github.com/users/pnarayanan/events{/privacy}","received_events_url":"https://api.github.com/users/pnarayanan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pnarayanan/ambry","description":"Immutable blob store","fork":true,"url":"https://api.github.com/repos/pnarayanan/ambry","forks_url":"https://api.github.com/repos/pnarayanan/ambry/forks","keys_url":"https://api.github.com/repos/pnarayanan/ambry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pnarayanan/ambry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pnarayanan/ambry/teams","hooks_url":"https://api.github.com/repos/pnarayanan/ambry/hooks","issue_events_url":"https://api.github.com/repos/pnarayanan/ambry/issues/events{/number}","events_url":"https://api.github.com/repos/pnarayanan/ambry/events","assignees_url":"https://api.github.com/repos/pnarayanan/ambry/assignees{/user}","branches_url":"https://api.github.com/repos/pnarayanan/ambry/branches{/branch}","tags_url":"https://api.github.com/repos/pnarayanan/ambry/tags","blobs_url":"https://api.github.com/repos/pnarayanan/ambry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pnarayanan/ambry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pnarayanan/ambry/git/refs{/sha}","trees_url":"https://api.github.com/repos/pnarayanan/ambry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pnarayanan/ambry/statuses/{sha}","languages_url":"https://api.github.com/repos/pnarayanan/ambry/languages","stargazers_url":"https://api.github.com/repos/pnarayanan/ambry/stargazers","contributors_url":"https://api.github.com/repos/pnarayanan/ambry/contributors","subscribers_url":"https://api.github.com/repos/pnarayanan/ambry/subscribers","subscription_url":"https://api.github.com/repos/pnarayanan/ambry/subscription","commits_url":"https://api.github.com/repos/pnarayanan/ambry/commits{/sha}","git_commits_url":"https://api.github.com/repos/pnarayanan/ambry/git/commits{/sha}","comments_url":"https://api.github.com/repos/pnarayanan/ambry/comments{/number}","issue_comment_url":"https://api.github.com/repos/pnarayanan/ambry/issues/comments{/number}","contents_url":"https://api.github.com/repos/pnarayanan/ambry/contents/{+path}","compare_url":"https://api.github.com/repos/pnarayanan/ambry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pnarayanan/ambry/merges","archive_url":"https://api.github.com/repos/pnarayanan/ambry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pnarayanan/ambry/downloads","issues_url":"https://api.github.com/repos/pnarayanan/ambry/issues{/number}","pulls_url":"https://api.github.com/repos/pnarayanan/ambry/pulls{/number}","milestones_url":"https://api.github.com/repos/pnarayanan/ambry/milestones{/number}","notifications_url":"https://api.github.com/repos/pnarayanan/ambry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pnarayanan/ambry/labels{/name}","releases_url":"https://api.github.com/repos/pnarayanan/ambry/releases{/id}","deployments_url":"https://api.github.com/repos/pnarayanan/ambry/deployments","created_at":"2014-10-18T01:44:12Z","updated_at":"2016-05-03T23:43:02Z","pushed_at":"2016-09-13T19:00:46Z","git_url":"git://github.com/pnarayanan/ambry.git","ssh_url":"git@github.com:pnarayanan/ambry.git","clone_url":"https://github.com/pnarayanan/ambry.git","svn_url":"https://github.com/pnarayanan/ambry","homepage":null,"size":7238,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"linkedin:master","ref":"master","sha":"0f2e54c494960ee2eccd3033e19cae88386f6b67","user":{"login":"linkedin","id":357098,"avatar_url":"https://avatars.githubusercontent.com/u/357098?v=3","gravatar_id":"","url":"https://api.github.com/users/linkedin","html_url":"https://github.com/linkedin","followers_url":"https://api.github.com/users/linkedin/followers","following_url":"https://api.github.com/users/linkedin/following{/other_user}","gists_url":"https://api.github.com/users/linkedin/gists{/gist_id}","starred_url":"https://api.github.com/users/linkedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linkedin/subscriptions","organizations_url":"https://api.github.com/users/linkedin/orgs","repos_url":"https://api.github.com/users/linkedin/repos","events_url":"https://api.github.com/users/linkedin/events{/privacy}","received_events_url":"https://api.github.com/users/linkedin/received_events","type":"Organization","site_admin":false},"repo":{"id":13870893,"name":"ambry","full_name":"linkedin/ambry","owner":{"login":"linkedin","id":357098,"avatar_url":"https://avatars.githubusercontent.com/u/357098?v=3","gravatar_id":"","url":"https://api.github.com/users/linkedin","html_url":"https://github.com/linkedin","followers_url":"https://api.github.com/users/linkedin/followers","following_url":"https://api.github.com/users/linkedin/following{/other_user}","gists_url":"https://api.github.com/users/linkedin/gists{/gist_id}","starred_url":"https://api.github.com/users/linkedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linkedin/subscriptions","organizations_url":"https://api.github.com/users/linkedin/orgs","repos_url":"https://api.github.com/users/linkedin/repos","events_url":"https://api.github.com/users/linkedin/events{/privacy}","received_events_url":"https://api.github.com/users/linkedin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/linkedin/ambry","description":"Distributed object store","fork":false,"url":"https://api.github.com/repos/linkedin/ambry","forks_url":"https://api.github.com/repos/linkedin/ambry/forks","keys_url":"https://api.github.com/repos/linkedin/ambry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/linkedin/ambry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/linkedin/ambry/teams","hooks_url":"https://api.github.com/repos/linkedin/ambry/hooks","issue_events_url":"https://api.github.com/repos/linkedin/ambry/issues/events{/number}","events_url":"https://api.github.com/repos/linkedin/ambry/events","assignees_url":"https://api.github.com/repos/linkedin/ambry/assignees{/user}","branches_url":"https://api.github.com/repos/linkedin/ambry/branches{/branch}","tags_url":"https://api.github.com/repos/linkedin/ambry/tags","blobs_url":"https://api.github.com/repos/linkedin/ambry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/linkedin/ambry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/linkedin/ambry/git/refs{/sha}","trees_url":"https://api.github.com/repos/linkedin/ambry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/linkedin/ambry/statuses/{sha}","languages_url":"https://api.github.com/repos/linkedin/ambry/languages","stargazers_url":"https://api.github.com/repos/linkedin/ambry/stargazers","contributors_url":"https://api.github.com/repos/linkedin/ambry/contributors","subscribers_url":"https://api.github.com/repos/linkedin/ambry/subscribers","subscription_url":"https://api.github.com/repos/linkedin/ambry/subscription","commits_url":"https://api.github.com/repos/linkedin/ambry/commits{/sha}","git_commits_url":"https://api.github.com/repos/linkedin/ambry/git/commits{/sha}","comments_url":"https://api.github.com/repos/linkedin/ambry/comments{/number}","issue_comment_url":"https://api.github.com/repos/linkedin/ambry/issues/comments{/number}","contents_url":"https://api.github.com/repos/linkedin/ambry/contents/{+path}","compare_url":"https://api.github.com/repos/linkedin/ambry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/linkedin/ambry/merges","archive_url":"https://api.github.com/repos/linkedin/ambry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/linkedin/ambry/downloads","issues_url":"https://api.github.com/repos/linkedin/ambry/issues{/number}","pulls_url":"https://api.github.com/repos/linkedin/ambry/pulls{/number}","milestones_url":"https://api.github.com/repos/linkedin/ambry/milestones{/number}","notifications_url":"https://api.github.com/repos/linkedin/ambry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/linkedin/ambry/labels{/name}","releases_url":"https://api.github.com/repos/linkedin/ambry/releases{/id}","deployments_url":"https://api.github.com/repos/linkedin/ambry/deployments","created_at":"2013-10-25T20:04:54Z","updated_at":"2016-09-12T07:24:15Z","pushed_at":"2016-09-13T19:36:17Z","git_url":"git://github.com/linkedin/ambry.git","ssh_url":"git@github.com:linkedin/ambry.git","clone_url":"https://github.com/linkedin/ambry.git","svn_url":"https://github.com/linkedin/ambry","homepage":"https://github.com/linkedin/ambry/wiki","size":8662,"stargazers_count":730,"watchers_count":730,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":105,"mirror_url":null,"open_issues_count":45,"forks":105,"open_issues":45,"watchers":730,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/linkedin/ambry/pulls/445"},"html":{"href":"https://github.com/linkedin/ambry/pull/445"},"issue":{"href":"https://api.github.com/repos/linkedin/ambry/issues/445"},"comments":{"href":"https://api.github.com/repos/linkedin/ambry/issues/445/comments"},"review_comments":{"href":"https://api.github.com/repos/linkedin/ambry/pulls/445/comments"},"review_comment":{"href":"https://api.github.com/repos/linkedin/ambry/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/linkedin/ambry/pulls/445/commits"},"statuses":{"href":"https://api.github.com/repos/linkedin/ambry/statuses/aa6c2db1b6db42e44531f7edb5e78d32195dc3d4"}}}}
{"actor":{"display_login":"xiahome"}}