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

chore: limit queries to ds #2446

Merged
merged 8 commits into from Sep 21, 2022
Merged

chore: limit queries to ds #2446

merged 8 commits into from Sep 21, 2022

Conversation

BonapartePC
Copy link
Contributor

@BonapartePC BonapartePC commented Sep 15, 2022

Description

Two changes are made in this PR:

  1. Add stats for the number of DS hits made per query
  2. Limit the number of DS hits per query

Notion Ticket

https://www.notion.so/rudderstacks/Add-stats-for-the-number-of-DS-per-query-41c957dab7eb414397cd7653a7c65701
https://www.notion.so/rudderstacks/Limit-the-number-of-DS-queries-per-jobsdb-Get-4db41289310940a8b49ae2af7b36f6f3

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@BonapartePC BonapartePC marked this pull request as draft September 15, 2022 11:41
enterprise/replay/replay.go Outdated Show resolved Hide resolved
jobsdb/jobsdb.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 16, 2022

Codecov Report

Base: 38.56% // Head: 38.67% // Increases project coverage by +0.11% 🎉

Coverage data is based on head (3647c0e) compared to base (45936bb).
Patch coverage: 79.66% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2446      +/-   ##
==========================================
+ Coverage   38.56%   38.67%   +0.11%     
==========================================
  Files         166      166              
  Lines       36636    36674      +38     
==========================================
+ Hits        14127    14182      +55     
+ Misses      21595    21576      -19     
- Partials      914      916       +2     
Impacted Files Coverage Δ
jobsdb/jobsdb.go 69.12% <77.35%> (+0.31%) ⬆️
jobsdb/unionQuery.go 86.16% <100.00%> (+0.27%) ⬆️
utils/httputil/server.go 80.76% <0.00%> (-11.54%) ⬇️
config/backend-config/backend-config.go 69.88% <0.00%> (+0.56%) ⬆️
processor/processor.go 72.09% <0.00%> (+0.82%) ⬆️
config/backend-config/namespace_config.go 78.62% <0.00%> (+2.29%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@BonapartePC BonapartePC marked this pull request as ready for review September 16, 2022 05:07
app/apphandlers/processorAppHandler.go Outdated Show resolved Hide resolved
app/apphandlers/processorAppHandler.go Outdated Show resolved Hide resolved
jobsdb/jobsdb.go Outdated Show resolved Hide resolved
jobsdb/jobsdb.go Outdated Show resolved Hide resolved
jobsdb/jobsdb.go Outdated Show resolved Hide resolved
for _, ds := range dsList {
unprocessedJobs, err := jd.getUnprocessedJobsDS(ctx, ds, true, params)
if dsLimit > 0 && dsQueryCount >= dsLimit {
Copy link
Contributor

@atzoum atzoum Sep 19, 2022

Choose a reason for hiding this comment

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

it would be useful to have another counter stat here to know how often we are reaching limits our

Copy link
Member

Choose a reason for hiding this comment

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

What is the default max dsLimit?

Copy link
Contributor

Choose a reason for hiding this comment

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

the default is no limit

jobsdb/jobsdb.go Outdated Show resolved Hide resolved
jobsdb/unionQuery.go Outdated Show resolved Hide resolved
jobsdb/unionQuery.go Outdated Show resolved Hide resolved
@atzoum
Copy link
Contributor

atzoum commented Sep 19, 2022

@BonapartePC let's add a test verifying this new jobsDB configuration option

jobsdb/unionQuery.go Outdated Show resolved Hide resolved
jobsdb/unionQuery.go Outdated Show resolved Hide resolved
jobsdb/unionQuery.go Outdated Show resolved Hide resolved
jobsdb/unionQuery.go Outdated Show resolved Hide resolved
return res.Jobs
}

t.Run("Test cache with ds limit as one", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@atzoum atzoum left a comment

Choose a reason for hiding this comment

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

thank you @BonapartePC for addressing all comments!

Comment on lines +4333 to +4334
dsQueryCount := 0
var dsLimit int
Copy link
Member

Choose a reason for hiding this comment

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

[minor] for consistency and staying idiomatic

Suggested change
dsQueryCount := 0
var dsLimit int
var dsQueryCount int
var dsLimit int

Comment on lines +4571 to +4573
if dsHit {
dsQueryCount++
}
Copy link
Member

Choose a reason for hiding this comment

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

We only increase dsQueryCount when a dsHit takes place, and the decision to stop is based on that.

What if dsQueryCount:

  1. was measured regardless of queries hit ?
  2. we stopped early once the dsQueryCount was reached and we had non-zero data.

Letting

The current approach makes sense, but I feel it doesn't penalise queries early enough when we have sparse entries.

Assume we have 200 tables and data are only on in table 3:

  • first one
  • one in the middle
  • one in the end

Now, this algorithm will scan all 200 tables twice until the cache kicks in and avoid the lookup in some tables.

With the approaches I am suggesting, it will require 5 queries for the tables to be scanned, but those queries will be bounded.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lvrach a dsHit happens whenever we query the dataset, regardless if the query returns results or not.
The only occasions where dsHit will be returned as false are:

  1. If we have a cache hit (no jobs & no query)
  2. An error is returned for whatever reason

Copy link
Member

Choose a reason for hiding this comment

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

Got it, my bad it wasn't clear from the diff.

A small comment about what getProcessedJobsDS returns would be useful here.

@cisse21 cisse21 merged commit 082b9f5 into master Sep 21, 2022
@cisse21 cisse21 deleted the chore.limitDSQuery branch September 21, 2022 10:25
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.

None yet

5 participants