Nevertheless, the terms index isn't that big in comparison to, say, the size
of a posting list for a common term, so the cost of re-heating it isn't
astronomical in the grand scheme of things.
Be careful: it's the seeking that kills you (until we switch to SSDs
at which point perhaps most of this discussion is moot!). Even though
the terms index net size is low, if re-heating the spots you touch
incurs 20 separate page misses, you lose.
Potentially worse than the terms index are norms, if the search hits
alot of docs.
> Take a large Jira instance...
Search responsiveness is already compromised in such a situation, because we
can all but guarantee that the posting list files have already been evicted
from cache. If the box has enough RAM for the large JIRA instance including
the Lucene index, search responsiveness won't be a problem. As soon as you
start running a little short on RAM, though, there's no way to stop infrequent
searches from being sluggish.
If the term index and norms are pinned (or happen to still be hot), I
would expect most searches to be OK with this "in the middle" use case
because the number of seeks you'll hit should be well contained
(assuming your posting list isn't unduly fragmented by the
filesystem). Burning through the posting list is a linear scan.
Queries that simply hit too many docs will always be slow anyways.
I think at both extremes (way too litle RAM and tons of RAM) both
approaches (pinned in RAM vs mmap'd) should perfom the same. It's the
cases in between where I think letting VM decide whether critical
things (terms index, norms) get to stay hot is dangerous.
The terms index could indeed get evicted some of the time on busy systems, but
the point is that the system IO cache usually works in our favor, even under
I think you're just more trusting of the IO/VM system. I think LRU is
a poor metric.
As far as backup daemons blowing up everybody's cache, that's stupid,
pathological behavior: <http://kerneltrap.org/node/3000#comment-8573>. Such
apps ought to be calling madvise(ptr, len, MADV_SEQUENTIAL) so that the kernel
knows it can recycle the cache pages as soon as they're cleared.
Excellent! If only more people knew about this. And, if only we
could do this from javaland. EG SegmentMerger should do this for all
segment data it's reading & writing.
Nathan Kurz and I brainstormed this subject in a phone call this morning, and
we came up with a three-file lexicon index design:
I don't fully understand this approach. Would the index file pointers
point into the full lexicon's packed utf8 file, or a separate "only
terms in the index" packed utf8 file?
We currently materialize individual Strings when we load our index,
which is bad because of the GC cost, added RAM overhead (& swapping)
and because for iso8859-1 only terms we are using 2X the space over
utf8. So I'd love to eventually do something similar (in RAM) for
> Have you tried any actual tests swapping these approaches in as your
> terms index impl?
No - changing something like this requires a lot of coding, so it's better to
do thought experiments first to winnow down the options.
Agreed. But once you've got the mmap-based solution up and running
it'd be nice to meaure net time doing terms lookup / norms reading,
for a variety of search use cases, and plot that on a histogram.
When I mentioned this to Nate, he remarked that we're using the OS kernel like
you're using the JVM.
Lucy/KS can't enforce that, and we wouldn't want to. It's very convenient to
be able to launch a cheap search process.
It seems like the ability to very quickly launch brand new searchers
is/has become a strong design goal of Lucy/KS. What's the driver
here? Is it for near-realtime search? (Which I think may be better
achieved by having IndexWriter export a reader, rather than using IO
system as the intermediary).
If we fix terms index to bulk load arrays (it's not now) then the cost
of loading norms & terms index on instantiating a reader should be
fairly well contained, though not as near zero as Lucy/KS will be.
> That's a nice goal. Our biggest cost in Lucene is warming the
> FieldCache, used for sorting, function queries, etc.
Exactly. It would be nice to add a plug-in indexing component that
writes sort caches to files that can be memory mapped at IndexReader
startup. There would be multiple files: both a solid array of 32-bit
integers mapping document number to sort order, and the field cache
values. Such a component would allow us to move the time it takes to
read in a sort cache from IndexReader-startup-time to index-time.
Except I would have IndexReader use its RAM budget to pick & choose
which of these will be hot, and which would be mmap'd.
Hmm, maybe we can conflate this with a column-stride field writer
and require that sort fields have a fixed width?
Yes I think column-stride fields writer should write the docID -> ord
part of StringIndex to disk, and MultiRangeQuery in
then use it. With enumerated type of fields (far fewer unique terms
than docs), bit packing will make them compact.
In KS, the relevant IndexReader methods no longer take a Term
object. (In fact, there IS no Term object any more -
KinoSearch::Index::Term has been removed.) Instead, they take a
string field and a generic "Obj".
But you must at least require these Obj's to know how to compareTo one
another? Does this mean using per-field custom sort ordering
(collator) is straightforward for KS?
I suppose we genericize this by adding a TermsDictReader/LexReader
argument to the IndexReader constructor? That way, someone can
supply a custom subclass that knows how to decode custom dictionary
Right; that's what let me create the PulsingCodec here.
The biggest problem with the "load important stuff into RAM" approach,
of course, is we can't actually pin VM pages from java, which means
the OS will happily swap out my RAM anyway, at which point of course
we should have used mmap. Though apparently at least Windows has an
option to "optimize for services" (= "don't swap out my RAM" I think)
vs "optimize for applications", and Linux lets you tune swappiness.
But both are global.