<div dir="ltr">Awesome, thanks! <br><div>I use xapian 1.4.5 and congratulate 1.4.6 has been released. I am reading these link you gave me. I will issue another thread if I get stucked.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 3, 2018 at 2:21 PM Olly Betts <<a href="mailto:olly@survex.com">olly@survex.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jul 02, 2018 at 06:08:40PM +0800, morefreeze wrote:<br>
> I found every first time(like after booting computer) or<br>
> sometime(occasional) to query(use QueryParse) this databases will cost<br>
> significant seconds (like 5 seconds), although it cost 0.8 seconds on<br>
> average. What is the reason of this?<br>
<br>
If you've just rebooted, none of the database will be cached, so<br>
everything has to be fetched from disk and that takes more time.<br>
<br>
The second query will be faster even if it's for entirely different<br>
terms, because at least the root blocks will be read from cache.<br>
And pretty quickly the cache ends up with all the frequently read<br>
blocks.<br>
<br>
This can also happen without a reboot if another process reads a lot<br>
of data which ends up in cache instead of the database blocks.  If<br>
the machine has cronjobs making backups, update the db used by the<br>
"locate" tool, or doing other things which read a lot of files, you<br>
might want to consider carefully when they run, or run them under<br>
something which minimises cache effects such as "nocache".<br>
<br>
> If I want to shorten this query time what should I do or try? BTW, I<br>
> think splitting more databases and query them parallelly is not a good<br>
> idea, unless xapian ensure each query is less than a expected<br>
> time(Actually this 13M database is 'small', :P).<br>
<br>
I'd think searching more databases would if anything make this "cold<br>
cache" effect worse.<br>
<br>
You don't say what version you're using, but make sure it's a recent<br>
Xapian 1.4.x and that you're using the glass backend.  If you're still<br>
using 1.2.x, or 1.4.x with chert databases then switching to 1.4.x+glass<br>
is likely to help.<br>
<br>
You can warm the cache usefully just by running a few queries (if<br>
you make them for commonly searched terms that will be more effective).<br>
So if you have a cluster of search machines and want to add a new<br>
member to it, you can automate running a few "warm up" queries after<br>
spinning up the new instance but before actually adding it to the<br>
cluster.<br>
<br>
1.4.x will issue prefetch hints if posix_fadvise() is available, which<br>
helps when the cache is cold.  These are done automatically for<br>
postlists, but you can call MSet::fetch() to issue prefetch hints for<br>
fetching document data.  This ticket is about the prefetching changes:<br>
<br>
<a href="https://trac.xapian.org/ticket/671" rel="noreferrer" target="_blank">https://trac.xapian.org/ticket/671</a><br>
<br>
If you want to profile what database blocks are being read, then the<br>
strace-analyse script may be useful:<br>
<br>
<a href="https://trac.xapian.org/browser/git/xapian-maintainer-tools/profiling/strace-analyse" rel="noreferrer" target="_blank">https://trac.xapian.org/browser/git/xapian-maintainer-tools/profiling/strace-analyse</a><br>
<br>
See the comments in the script for how to use it.<br>
<br>
Cheers,<br>
    Olly<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span style="color:rgb(119,119,119);font-family:'Open Sans';font-size:16px;line-height:20px">One of my most productive days was throwing away 1000 lines of code.</span><br></div></div>