You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2016/10/04 18:19:21 UTC

[jira] [Commented] (COUCHDB-3061) Decrease search time for deeply buried headers

    [ https://issues.apache.org/jira/browse/COUCHDB-3061?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15546210#comment-15546210 ] 

ASF subversion and git services commented on COUCHDB-3061:
----------------------------------------------------------

Commit d5fbb6dd0d770861222b6a5de3124f10d9eafd4f in couchdb-couch's branch refs/heads/master from [~jaydoane]
[ https://git-wip-us.apache.org/repos/asf?p=couchdb-couch.git;h=d5fbb6d ]

Use vectored reads to search for buried headers

Current behavior attempts to read a header at each block, starting at
the eof and working backwards one block at a time. Deeply buried headers
can take a long time to find, depending on the depth of the header,
server load, etc.

This commit changes the behavior so that if the last block in the file
does not contain a header, it switches to using a "vectored" approach
where multiple candidate header prefixes (of 5 bytes) are read in a
single operation, greatly speeding up the search. On a modern linux
system with SSD, we see improvements up to 15x.

COUCHDB-3061


> Decrease search time for deeply buried headers
> ----------------------------------------------
>
>                 Key: COUCHDB-3061
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-3061
>             Project: CouchDB
>          Issue Type: Improvement
>          Components: Database Core
>            Reporter: Jay Doane
>            Assignee: Jay Doane
>
> When a db compaction is interrupted and restarted, it's possible for the most recent header written to the .compact.meta file to be buried under many GB from the end of file. For example, an interrupted compaction left the following files:
> {code}
> -rw-r--r-- 1 dbcore dbcore 47G Jun 27 04:29 /srv/db/shards/40000000-7fffffff/opendi/yellow-ng-loadbalancer.1461156255.couch.compact.data
> -rw-r--r-- 1 dbcore dbcore 12G Jun 27 05:20 /srv/db/shards/40000000-7fffffff/opendi/yellow-ng-loadbalancer.1461156255.couch.compact.meta
> {code}
> but
> {code}
> # grep -abo db_header yellow-ng-loadbalancer.1461156255.couch.compact.meta | tail -1
> 4364894251:db_header
> {code}
> which means the current algorithm must search through about 8GB of file before it gets to a header. I measured how long it takes, both on an SSD laptop and SSD server, getting similar numbers:
> {code}
> (dbcore@db3.testy012.cloudant.net)18> timer:tc(couch_file,test_find_header,["/srv/jdoane/yellow-ng-loadbalancer.1461156255.couch.compact.meta", default]).
> {328335338, ...
> (node1@127.0.0.1)27> timer:tc(couch_file,test_find_header,["/Users/jay/proj/ibm/sample-data/yellow-ng-loadbalancer.1461156255.couch.compact.meta", default]).
> {426650530, ...
> {code}
> which is between 328-427 seconds, or 19-25 MB/s.
> One reason for this relative slowness is because the current algorithm performs a disk read for every block it searches:
> https://github.com/apache/couchdb-couch/blob/master/src/couch_file.erl#L537-L539
> We can improve the speed by loading a "chunk" of many blocks into memory with a single read operation, and then search each block in memory, trading off memory for speed. Ideally, the tradeoff can be made configurable, so that existing speed/memory behavior can be retained by default.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)