From d8af1fde685626283826ecaf52d4ac49cebdea98 Mon Sep 17 00:00:00 2001
From: Will Greenberg <will@endlessm.com>
Date: Mon, 16 Mar 2015 17:56:38 -0700
Subject: [PATCH] Really gross fix for sharded db performance
---
xapian-core/common/io_utils.cc | 12 ++++++++++++
xapian-core/common/io_utils.h | 2 ++
xapian-core/matcher/multimatch.cc | 10 ++++++++++
3 files changed, 24 insertions(+)
diff --git a/xapian-core/common/io_utils.cc b/xapian-core/common/io_utils.cc
index fefef8e..2f6e7ac 100644
a
|
b
|
throw_block_error(const char * s, off_t b, int e)
|
104 | 104 | throw Xapian::DatabaseError(m, e); |
105 | 105 | } |
106 | 106 | |
| 107 | // dirty dirty hack that turns all preads into readaheads; preempts heavy disk |
| 108 | // io operations |
| 109 | bool IS_READAHEAD = false; |
| 110 | void set_readahead(bool val) { |
| 111 | IS_READAHEAD = val; |
| 112 | } |
| 113 | |
107 | 114 | void |
108 | 115 | io_read_block(int fd, char * p, size_t n, off_t b) |
109 | 116 | { |
… |
… |
io_read_block(int fd, char * p, size_t n, off_t b)
|
113 | 120 | // per block read. |
114 | 121 | #ifdef HAVE_PREAD |
115 | 122 | while (true) { |
| 123 | if (IS_READAHEAD) { |
| 124 | // readahead has reversed order of parameters to pread, for some reason... |
| 125 | readahead(fd, o, n); |
| 126 | return; |
| 127 | } |
116 | 128 | ssize_t c = pread(fd, p, n, o); |
117 | 129 | // We should get a full read most of the time, so streamline that case. |
118 | 130 | if (usual(c == ssize_t(n))) |
diff --git a/xapian-core/common/io_utils.h b/xapian-core/common/io_utils.h
index 89d5d46..5c728dd 100644
a
|
b
|
inline bool io_sync(int fd)
|
47 | 47 | #endif |
48 | 48 | } |
49 | 49 | |
| 50 | void set_readahead(bool val); |
| 51 | |
50 | 52 | inline bool io_full_sync(int fd) |
51 | 53 | { |
52 | 54 | #ifdef F_FULLFSYNC |
diff --git a/xapian-core/matcher/multimatch.cc b/xapian-core/matcher/multimatch.cc
index ef8525e..5bb096b 100644
a
|
b
|
|
32 | 32 | #include "debuglog.h" |
33 | 33 | #include "submatch.h" |
34 | 34 | #include "localsubmatch.h" |
| 35 | #include "io_utils.h" |
35 | 36 | #include "omassert.h" |
36 | 37 | #include "api/omenquireinternal.h" |
37 | 38 | #include "realtime.h" |
… |
… |
MultiMatch::MultiMatch(const Xapian::Database &db_,
|
350 | 351 | } |
351 | 352 | |
352 | 353 | stats.set_query(query); |
| 354 | |
| 355 | set_readahead(true); |
| 356 | // readahead all the blocks we're about to read |
| 357 | for (size_t leaf = 0; leaf < leaves.size(); ++leaf) { |
| 358 | SubMatch * submatch = leaves[leaf].get(); |
| 359 | submatch->prepare_match(true, stats); |
| 360 | } |
| 361 | set_readahead(false); |
| 362 | |
353 | 363 | prepare_sub_matches(leaves, errorhandler, stats); |
354 | 364 | stats.set_bounds_from_db(db); |
355 | 365 | } |