Skip to content
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

Adds debug logs for KNNQuery and KNNWeight #2466

Merged
merged 6 commits into from
Jan 30, 2025

Conversation

shatejas
Copy link
Collaborator

@shatejas shatejas commented Jan 29, 2025

Description

Adds debug logs with timing information for various knn query components

Testing

Cluster setting changed in local

curl --request PUT \
  --url http://localhost:9200/_cluster/settings \
  --header 'Content-Type: application/json' \
  --data '{
  "persistent" : {
		"logger.org.opensearch.knn.index.query" : "DEBUG"
  }
}'

Output

q.KNNQueryFactory] [integTest-0] Creating custom k-NN query for index:target_index_faiss, field:location, k:3, filterQuery:+IndexOrDocValuesQuery(indexQuery=rating:[8 TO 10], dvQuery=rating:[8 TO 10]), efSearch:null
[2025-01-29T11:20:21,929][DEBUG][o.o.k.i.q.KNNQuery       ] [integTest-0] Creating filter weight for field [location] took [603583] nanos
[2025-01-29T11:20:21,930][DEBUG][o.o.k.i.q.KNNWeight      ] [integTest-0] Creating filter bitset for field [location] took [462500] nanos
[2025-01-29T11:20:21,930][DEBUG][o.o.k.i.q.KNNWeight      ] [integTest-0] Info for doing exact search filterIdsLength : 10, Threshold value: -1
[2025-01-29T11:20:21,930][DEBUG][o.o.k.i.q.KNNWeight      ] [integTest-0] Exact search for field [location] took [232083] nanos

Check List

  • New functionality includes testing.
  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -168,7 +171,10 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo
if (!KNNSettings.isKNNPluginEnabled()) {
throw new IllegalStateException("KNN plugin is disabled. To enable update knn.plugin.enabled to true");
}
StopWatch stopWatch = new StopWatch().start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap this behind log.isDebugEnabled()?
It's not a big overhead but given that it's being used only for debug logging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about if but wanted to avoid if conditions. Let me add it

@shatejas shatejas requested a review from kotwanikunal January 29, 2025 20:14
@@ -166,6 +174,13 @@ public PerLeafResult searchLeaf(LeafReaderContext context, int k) throws IOExcep
return new PerLeafResult(filterWeight == null ? null : filterBitSet, docIdsToScoreMap);
}

private void stopStopWatchAndLog(@Nullable StopWatch stopWatch, String message) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add final to method parameters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -153,7 +158,10 @@ public PerLeafResult searchLeaf(LeafReaderContext context, int k) throws IOExcep
* so that it will not do a bitset look up in bottom search layer.
*/
final BitSet annFilter = (filterWeight != null && cardinality == maxDoc) ? null : filterBitSet;
StopWatch annStopWatch = startStopWatch();
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

private void stopStopWatchAndLog(@Nullable StopWatch stopWatch, String message) {
if (log.isDebugEnabled() && stopWatch != null) {
stopWatch.stop();
log.debug(message, knnQuery.getField(), stopWatch.totalTime().nanos());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it advisable to assume that message will have two arguments and in that order?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine considering its private

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is error prone. Considering it is private, can you add doc saying that param message expects two args with field name and nano secs in that order

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the sequence of stopping the watch and then logging it I can change the name of the function or just pass a prefix and standardize the message

final Weight filterWeight = getFilterWeight(searcher);
if (log.isDebugEnabled() && stopWatch != null) {
stopWatch.stop();
log.debug("Creating filter weight for field [{}] took [{}] nanos", field, stopWatch.totalTime().nanos());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need any segment info like total docs which was present? name of the shard etc for better debugging. Because we have a lot of segments then this log statement won't be that helpful

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added shard and segment info. cat APIs should help trace down total docs and deleted docs

VijayanB
VijayanB previously approved these changes Jan 29, 2025
return exactSearcher.searchLeaf(leafReaderContext, exactSearcherContext);
StopWatch stopWatch = startStopWatch();
Map<Integer, Float> exactSearchResults = exactSearcher.searchLeaf(leafReaderContext, exactSearcherContext);
final SegmentReader reader = Lucene.segmentReader(leafReaderContext.reader());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here to not have to make changes in NativeEngineQuery

Signed-off-by: Tejas Shah <[email protected]>
@shatejas shatejas merged commit f322e27 into opensearch-project:2.x Jan 30, 2025
102 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 30, 2025
* Adds debug logs for KNNQuery and KNNWeight

Signed-off-by: Tejas Shah <[email protected]>

* Adds check to see if log is enabled to start and stop StopWatch

Signed-off-by: Tejas Shah <[email protected]>

* Addressing comments on the PR

Signed-off-by: Tejas Shah <[email protected]>

* Adds shard and segment info in the logs

Signed-off-by: Tejas Shah <[email protected]>

* Removes unnecessary segment name param from exact search

Signed-off-by: Tejas Shah <[email protected]>

* Fixes the build

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Tejas Shah <[email protected]>
(cherry picked from commit f322e27)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 30, 2025
* Adds debug logs for KNNQuery and KNNWeight

Signed-off-by: Tejas Shah <[email protected]>

* Adds check to see if log is enabled to start and stop StopWatch

Signed-off-by: Tejas Shah <[email protected]>

* Addressing comments on the PR

Signed-off-by: Tejas Shah <[email protected]>

* Adds shard and segment info in the logs

Signed-off-by: Tejas Shah <[email protected]>

* Removes unnecessary segment name param from exact search

Signed-off-by: Tejas Shah <[email protected]>

* Fixes the build

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Tejas Shah <[email protected]>
(cherry picked from commit f322e27)
shatejas added a commit that referenced this pull request Jan 30, 2025
* Adds debug logs for KNNQuery and KNNWeight

Signed-off-by: Tejas Shah <[email protected]>

* Adds check to see if log is enabled to start and stop StopWatch

Signed-off-by: Tejas Shah <[email protected]>

* Addressing comments on the PR

Signed-off-by: Tejas Shah <[email protected]>

* Adds shard and segment info in the logs

Signed-off-by: Tejas Shah <[email protected]>

* Removes unnecessary segment name param from exact search

Signed-off-by: Tejas Shah <[email protected]>

* Fixes the build

Signed-off-by: Tejas Shah <[email protected]>

---------

Signed-off-by: Tejas Shah <[email protected]>
(cherry picked from commit f322e27)

Co-authored-by: Tejas Shah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants