-
Notifications
You must be signed in to change notification settings - Fork 22
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
BAAS-28597: Add counter for limiter wait calls #117
Changes from 5 commits
0ae652c
ea92633
9824c33
5edfab1
c0dc87a
9796a86
d861907
e07d007
c4ada0f
8b8c99f
5f81ce0
760c1e6
43a5dab
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 | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |||||
"strings" | ||||||
"sync" | ||||||
"sync/atomic" | ||||||
"time" | ||||||
|
||||||
"github.com/dop251/goja/unistring" | ||||||
) | ||||||
|
@@ -617,17 +618,22 @@ func (vm *vm) run() { | |||||
ctx = context.Background() | ||||||
} | ||||||
|
||||||
if waitErr := vm.r.limiter.WaitN(ctx, vm.r.limiterTicksLeft); waitErr != nil { | ||||||
if vm.r.vm.ctx == nil { | ||||||
panic(waitErr) | ||||||
} | ||||||
if ctxErr := vm.r.vm.ctx.Err(); ctxErr != nil { | ||||||
panic(ctxErr) | ||||||
} | ||||||
if strings.Contains(waitErr.Error(), "would exceed") { | ||||||
panic(context.DeadlineExceeded) | ||||||
now := time.Now() | ||||||
r := vm.r.limiter.ReserveN(now, vm.r.limiterTicksLeft) | ||||||
if !r.OK() { | ||||||
panic("failed to make reservation") | ||||||
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
This will keep the same behavior as the |
||||||
} | ||||||
|
||||||
delay := r.DelayFrom(now) | ||||||
if delay > 0 { | ||||||
vm.r.limiterWaitCount++ | ||||||
vm.r.limiterWaitTotalTime += delay.Nanoseconds() | ||||||
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. [nit] thoughts on changing 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. Ooo I like that! Great idea |
||||||
|
||||||
err := sleep(ctx, delay) | ||||||
if err != nil { | ||||||
r.Cancel() | ||||||
panic(err) | ||||||
} | ||||||
panic(waitErr) | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -5606,3 +5612,15 @@ func (s valueStack) MemUsage(ctx *MemUsageContext) (memUsage uint64, newMemUsage | |||||
|
||||||
return memUsage, newMemUsage, nil | ||||||
} | ||||||
|
||||||
// sleep is equivalent to time.Sleep, but is interruptible via context cancelation. | ||||||
func sleep(ctx context.Context, duration time.Duration) error { | ||||||
timer := time.NewTimer(duration) | ||||||
defer timer.Stop() | ||||||
select { | ||||||
case <-ctx.Done(): | ||||||
return ctx.Err() | ||||||
case <-timer.C: | ||||||
return nil | ||||||
} | ||||||
} |
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.
@arahmanan the baas counterpart will be to log the LimiterWaitCount when the function execution finishes similar to how we log
Ticks()
. (This could also be a prometheus counter potentially, or perhaps I can piggyback on the Ticks log and include limiterWaitCount... we can discuss in the BAAS pr though)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.
oh I like the idea of adding it to the ticks log! If we do that, adding a new prom metric won't be necessary.