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

recording the cost for different types of queries #1829

Merged
merged 10 commits into from
Jun 13, 2023

Conversation

Thejas-bhat
Copy link
Member

@Thejas-bhat Thejas-bhat commented May 30, 2023

  • Adds a new callback function SearchIncrementalCostCallbackFn which is used to track incremental cost updates for the query. It can also be used to track costs for different types of queries as well.

  • Renames "bytesRead" to "search_cost"

@abhinavdangeti abhinavdangeti added this to the v2.3.9 milestone May 30, 2023
@Thejas-bhat Thejas-bhat marked this pull request as ready for review June 5, 2023 10:43
search/util.go Outdated
type SearchIOStatsCallbackFunc func(uint64)

// The callback signature is (message, queryType, cost) which allows
// the caller to act on a particular query type and what its the associated
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we concise "query type and what its the associated cost of an operation."
to
"query type and it's associated cost of operation"

Copy link
Member Author

Choose a reason for hiding this comment

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

will do, thanks

search/util.go Outdated

// The callback signature is (message, queryType, cost) which allows
// the caller to act on a particular query type and what its the associated
// cost of an operation. "add" indicates to increment the cost for the query
Copy link
Contributor

Choose a reason for hiding this comment

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

Values of message argument (like "add" and "done" ) aren't defined by bleve, it is upto the user of bleve.

If you have specified "add" and "done" as examples of message argument value, then we can frame it that way

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, the cost callback according to me includes very basic set of messages, which are add, done and maybe abort, since its mainly enabling the caller to track the costs incrementally and act upon that along with a "done" type of a message that will help the caller to act upon the tracked bytes until now. perhaps an abort invocation can be done when there is a ctx.Done() in the collector phase (which would happen when the search's context is cancelled i believe) in that case, the caller can handle separately perhaps.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got your point.
Bleve will invoke the callback with these messages "add", "done", "abort" etc ...
And it is the responsibility of the author of the callback to properly handle these messages.

In this case, we can frame our comment like this:
"Implementation of SearchIncrementalCostCallbackFn should handle the following messages
- add: "description ..."
- abort: description ...
- done: description ...
"

We can even assign IDs to these messages and export from bleve

type IncCostMessage uint

const (
AddM = Service(1 << iota) // description
AbortM // description
DoneM // description
)

type SearchIncrementalCostCallbackFn func(IncCostMessage, string, uint64)

Thoughts ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah i've renamed the messages and query types, thanks

search/util.go Outdated Show resolved Hide resolved
abhinavdangeti
abhinavdangeti previously approved these changes Jun 12, 2023
Copy link
Member

@abhinavdangeti abhinavdangeti left a comment

Choose a reason for hiding this comment

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

Couple comments, looks good otherwise.

@@ -486,14 +486,14 @@ func (ss *SearchStatus) Merge(other *SearchStatus) {
// A SearchResult describes the results of executing
// a SearchRequest.
type SearchResult struct {
Copy link
Member

Choose a reason for hiding this comment

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

Would you add commentary above this construct explaining what each of the response attribute stands for. This would then include what our definition for Cost is - the user can benefit from this with godocs.

search.go Outdated
Request *SearchRequest `json:"request"`
Hits search.DocumentMatchCollection `json:"hits"`
Total uint64 `json:"total_hits"`
Cost uint64 `json:"search_cost"`
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the json bit should simply be cost - given that this is already part of SearchResult.

@abhinavdangeti abhinavdangeti dismissed their stale review June 12, 2023 19:21

Couple comments need addressing.

index_impl.go Outdated
totalBytesRead += storedFieldsBytes
totalSearchCost += storedFieldsBytes

search.RecordSearchCost(ctx, search.AddM, storedFieldsBytes)
Copy link
Member

Choose a reason for hiding this comment

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

Make this one call as opposed to per hit.

@Thejas-bhat Thejas-bhat merged commit c4a521b into blevesearch:master Jun 13, 2023
ns-codereview pushed a commit to couchbase/cbft that referenced this pull request Jun 14, 2023
- The main approach used over here is leveraging the callbacks that
can be set in the context over which the search is performed.
- Bleve side of things invokes this callback whenever it reaches a
point where the bytes have to be converted and metered against regulator.
  - blevesearch/bleve#1829
- Also, removing the old APIs for the metering along read paths, as we
are now using callbacks.

Change-Id: I500e87f1e5ea4ffbf0ec254c8fc36ece0328a904
Reviewed-on: https://review.couchbase.org/c/cbft/+/191695
Well-Formed: Build Bot <[email protected]>
Tested-by: <[email protected]>
Reviewed-by: <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants