-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add concurrency control parameters #144
Add concurrency control parameters #144
Conversation
deee4d2
to
7c1799f
Compare
7c1799f
to
ce8478f
Compare
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.
LGTM - please consider the minor comments.
sql/scanner.go
Outdated
if sema != nil { | ||
// Release the slot once the goroutine is done. | ||
sema.Release(1) | ||
} | ||
wg.Done() |
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.
This can be done in a deferred call for more safety (from premature returns like the one you had earlier in case of ctx.Done()
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.
This function currently can't actually, return early, so the effect is the same, but I will add it to a defer
just to to make it more resilient to possible future changes.
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.
Addr bb28f86
// database handles (one per database). | ||
var sema *semaphore.Weighted | ||
if s.config.RepoConfig.MaxOpenConns > 0 { | ||
sema = semaphore.NewWeighted(int64(s.config.RepoConfig.MaxOpenConns)) |
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.
What are we now doing with MaxOpenConns (is it needed any longer)?
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.
Yes, it is still needed. It eventually gets passed all the way down to the sql.DB
instance - see: https://github.com/cyralinc/dmap/blob/main/sql/generic.go#L243
This ultimately means that the number of concurrent queries for a single database will be min(MaxOpenConns, MaxConcurrency)
, since all queries to a database use the same sql.DB
instance.
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.
Sorry, I thought I had approved earlier.
Description of the change
This PR adds some concurrency control parameters which can be useful to tweaking performance/resource usage and dealing with long-running queries.
Type of change
Checklists
Development
Code review
Testing
Unit and manual testing.