-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
61 lines (51 loc) · 1.92 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package scheduler
// Config configures the Ratelimitter.
type Config struct {
// OPS stands for operations per second and is the amount of operations
// that the scheduler should allow during the course of one second.
OPS float32
// Workers is the amount of goroutine workers that process operations.
// If this is 0 then no worker goroutines will be used and operations will
// be executed synchronously from within the main tick loop.
Workers int
// MaxQueueSize is the maximum size of the operations queue.
// This maximum is always enforced, even when priority-specific
// queue's have a higher maximum queue size.
MaxQueueSize int
// ExecutionBufferSize is the capacity of the buffered channel which
// forwards operations to the various workers.
// This should be as low as possible to keep the scheduler in sync with
// the remote rate limit window as much as possible.
ExecutionBufferSize int
// Fallback is an (optional) operation that will be executed every time that
// no other operations are available. It will be executed from within the
// same loop that processes ticks even if there are workers available.
// This is by design and allows using this hook to refill the operations
// queue whenever it's empty.
Fallback Operation
// PriorityAutoInit sets whether priorities are automatically initialized.
// When this is false, the Scheduler will return an error every time an
// operation uses an uninitialized priority.
PriorityAutoInit bool
// PriorityDefaultCapacity indicates the default capacity of a priority.
// This is only relevant when PriorityAutoInit is true.
PriorityDefaultCapacity int
}
func (c Config) rate() float32 {
if c.OPS <= 0 {
return 1
}
return c.OPS
}
func (c Config) maxops() uint32 {
if c.MaxQueueSize <= 0 {
return ^uint32(0)
}
return uint32(c.MaxQueueSize)
}
func (c Config) opbuf() int {
if c.ExecutionBufferSize <= 0 {
return 1
}
return c.ExecutionBufferSize
}