Skip to content

Commit

Permalink
config: auto-size concurrent request capacity
Browse files Browse the repository at this point in the history
This just uses a multiple of available cores.

Closes: PROJQUAY-2330
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Jan 17, 2022
1 parent 93a835e commit 2cc4af7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 18 additions & 10 deletions config/indexer.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package config

import "runtime"

// Indexer provides Clair Indexer node configuration
type Indexer struct {
// Scanner allows for passing configuration options to layer scanners.
Expand All @@ -24,7 +26,10 @@ type Indexer struct {
LayerScanConcurrency int `yaml:"layer_scan_concurrency" json:"layer_scan_concurrency"`
// Rate limits the number if index report creation requests.
//
// Any value below 1 is considered unlimited.
// Setting this to 0 will attempt to auto-size this value. Setting a
// negative value means "unlimited." The auto-sizing is a multiple of the
// number of available cores.
//
// The API will return a 429 status code if concurrency is exceeded.
IndexReportRequestConcurrency int `yaml:"index_report_request_concurrency" json:"index_report_request_concurrency"`
// A "true" or "false" value
Expand All @@ -44,7 +49,18 @@ func (i *Indexer) validate(mode Mode) (ws []Warning, err error) {
if i.ScanLockRetry == 0 {
i.ScanLockRetry = DefaultScanLockRetry
}
return i.lint()
if i.IndexReportRequestConcurrency == 0 {
// GOMAXPROCS should be set to the number of cores available.
gmp := runtime.GOMAXPROCS(0)
const wildGuess = 4
i.IndexReportRequestConcurrency = gmp * wildGuess
ws = append(ws, Warning{
path: ".index_report_request_concurrency",
msg: `automatically sizing number of concurrent requests`,
})
}
lws, err := i.lint()
return append(ws, lws...), err
}

func (i *Indexer) lint() (ws []Warning, err error) {
Expand Down Expand Up @@ -75,14 +91,6 @@ func (i *Indexer) lint() (ws []Warning, err error) {
msg: `large values may exceed resource quotas`,
})
}
if i.IndexReportRequestConcurrency < 1 {
// Remove this lint if we come up with a heuristic instead of just
// "unlimited".
ws = append(ws, Warning{
path: ".index_report_request_concurrency",
msg: `unlimited concurrent requests may exceed resource quotas`,
})
}

return ws, nil
}
Expand Down
1 change: 0 additions & 1 deletion config/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func ExampleLint() {
// warning: http listen address not provided, default will be used (at $.http_listen_addr)
// warning: introspection address not provided, default will be used (at $.introspection_addr)
// warning: connection string is empty and no relevant environment variables found (at $.indexer.connstring)
// warning: unlimited concurrent requests may exceed resource quotas (at $.indexer.index_report_request_concurrency)
// warning: connection string is empty and no relevant environment variables found (at $.matcher.connstring)
// warning: updater period is very aggressive: most sources are updated daily (at $.matcher.period)
// warning: update garbage collection is off (at $.matcher.update_retention)
Expand Down

0 comments on commit 2cc4af7

Please sign in to comment.