-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add extra DLS stats in x-pack usage #132807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -40,6 +40,9 @@ | |
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
@@ -49,8 +52,10 @@ | |
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
| import java.util.function.LongSupplier; | ||
|
|
||
| /** | ||
| * This is a cache for {@link BitSet} instances that are used with the {@link DocumentSubsetReader}. | ||
|
|
@@ -120,18 +125,27 @@ public final class DocumentSubsetBitsetCache implements IndexReader.ClosedListen | |
| private final Cache<BitsetCacheKey, BitSet> bitsetCache; | ||
| private final Map<IndexReader.CacheKey, Set<BitsetCacheKey>> keysByIndex; | ||
| private final AtomicLong cacheFullWarningTime; | ||
| private final AtomicLong hitsTimeTakenNanos; | ||
| private final AtomicLong missesTimeTakenNanos; | ||
| private final LongSupplier relativeNanoTimeProvider; | ||
|
|
||
| public DocumentSubsetBitsetCache(Settings settings, ThreadPool threadPool) { | ||
| this(settings, threadPool.executor(ThreadPool.Names.GENERIC)); | ||
| this(settings, threadPool.executor(ThreadPool.Names.GENERIC), System::nanoTime); | ||
| } | ||
|
|
||
| // visible for testing | ||
| DocumentSubsetBitsetCache(Settings settings, ExecutorService cleanupExecutor) { | ||
| this(settings, cleanupExecutor, System::nanoTime); | ||
| } | ||
|
|
||
| /** | ||
| * @param settings The global settings object for this node | ||
| * @param cleanupExecutor An executor on which the cache cleanup tasks can be run. Due to the way the cache is structured internally, | ||
| * it is sometimes necessary to run an asynchronous task to synchronize the internal state. | ||
| * @param relativeNanoTimeProvider Provider of nanos for code that needs to measure relative time. | ||
| */ | ||
| // visible for testing | ||
| DocumentSubsetBitsetCache(Settings settings, ExecutorService cleanupExecutor) { | ||
| DocumentSubsetBitsetCache(Settings settings, ExecutorService cleanupExecutor, LongSupplier relativeNanoTimeProvider) { | ||
| final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); | ||
| this.cacheEvictionLock = new ReleasableLock(readWriteLock.writeLock()); | ||
| this.cacheModificationLock = new ReleasableLock(readWriteLock.readLock()); | ||
|
|
@@ -148,6 +162,9 @@ public DocumentSubsetBitsetCache(Settings settings, ThreadPool threadPool) { | |
|
|
||
| this.keysByIndex = new ConcurrentHashMap<>(); | ||
| this.cacheFullWarningTime = new AtomicLong(0); | ||
| this.hitsTimeTakenNanos = new AtomicLong(); | ||
| this.missesTimeTakenNanos = new AtomicLong(); | ||
| this.relativeNanoTimeProvider = Objects.requireNonNull(relativeNanoTimeProvider); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -220,6 +237,8 @@ public long ramBytesUsed() { | |
| */ | ||
| @Nullable | ||
| public BitSet getBitSet(final Query query, final LeafReaderContext context) throws ExecutionException { | ||
| final long startTime = relativeNanoTimeProvider.getAsLong(); | ||
|
|
||
| final IndexReader.CacheHelper coreCacheHelper = context.reader().getCoreCacheHelper(); | ||
| if (coreCacheHelper == null) { | ||
| try { | ||
|
|
@@ -233,7 +252,9 @@ public BitSet getBitSet(final Query query, final LeafReaderContext context) thro | |
| final BitsetCacheKey cacheKey = new BitsetCacheKey(indexKey, query); | ||
|
|
||
| try (ReleasableLock ignored = cacheModificationLock.acquire()) { | ||
| final AtomicBoolean cacheKeyWasPresent = new AtomicBoolean(true); | ||
| final BitSet bitSet = bitsetCache.computeIfAbsent(cacheKey, ignore1 -> { | ||
| cacheKeyWasPresent.set(false); | ||
| // This ensures all insertions into the set are guarded by ConcurrentHashMap's atomicity guarantees. | ||
| keysByIndex.compute(indexKey, (ignore2, set) -> { | ||
| if (set == null) { | ||
|
|
@@ -262,6 +283,11 @@ public BitSet getBitSet(final Query query, final LeafReaderContext context) thro | |
| } | ||
| return result; | ||
| }); | ||
| if (cacheKeyWasPresent.get()) { | ||
| hitsTimeTakenNanos.addAndGet(relativeNanoTimeProvider.getAsLong() - startTime); | ||
| } else { | ||
| missesTimeTakenNanos.addAndGet(relativeNanoTimeProvider.getAsLong() - startTime); | ||
| } | ||
| if (bitSet == NULL_MARKER) { | ||
| return null; | ||
| } else { | ||
|
|
@@ -320,7 +346,18 @@ public static List<Setting<?>> getSettings() { | |
|
|
||
| public Map<String, Object> usageStats() { | ||
| final ByteSizeValue ram = ByteSizeValue.ofBytes(ramBytesUsed()); | ||
| return Map.of("count", entryCount(), "memory", ram.toString(), "memory_in_bytes", ram.getBytes()); | ||
| final Cache.Stats bitsetCacheStats = bitsetCache.stats(); | ||
|
|
||
| final HashMap<String, Object> stats = new LinkedHashMap<>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Use |
||
| stats.put("count", entryCount()); | ||
| stats.put("memory", ram.toString()); | ||
| stats.put("memory_in_bytes", ram.getBytes()); | ||
| stats.put("hits", bitsetCacheStats.getHits()); | ||
| stats.put("misses", bitsetCacheStats.getMisses()); | ||
| stats.put("evictions", bitsetCacheStats.getEvictions()); | ||
| stats.put("hits_time_in_millis", TimeValue.nsecToMSec(hitsTimeTakenNanos.get())); | ||
| stats.put("misses_time_in_millis", TimeValue.nsecToMSec(missesTimeTakenNanos.get())); | ||
| return Collections.unmodifiableMap(stats); | ||
| } | ||
|
|
||
| private static final class BitsetCacheKey { | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://en.wikipedia.org/wiki/Rectification_of_names -- do not express individuality, make your thing like the other things.