-
Notifications
You must be signed in to change notification settings - Fork 10
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 rate.Limiter to RunConfiguration #65
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3,17 +3,18 @@ package loadgen | |||||||
import ( | ||||||||
"context" | ||||||||
"fmt" | ||||||||
"go.temporal.io/api/enums/v1" | ||||||||
"go.temporal.io/api/operatorservice/v1" | ||||||||
"path/filepath" | ||||||||
"runtime" | ||||||||
"strconv" | ||||||||
"strings" | ||||||||
"time" | ||||||||
|
||||||||
"github.com/temporalio/omes/loadgen/kitchensink" | ||||||||
"go.temporal.io/api/enums/v1" | ||||||||
"go.temporal.io/api/operatorservice/v1" | ||||||||
"go.temporal.io/sdk/client" | ||||||||
"go.uber.org/zap" | ||||||||
"golang.org/x/time/rate" | ||||||||
) | ||||||||
|
||||||||
type Scenario struct { | ||||||||
|
@@ -110,6 +111,9 @@ func (s *ScenarioInfo) ScenarioOptionInt(name string, defaultValue int) int { | |||||||
const DefaultIterations = 10 | ||||||||
const DefaultMaxConcurrent = 10 | ||||||||
|
||||||||
// DefaultRateLimiter is unlimited | ||||||||
var DefaultRateLimiter = rate.NewLimiter(rate.Inf, 0) | ||||||||
|
||||||||
Comment on lines
+114
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Seems a nil limiter is supported at runtime |
||||||||
type RunConfiguration struct { | ||||||||
// Number of iterations to run of this scenario (mutually exclusive with Duration). | ||||||||
Iterations int | ||||||||
|
@@ -119,6 +123,8 @@ type RunConfiguration struct { | |||||||
// Maximum number of instances of the Execute method to run concurrently. | ||||||||
// Default is DefaultMaxConcurrent. | ||||||||
MaxConcurrent int | ||||||||
// Rate limiter to be Wait-ed before each iteration. | ||||||||
Limiter *rate.Limiter | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Quite a bit more flexible |
||||||||
} | ||||||||
|
||||||||
func (r *RunConfiguration) ApplyDefaults() { | ||||||||
|
@@ -128,6 +134,9 @@ func (r *RunConfiguration) ApplyDefaults() { | |||||||
if r.MaxConcurrent == 0 { | ||||||||
r.MaxConcurrent = DefaultMaxConcurrent | ||||||||
} | ||||||||
if r.Limiter == nil { | ||||||||
r.Limiter = DefaultRateLimiter | ||||||||
} | ||||||||
Comment on lines
+137
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Seems a nil rate limiter is supported at runtime |
||||||||
} | ||||||||
|
||||||||
// Run represents an individual scenario run (many may be in a single instance (of possibly many) of a scenario). | ||||||||
|
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.
Why is this repeated here when it's stored on
config
? In fact, it seems this field is read but never written - I'm not sure anything's actually happening yet.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.
🤦 You're totally right. This is a leftover from my initial draft hardcoded implementation.
I've fixed it, now the construction like this works as expected: