forked from apache/lucene
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce the overhead of
IndexInput#prefetch
when data is cached in RAM.
As Robert pointed out and benchmarks confirmed, there is some (small) overhead to calling `madvise` via the foreign function API, benchmarks suggest it is in the order of 1-2us. This is not much for a single call, but may become non-negligible across many calls. Until now, we only looked into using prefetch() for terms, skip data and postings start pointers which are a single prefetch() operation per segment per term. But we may want to start using it in cases that could result into more calls to `madvise`, e.g. if we start using it for stored fields and a user requests 10k documents. In apache#13337, Robert wondered if we could take advantage of `mincore()` to reduce the overhead of `IndexInput#prefetch()`, which is what this PR is doing. For now, this is trying to not add new APIs. Instead, `IndexInput#prefetch` tracks consecutive hits on the page cache and calls `madvise` less and less frequently under the hood as the number of cache hits increases.
- Loading branch information
Showing
5 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lucene/core/src/test/org/apache/lucene/util/TestBitUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.util; | ||
|
||
import org.apache.lucene.tests.util.LuceneTestCase; | ||
|
||
public class TestBitUtil extends LuceneTestCase { | ||
|
||
public void testIsZeroOrPowerOfTwo() { | ||
assertTrue(BitUtil.isZeroOrPowerOfTwo(0)); | ||
for (int shift = 0; shift <= 31; ++shift) { | ||
assertTrue(BitUtil.isZeroOrPowerOfTwo(1 << shift)); | ||
} | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(3)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(5)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(6)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(7)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(9)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(Integer.MAX_VALUE)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(Integer.MAX_VALUE + 2)); | ||
assertFalse(BitUtil.isZeroOrPowerOfTwo(-1)); | ||
} | ||
} |