Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 27A80200C0D for ; Tue, 31 Jan 2017 16:53:24 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 26474160B46; Tue, 31 Jan 2017 15:53:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 65D7B160B52 for ; Tue, 31 Jan 2017 16:53:23 +0100 (CET) Received: (qmail 7029 invoked by uid 500); 31 Jan 2017 15:53:22 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 6911 invoked by uid 99); 31 Jan 2017 15:53:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Jan 2017 15:53:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 03A75DFC9D; Tue, 31 Jan 2017 15:53:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vatamane@apache.org To: commits@couchdb.apache.org Date: Tue, 31 Jan 2017 15:53:22 -0000 Message-Id: <7b782f5fbab1486b8aad4d3c35018dc5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] couch commit: updated refs/heads/master to c73a883 archived-at: Tue, 31 Jan 2017 15:53:24 -0000 Repository: couchdb-couch Updated Branches: refs/heads/master e285b34a7 -> c73a8831b Remove 8kB read-ahead from couch_file In production it showed an increased input Erlang IO and increased binary memory usage. See attached file in Jira ticket: COUCHDB-3284 Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/d52a5335 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/d52a5335 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/d52a5335 Branch: refs/heads/master Commit: d52a5335d930d11ade4953c8576d22f55872ff6f Parents: 604edd1 Author: Nick Vatamaniuc Authored: Fri Jan 27 12:04:01 2017 -0500 Committer: Nick Vatamaniuc Committed: Fri Jan 27 16:49:42 2017 -0500 ---------------------------------------------------------------------- src/couch_file.erl | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/d52a5335/src/couch_file.erl ---------------------------------------------------------------------- diff --git a/src/couch_file.erl b/src/couch_file.erl index 2623824..5d11083 100644 --- a/src/couch_file.erl +++ b/src/couch_file.erl @@ -20,7 +20,6 @@ -define(INITIAL_WAIT, 60000). -define(MONITOR_CHECK, 10000). -define(SIZE_BLOCK, 16#1000). % 4 KiB --define(READ_AHEAD, 2 * ?SIZE_BLOCK). -define(IS_OLD_STATE(S), is_pid(S#file.db_monitor)). -define(PREFIX_SIZE, 5). -define(DEFAULT_READ_COUNT, 1024). @@ -423,27 +422,15 @@ handle_call(close, _From, #file{fd=Fd}=File) -> {stop, normal, file:close(Fd), File#file{fd = nil}}; handle_call({pread_iolist, Pos}, _From, File) -> - {RawData, NextPos} = try - % up to 8Kbs of read ahead - read_raw_iolist_int(File, Pos, ?READ_AHEAD - (Pos rem ?SIZE_BLOCK)) - catch - throw:{read_beyond_eof, _} = Reason -> - throw(Reason); - throw:{exceed_pread_limit, _, _} = Reason -> - throw(Reason); - _:_ -> - read_raw_iolist_int(File, Pos, 4) - end, - <> = - iolist_to_binary(RawData), - case Prefix of - 1 -> - {Md5, IoList} = extract_md5( - maybe_read_more_iolist(RestRawData, 16 + Len, NextPos, File)), + {LenIolist, NextPos} = read_raw_iolist_int(File, Pos, 4), + case iolist_to_binary(LenIolist) of + <<1:1/integer,Len:31/integer>> -> % an MD5-prefixed term + {Md5AndIoList, _} = read_raw_iolist_int(File, NextPos, Len+16), + {Md5, IoList} = extract_md5(Md5AndIoList), {reply, {ok, IoList, Md5}, File}; - 0 -> - IoList = maybe_read_more_iolist(RestRawData, Len, NextPos, File), - {reply, {ok, IoList, <<>>}, File} + <<0:1/integer,Len:31/integer>> -> + {Iolist, _} = read_raw_iolist_int(File, NextPos, Len), + {reply, {ok, Iolist, <<>>}, File} end; handle_call(bytes, _From, #file{fd = Fd} = File) -> @@ -617,7 +604,7 @@ read_raw_iolist_int(#file{fd = Fd, pread_limit = Limit} = F, Pos, Len) -> BlockOffset = Pos rem ?SIZE_BLOCK, TotalBytes = calculate_total_read_len(BlockOffset, Len), case Pos + TotalBytes of - Size when Size > F#file.eof + ?READ_AHEAD -> + Size when Size > F#file.eof -> couch_stats:increment_counter([pread, exceed_eof]), {_Fd, Filepath} = get(couch_file_fd), throw({read_beyond_eof, Filepath});