{"action":"created","comment":{"url":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments/149150498","pull_request_review_id":74494820,"id":149150498,"diff_hunk":"@@ -641,19 +829,16 @@ private long remainingInternal() {\n    */\n   private void seekInternalWithCachingPartiallyReadBlock(long pos) throws IOException {\n     // Precompute this because mPos will be updated several times in this function.\n-    final boolean isInCurrentBlock = pos / mBlockSize == mPos / mBlockSize;\n+    final boolean isInCurrentBlock = mCurrentBlockInStream != null\n+        && mPositionState.isInCurrentBlock(pos);\n \n     if (isInCurrentBlock) {\n-      // the read is within the current block update stream to refresh the streams\n-      updateStreams();\n       if (isReadFromLocalWorker()) {\n         // no need to partial cache the current block, and the seek is within the block\n         // so directly seeks to position.\n-        mPos = pos;\n-        // updateStreams is necessary when pos = mFileLength.\n-        updateStreams();\n+        mPositionState.setPos(pos);\n         if (mCurrentBlockInStream != null) {\n-          mCurrentBlockInStream.seek(mPos % mBlockSize);\n+          mCurrentBlockInStream.seek(mPositionState.getPos() % mBlockSize);","path":"core/client/fs/src/main/java/alluxio/client/file/FileInStream.java","position":693,"original_position":693,"commit_id":"c3fbb2e0666a6aa055deda55842f58c913774fde","original_commit_id":"c3fbb2e0666a6aa055deda55842f58c913774fde","user":{"login":"yupeng9","id":13425258,"avatar_url":"https://avatars1.githubusercontent.com/u/13425258?v=4","gravatar_id":"","url":"https://api.github.com/users/yupeng9","html_url":"https://github.com/yupeng9","followers_url":"https://api.github.com/users/yupeng9/followers","following_url":"https://api.github.com/users/yupeng9/following{/other_user}","gists_url":"https://api.github.com/users/yupeng9/gists{/gist_id}","starred_url":"https://api.github.com/users/yupeng9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yupeng9/subscriptions","organizations_url":"https://api.github.com/users/yupeng9/orgs","repos_url":"https://api.github.com/users/yupeng9/repos","events_url":"https://api.github.com/users/yupeng9/events{/privacy}","received_events_url":"https://api.github.com/users/yupeng9/received_events","type":"User","site_admin":false},"body":"if the seek position is in the first block for the first read of the opened file, without `updateStreams()` the `mCurrentBlockInStream`  would not be initialized and therefore be null, right?","created_at":"2017-11-06T17:41:42Z","updated_at":"2017-11-06T17:43:31Z","html_url":"https://github.com/Alluxio/alluxio/pull/6346#discussion_r149150498","pull_request_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments/149150498"},"html":{"href":"https://github.com/Alluxio/alluxio/pull/6346#discussion_r149150498"},"pull_request":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346"}}},"pull_request":{"url":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346","id":149301669,"html_url":"https://github.com/Alluxio/alluxio/pull/6346","diff_url":"https://github.com/Alluxio/alluxio/pull/6346.diff","patch_url":"https://github.com/Alluxio/alluxio/pull/6346.patch","issue_url":"https://api.github.com/repos/Alluxio/alluxio/issues/6346","number":6346,"state":"open","locked":false,"title":"[ALLUXIO-3050] Optimize performance of tiny read","user":{"login":"uronce-cc","id":3663941,"avatar_url":"https://avatars1.githubusercontent.com/u/3663941?v=4","gravatar_id":"","url":"https://api.github.com/users/uronce-cc","html_url":"https://github.com/uronce-cc","followers_url":"https://api.github.com/users/uronce-cc/followers","following_url":"https://api.github.com/users/uronce-cc/following{/other_user}","gists_url":"https://api.github.com/users/uronce-cc/gists{/gist_id}","starred_url":"https://api.github.com/users/uronce-cc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uronce-cc/subscriptions","organizations_url":"https://api.github.com/users/uronce-cc/orgs","repos_url":"https://api.github.com/users/uronce-cc/repos","events_url":"https://api.github.com/users/uronce-cc/events{/privacy}","received_events_url":"https://api.github.com/users/uronce-cc/received_events","type":"User","site_admin":false},"body":"https://alluxio.atlassian.net/browse/ALLUXIO-3050\r\n\r\nThis is the first PR to fix the tiny read performance issue, the goal of this PR is to reduce the number of computations for computing block IDs based on `mPos` for each call to `updateStreams`.\r\n\r\nI did an experiment reading a 8GB file cached in Alluxio's memory tier with a 8B read buffer, the profiling of Alluxio client process shows that `getBlockId` and `getCurrentBlockId` takes more than 1/3 of the total time. \r\n\r\n<img width=\"1402\" alt=\"screen shot 2017-10-26 at 4 49 15 pm\" src=\"https://user-images.githubusercontent.com/3663941/32129135-f4959076-bb38-11e7-8bb3-52196e897511.png\">\r\n\r\nThis PR changes the logic in `updateStreams`:\r\n\r\n* For streaming read, the block stream is updated based on whether the current block stream has all been consumed, we keep track of blockIdIndex instead of computing the index every time `updateStreams` is called.\r\n* For `seek` and `skip`, they can update streams based on computing the new block index from `mPos`.\r\n\r\nI ran several experiments for reading a 4GB in memory file with an 8B read buffer with read type CACHE_PROMOTE. The improvement of read throughput for 1 thread is around 48% improvement.\r\n\r\nBut for 1 thread, comparing the read throughput with 1MB read buffer below, there is at least 2x slowdown for the 8B read buffer case, so there might still have space for optimization.\r\n","created_at":"2017-10-27T22:55:52Z","updated_at":"2017-11-06T17:43:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b04e0d6cccb0b58656c1bd253d505fc0497de909","assignee":{"login":"apc999","id":1413748,"avatar_url":"https://avatars0.githubusercontent.com/u/1413748?v=4","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false},"assignees":[{"login":"apc999","id":1413748,"avatar_url":"https://avatars0.githubusercontent.com/u/1413748?v=4","gravatar_id":"","url":"https://api.github.com/users/apc999","html_url":"https://github.com/apc999","followers_url":"https://api.github.com/users/apc999/followers","following_url":"https://api.github.com/users/apc999/following{/other_user}","gists_url":"https://api.github.com/users/apc999/gists{/gist_id}","starred_url":"https://api.github.com/users/apc999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apc999/subscriptions","organizations_url":"https://api.github.com/users/apc999/orgs","repos_url":"https://api.github.com/users/apc999/repos","events_url":"https://api.github.com/users/apc999/events{/privacy}","received_events_url":"https://api.github.com/users/apc999/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346/commits","review_comments_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346/comments","review_comment_url":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Alluxio/alluxio/issues/6346/comments","statuses_url":"https://api.github.com/repos/Alluxio/alluxio/statuses/c3fbb2e0666a6aa055deda55842f58c913774fde","head":{"label":"uronce-cc:fix-tiny-read","ref":"fix-tiny-read","sha":"c3fbb2e0666a6aa055deda55842f58c913774fde","user":{"login":"uronce-cc","id":3663941,"avatar_url":"https://avatars1.githubusercontent.com/u/3663941?v=4","gravatar_id":"","url":"https://api.github.com/users/uronce-cc","html_url":"https://github.com/uronce-cc","followers_url":"https://api.github.com/users/uronce-cc/followers","following_url":"https://api.github.com/users/uronce-cc/following{/other_user}","gists_url":"https://api.github.com/users/uronce-cc/gists{/gist_id}","starred_url":"https://api.github.com/users/uronce-cc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uronce-cc/subscriptions","organizations_url":"https://api.github.com/users/uronce-cc/orgs","repos_url":"https://api.github.com/users/uronce-cc/repos","events_url":"https://api.github.com/users/uronce-cc/events{/privacy}","received_events_url":"https://api.github.com/users/uronce-cc/received_events","type":"User","site_admin":false},"repo":{"id":52493150,"name":"alluxio","full_name":"uronce-cc/alluxio","owner":{"login":"uronce-cc","id":3663941,"avatar_url":"https://avatars1.githubusercontent.com/u/3663941?v=4","gravatar_id":"","url":"https://api.github.com/users/uronce-cc","html_url":"https://github.com/uronce-cc","followers_url":"https://api.github.com/users/uronce-cc/followers","following_url":"https://api.github.com/users/uronce-cc/following{/other_user}","gists_url":"https://api.github.com/users/uronce-cc/gists{/gist_id}","starred_url":"https://api.github.com/users/uronce-cc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uronce-cc/subscriptions","organizations_url":"https://api.github.com/users/uronce-cc/orgs","repos_url":"https://api.github.com/users/uronce-cc/repos","events_url":"https://api.github.com/users/uronce-cc/events{/privacy}","received_events_url":"https://api.github.com/users/uronce-cc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/uronce-cc/alluxio","description":"Memory-Centric Virtual Distributed Storage System","fork":true,"url":"https://api.github.com/repos/uronce-cc/alluxio","forks_url":"https://api.github.com/repos/uronce-cc/alluxio/forks","keys_url":"https://api.github.com/repos/uronce-cc/alluxio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uronce-cc/alluxio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uronce-cc/alluxio/teams","hooks_url":"https://api.github.com/repos/uronce-cc/alluxio/hooks","issue_events_url":"https://api.github.com/repos/uronce-cc/alluxio/issues/events{/number}","events_url":"https://api.github.com/repos/uronce-cc/alluxio/events","assignees_url":"https://api.github.com/repos/uronce-cc/alluxio/assignees{/user}","branches_url":"https://api.github.com/repos/uronce-cc/alluxio/branches{/branch}","tags_url":"https://api.github.com/repos/uronce-cc/alluxio/tags","blobs_url":"https://api.github.com/repos/uronce-cc/alluxio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uronce-cc/alluxio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uronce-cc/alluxio/git/refs{/sha}","trees_url":"https://api.github.com/repos/uronce-cc/alluxio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uronce-cc/alluxio/statuses/{sha}","languages_url":"https://api.github.com/repos/uronce-cc/alluxio/languages","stargazers_url":"https://api.github.com/repos/uronce-cc/alluxio/stargazers","contributors_url":"https://api.github.com/repos/uronce-cc/alluxio/contributors","subscribers_url":"https://api.github.com/repos/uronce-cc/alluxio/subscribers","subscription_url":"https://api.github.com/repos/uronce-cc/alluxio/subscription","commits_url":"https://api.github.com/repos/uronce-cc/alluxio/commits{/sha}","git_commits_url":"https://api.github.com/repos/uronce-cc/alluxio/git/commits{/sha}","comments_url":"https://api.github.com/repos/uronce-cc/alluxio/comments{/number}","issue_comment_url":"https://api.github.com/repos/uronce-cc/alluxio/issues/comments{/number}","contents_url":"https://api.github.com/repos/uronce-cc/alluxio/contents/{+path}","compare_url":"https://api.github.com/repos/uronce-cc/alluxio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uronce-cc/alluxio/merges","archive_url":"https://api.github.com/repos/uronce-cc/alluxio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uronce-cc/alluxio/downloads","issues_url":"https://api.github.com/repos/uronce-cc/alluxio/issues{/number}","pulls_url":"https://api.github.com/repos/uronce-cc/alluxio/pulls{/number}","milestones_url":"https://api.github.com/repos/uronce-cc/alluxio/milestones{/number}","notifications_url":"https://api.github.com/repos/uronce-cc/alluxio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uronce-cc/alluxio/labels{/name}","releases_url":"https://api.github.com/repos/uronce-cc/alluxio/releases{/id}","deployments_url":"https://api.github.com/repos/uronce-cc/alluxio/deployments","created_at":"2016-02-25T03:13:56Z","updated_at":"2016-02-25T03:14:00Z","pushed_at":"2017-11-06T17:05:48Z","git_url":"git://github.com/uronce-cc/alluxio.git","ssh_url":"git@github.com:uronce-cc/alluxio.git","clone_url":"https://github.com/uronce-cc/alluxio.git","svn_url":"https://github.com/uronce-cc/alluxio","homepage":"http://www.alluxio.org/","size":83335,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Alluxio:master","ref":"master","sha":"567c33ab5ff9f1f1640d9a5fcd3ffc3b60ea597d","user":{"login":"Alluxio","id":16203694,"avatar_url":"https://avatars0.githubusercontent.com/u/16203694?v=4","gravatar_id":"","url":"https://api.github.com/users/Alluxio","html_url":"https://github.com/Alluxio","followers_url":"https://api.github.com/users/Alluxio/followers","following_url":"https://api.github.com/users/Alluxio/following{/other_user}","gists_url":"https://api.github.com/users/Alluxio/gists{/gist_id}","starred_url":"https://api.github.com/users/Alluxio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alluxio/subscriptions","organizations_url":"https://api.github.com/users/Alluxio/orgs","repos_url":"https://api.github.com/users/Alluxio/repos","events_url":"https://api.github.com/users/Alluxio/events{/privacy}","received_events_url":"https://api.github.com/users/Alluxio/received_events","type":"Organization","site_admin":false},"repo":{"id":7276954,"name":"alluxio","full_name":"Alluxio/alluxio","owner":{"login":"Alluxio","id":16203694,"avatar_url":"https://avatars0.githubusercontent.com/u/16203694?v=4","gravatar_id":"","url":"https://api.github.com/users/Alluxio","html_url":"https://github.com/Alluxio","followers_url":"https://api.github.com/users/Alluxio/followers","following_url":"https://api.github.com/users/Alluxio/following{/other_user}","gists_url":"https://api.github.com/users/Alluxio/gists{/gist_id}","starred_url":"https://api.github.com/users/Alluxio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alluxio/subscriptions","organizations_url":"https://api.github.com/users/Alluxio/orgs","repos_url":"https://api.github.com/users/Alluxio/repos","events_url":"https://api.github.com/users/Alluxio/events{/privacy}","received_events_url":"https://api.github.com/users/Alluxio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Alluxio/alluxio","description":"Alluxio, formerly Tachyon, Unify Data at Memory Speed","fork":false,"url":"https://api.github.com/repos/Alluxio/alluxio","forks_url":"https://api.github.com/repos/Alluxio/alluxio/forks","keys_url":"https://api.github.com/repos/Alluxio/alluxio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Alluxio/alluxio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Alluxio/alluxio/teams","hooks_url":"https://api.github.com/repos/Alluxio/alluxio/hooks","issue_events_url":"https://api.github.com/repos/Alluxio/alluxio/issues/events{/number}","events_url":"https://api.github.com/repos/Alluxio/alluxio/events","assignees_url":"https://api.github.com/repos/Alluxio/alluxio/assignees{/user}","branches_url":"https://api.github.com/repos/Alluxio/alluxio/branches{/branch}","tags_url":"https://api.github.com/repos/Alluxio/alluxio/tags","blobs_url":"https://api.github.com/repos/Alluxio/alluxio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Alluxio/alluxio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Alluxio/alluxio/git/refs{/sha}","trees_url":"https://api.github.com/repos/Alluxio/alluxio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Alluxio/alluxio/statuses/{sha}","languages_url":"https://api.github.com/repos/Alluxio/alluxio/languages","stargazers_url":"https://api.github.com/repos/Alluxio/alluxio/stargazers","contributors_url":"https://api.github.com/repos/Alluxio/alluxio/contributors","subscribers_url":"https://api.github.com/repos/Alluxio/alluxio/subscribers","subscription_url":"https://api.github.com/repos/Alluxio/alluxio/subscription","commits_url":"https://api.github.com/repos/Alluxio/alluxio/commits{/sha}","git_commits_url":"https://api.github.com/repos/Alluxio/alluxio/git/commits{/sha}","comments_url":"https://api.github.com/repos/Alluxio/alluxio/comments{/number}","issue_comment_url":"https://api.github.com/repos/Alluxio/alluxio/issues/comments{/number}","contents_url":"https://api.github.com/repos/Alluxio/alluxio/contents/{+path}","compare_url":"https://api.github.com/repos/Alluxio/alluxio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Alluxio/alluxio/merges","archive_url":"https://api.github.com/repos/Alluxio/alluxio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Alluxio/alluxio/downloads","issues_url":"https://api.github.com/repos/Alluxio/alluxio/issues{/number}","pulls_url":"https://api.github.com/repos/Alluxio/alluxio/pulls{/number}","milestones_url":"https://api.github.com/repos/Alluxio/alluxio/milestones{/number}","notifications_url":"https://api.github.com/repos/Alluxio/alluxio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Alluxio/alluxio/labels{/name}","releases_url":"https://api.github.com/repos/Alluxio/alluxio/releases{/id}","deployments_url":"https://api.github.com/repos/Alluxio/alluxio/deployments","created_at":"2012-12-21T17:43:46Z","updated_at":"2017-11-06T11:14:00Z","pushed_at":"2017-11-06T17:13:34Z","git_url":"git://github.com/Alluxio/alluxio.git","ssh_url":"git@github.com:Alluxio/alluxio.git","clone_url":"https://github.com/Alluxio/alluxio.git","svn_url":"https://github.com/Alluxio/alluxio","homepage":"http://www.alluxio.org/","size":82816,"stargazers_count":3199,"watchers_count":3199,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1668,"mirror_url":null,"archived":false,"open_issues_count":37,"forks":1668,"open_issues":37,"watchers":3199,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346"},"html":{"href":"https://github.com/Alluxio/alluxio/pull/6346"},"issue":{"href":"https://api.github.com/repos/Alluxio/alluxio/issues/6346"},"comments":{"href":"https://api.github.com/repos/Alluxio/alluxio/issues/6346/comments"},"review_comments":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346/comments"},"review_comment":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Alluxio/alluxio/pulls/6346/commits"},"statuses":{"href":"https://api.github.com/repos/Alluxio/alluxio/statuses/c3fbb2e0666a6aa055deda55842f58c913774fde"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"yupeng9"}}