Skip to content
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

Improve task scheduler rate limiter #3860

Merged
merged 5 commits into from
Feb 4, 2023

Conversation

yycptt
Copy link
Member

@yycptt yycptt commented Jan 28, 2023

What changed?

  • Fix task scheduler rate limiter disabling. Previously when disabling, if a task channel is throttled, the throttled flag will never be cleared.
  • Use Allow() instead of Reserve(), to minimize the impact of idle task channel when there's large number of empty namespaces. Keep doing Reserve() & CancelAt() may cause some rps token to be wasted.
  • Add a shadow mode for this rate limiter to emit throttled metrics but no actually block task scheduling.
  • Emit metrics upon throttling.

Why?

How did you test it?

Potential risks

Is hotfix candidate?

@yycptt yycptt requested a review from yux0 January 28, 2023 00:43
@yycptt yycptt requested a review from a team as a code owner January 28, 2023 00:43
Copy link
Contributor

@MichaelSnowden MichaelSnowden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a decorator pattern here instead of a flag argument? That would follow the open-closed principle and reduce branching/entanglement. For example:

fx.Decorate(func(rateLimiter, cfg) RateLimiter {
  return &rateLimiterShadow{rateLimiter, cfg.EnableRateLimiterShadowMode}
}

type rateLimiterShadow {
  RateLimiter
  UseShadow dynamicconfig.BoolPropertyFn
 }

func (t *rateLimiterShadow) Wait(...) ... {
  if t.UseShadow {
  } else {
  }
}

@yycptt
Copy link
Member Author

yycptt commented Jan 30, 2023

Can we use a decorator pattern here instead of a flag argument? That would follow the open-closed principle and reduce branching/entanglement. For example:

fx.Decorate(func(rateLimiter, cfg) RateLimiter {
  return &rateLimiterShadow{rateLimiter, cfg.EnableRateLimiterShadowMode}
}

type rateLimiterShadow {
  RateLimiter
  UseShadow dynamicconfig.BoolPropertyFn
 }

func (t *rateLimiterShadow) Wait(...) ... {
  if t.UseShadow {
  } else {
  }
}

Yeah that's a good idea. Not that easy though since different rate limiter requests need different metrics tag (and we need a way to pass those information in)

But for this change, consider it as a debug build, and all shadow related code will be deleted in next release after the issue was fixed.

Copy link
Contributor

@MichaelSnowden MichaelSnowden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better if this PR were split up into individual changes and we didn't use flag arguments, but given that this will be removed next release, LGTM.

Copy link
Contributor

@MichaelSnowden MichaelSnowden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's difficult for me to review the changes in common/tasks/interleaved_weighted_round_robin.go because the loop involved is so immense. If there's enough time, I'd encourage you to do some preparatory refactoring before adding this change. In particular, there's a complicated mix of blocking, non-blocking checks, usage of loop labels, and synchronization in one function. I'd encourage a more idiomatic Go approach where we use goroutines and select channel loops as opposed to nested loops with non-blocking ready checks

@yycptt yycptt merged commit 008f056 into temporalio:master Feb 4, 2023
@yycptt yycptt deleted the fix-task-processing-rl branch February 4, 2023 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants