Repository navigation
List matching perf - #11014
List matching perf#11014
Conversation
Update a bit more minor tidying
| } | ||
|
|
||
| // Fold any warning seen mid-loop into the terminal result so it isn't lost. | ||
| next.ComputeLimitWarning = next.ComputeLimitWarning || computeLimitWarning |
There was a problem hiding this comment.
this is equivalent, right? going "both ways" was a little confusing at first
| next.ComputeLimitWarning = next.ComputeLimitWarning || computeLimitWarning | |
| next.ComputeLimitWarning = computeLimitWarning |
There was a problem hiding this comment.
? not sure I understand your comment actually. This is putting the warning into the next value, which is then checked in s.checkNextScheduleResult
There was a problem hiding this comment.
line 132:
computeLimitWarning = computeLimitWarning || next.ComputeLimitWarning
merges the value from next into the separate bool, and then this
next.ComputeLimitWarning = next.ComputeLimitWarning || computeLimitWarning
merges it from the separate bool back into next
that's what I mean by "both ways". since it's always merged into the separate bool, then the separate bool has the value we want by itself, so we can just assign it simply, we don't have to merge back. right? or did I mis-read it?
There was a problem hiding this comment.
oh, I see what you mean, yeah, I had to stare at that for a while and I still got it wrong (At first I thought it was shadowing the variable, but that's not the case).
I think it must be this way because:
- It's that way because the quite-hard-to-read for loop (line 131) terminates on the final / likely problematic iteration, so probably the value we need to capture for this error case is most likely only going to be
131: next.ComputeLimitWarning = next.ComputeLimitWarning || computeLimitWarning
^^^ for loop terminated so this wasn't foldednextis reassigned in the loop, so we can't just fold it on itself
3c0ed7e to
94ec0fb
Compare
| func NewSpecBuilder(dc *dynamicconfig.Collection) *SpecBuilder { | ||
| return &SpecBuilder{ | ||
| warnIterations: dynamicconfig.SchedulerSpecWarnIterations.Get(dc), | ||
| maxIterations: dynamicconfig.SchedulerSpecMaxIterations.Get(dc), |
There was a problem hiding this comment.
@dnr I hope this is simpler, removed all the getters/setters and passing the fn directly down) to be evaluated in side-effect
There was a problem hiding this comment.
much simpler, yeah.
the common pattern in the codebase is to keep the actual dynamicconfig.Collection somewhat isolated from the application logic and pass in only the getters. see the big structs of getters for frontend/history/matching/worker, etc. or just the first random example I found: https://github.com/temporalio/temporal/blob/main/common/rpc/interceptor/slow_request_logger.go#L24
I wouldn't block it on this point but you might want to refactor it later.
(to be clear I'm not saying I like this pattern! personally I sometimes wish we did it this way. I'm just arguing for consistency)
There was a problem hiding this comment.
Updated, I don't feel strongly
| } | ||
|
|
||
| // Fold any warning seen mid-loop into the terminal result so it isn't lost. | ||
| next.ComputeLimitWarning = next.ComputeLimitWarning || computeLimitWarning |
There was a problem hiding this comment.
line 132:
computeLimitWarning = computeLimitWarning || next.ComputeLimitWarning
merges the value from next into the separate bool, and then this
next.ComputeLimitWarning = next.ComputeLimitWarning || computeLimitWarning
merges it from the separate bool back into next
that's what I mean by "both ways". since it's always merged into the separate bool, then the separate bool has the value we want by itself, so we can just assign it simply, we don't have to merge back. right? or did I mis-read it?
| // Simulated dynamic-config change: a much lower hard limit. Replay must still be | ||
| // deterministic because the recorded next times come from SideEffect markers. | ||
| require.NoError(t, replayWith(1000, filename), | ||
| "replay after a dynamic-config change should still be deterministic: %s", filename) |
There was a problem hiding this comment.
we don't have a history with a spec that exceeds the limit, right? so this is kind of a no-op for now?
There was a problem hiding this comment.
it's been added with service/worker/scheduler/testdata/replay_compute_limit_exceeded.json.gz. The key point was that:
- Hitting the limit did indeed error out the scehdule.
- Updating the limit didn't cause nondeterminitism
- It was able to continue after running updateSchedule, but (unsurprisingly I guess) not otherwise. It takes an active 'poke' in this case.
There was a problem hiding this comment.
| func NewSpecBuilder(dc *dynamicconfig.Collection) *SpecBuilder { | ||
| return &SpecBuilder{ | ||
| warnIterations: dynamicconfig.SchedulerSpecWarnIterations.Get(dc), | ||
| maxIterations: dynamicconfig.SchedulerSpecMaxIterations.Get(dc), |
There was a problem hiding this comment.
much simpler, yeah.
the common pattern in the codebase is to keep the actual dynamicconfig.Collection somewhat isolated from the application logic and pass in only the getters. see the big structs of getters for frontend/history/matching/worker, etc. or just the first random example I found: https://github.com/temporalio/temporal/blob/main/common/rpc/interceptor/slow_request_logger.go#L24
I wouldn't block it on this point but you might want to refactor it later.
(to be clear I'm not saying I like this pattern! personally I sometimes wish we did it this way. I'm just arguing for consistency)
| warnIterations: b.warnIterations, | ||
| maxIterations: b.maxIterations, |
There was a problem hiding this comment.
I'm wondering if it should grab the values at this point and put ints in the CompiledSpec itself. it feels slightly weird to keep that part dynamic when it's "compiled"
There was a problem hiding this comment.
So, we were discussing this briefly, and my limited mental model of the configuration lifecycle of the V1 schedules are that configuration is captured either at startup, in tweakables or, here, in the schedule generation inside a side-effect.
The interest we had was in being able to quickly react to problems identified in the event of some outage or bizzare or slow triggering issue (the last V2 stripe schedules Lina pointed to - rightly - as being a case where the schedules errored and then slept, and then bit us weeks later).
In having the configuration reevaluated at runtime, rather that at an earlier point in time, we felt that we'd be more easily be able to reason about it's operational characteristics. I guess this could either be tweakables or here. I don't feel strongly, but the wiring to get it from tweakables is a little annoying I guess.
| // Each history is replayed twice: once with the "original" (effectively disabled) bound, then | ||
| // again with a much lower bound simulating an operator lowering SchedulerSpecMaxIterations. | ||
| func TestReplaysWithDynamicConfigChange(t *testing.T) { | ||
| files, err := filepath.Glob("testdata/replay_*.json.gz") |
There was a problem hiding this comment.
I was kind of thinking that we'd also add an event history of a schedule that tripped that 1000-event limit specified.
There was a problem hiding this comment.
good call
There was a problem hiding this comment.
It's been added with service/worker/scheduler/testdata/replay_compute_limit_exceeded.json.gz
| warnIterations: b.warnIterations, | ||
| maxIterations: b.maxIterations, |
## What changed? Cherry-picks #11014 into cloud/157. ## Why? - Critical performance fix. --------- Co-authored-by: David Porter <[email protected]>
## What changed? Cherry-picks #11014 into cloud/158. ## Why? - Critical performance fix. --------- Co-authored-by: David Porter <[email protected]>
## What changed? Cherry-picks #11014 into cloud/158. ## Why? - Critical performance fix. Co-authored-by: David Porter <[email protected]>
This reverts commit a4e64e1. Signed-off-by: Brooks Newberry <[email protected]>
) ## What changed? Reverts #11091 from `cloud/v1.32.0-157`. ## Why? Required to complete additional release validations. ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) Signed-off-by: Brooks Newberry <[email protected]>
) ## What changed? Reverts #11088 from `cloud/v1.32.0-158`. ## Why? Required to complete additional release validations ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) Signed-off-by: Brooks Newberry <[email protected]>
## What changed? This addresses a performance concern in listing some schedules with specs which are excessive in what they exclude by adding a bound (credit to @lina-temporal ) . ## How did you test it? - [X] built - [X] run locally and tested manually - [X] covered by existing tests - [X] added new unit test(s) - [ ] added new functional test(s) ## Potential risks Relatively high risk change, risks breaking V1 schedules extensively if we mess up nondeterministism, will have to roll out with care. There's also the (unlikely) risk that some customers may actually hit the cap. For use-cases where this is happening, the operator should raise the limit and rely on warnings first. --------- Co-authored-by: Lina Jodoin <[email protected]>
…1128) ## What changed? Undo the revert from #11116 ## Why? Changes have been validated. ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) Signed-off-by: Brooks Newberry <[email protected]>
…1127) ## What changed? Undo the revert from #11115 ## Why? Changes have been validated. ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) Signed-off-by: Brooks Newberry <[email protected]>
## What changed? Cherry-picks the PRs labeled `release/1.30.7` onto `release/v1.30.x`, excluding #11014, which will be cherry picked independently List of PRs: - #11190 - Update sqlparser dependency - #11265 - Update ringpop-go and tchannel-go - #11409 - Update sqlparser to v0.1.0 - #11564 - [Visibility][Elasticsearch] Change datetime format to always include nanos component - #11723 - Validate history pagination branch token against mutable state Conflicts were in the dependency pins in `go.mod`/`go.sum`, in test and CI code, and in one production file: - `service/history/configs/config.go` - `NewConfig` on `main` has a `SendRawHistoryBytesToMatchingService` entry that does not exist on this branch. Kept this branch's two `SendRaw*` entries and added only `EnablePaginationTokenBranchValidation` and `EnablePaginationTokenBranchValidationShadowMode`. Two production edits were also needed where git reported no conflict: - `common/persistence/visibility/store/elasticsearch/visibility_store.go` - #11564 carries an incidental refactor to `errors.AsType[*query.ConverterError]`, a Go 1.26 stdlib API. This branch's `go` directive is 1.25.11, so those two call sites are left as `errors.As`. - `.github/workflows/run-tests.yml` - #11564 adds `elasticsearch` to a `CONTAINERS` env var that does not exist here. ## Why? Security and reliability patch release for 1.30.7. ## How did you test it? - [X] built - [ ] run locally and tested manually - [X] covered by existing tests - [X] added new unit test(s) - [ ] added new functional test(s) ## Potential risks `EnablePaginationTokenBranchValidation` defaults to `true`, so #11723's rejection path is live as soon as this ships. --------- Co-authored-by: Rodrigo Zhou <[email protected]> Co-authored-by: Prathyush PV <[email protected]>
Cherry-pick of #11014 (`c10c730e5`) onto `release/v1.30.x`. The change is a bit different to the original PR (#11014), in that that: - Some chunks around the ListFutureActionTimes in Schedules V2 is shaped slightly different, but V2 isn't even enabled and its' guarded nonetheless by the spec changes - Some test coverage from the earlier patch was not included owing to it relying on a bunch of test refactoring that happened in the intervening time. ## LLM summary: What changed? Bounds the schedule spec next-time search so an over-excluded spec (e.g. mirrored include/exclude calendars) can't spin toward `maxCalendarYear`. `GetNextTime` now returns `(GetNextTimeResult, error)`, with a non-fatal warn threshold and a hard bound, surfaced as `schedule_compute_limit_warning` / `schedule_compute_limit_exceeded`. Both bounds are new dynamic config: `scheduler.specWarnIterations` (default 86,400) and `scheduler.specMaxIterations` (default 1,209,600). ## Backport deltas vs. the original PR The CHASM scheduler on this branch predates a lot of main, so several hunks had no target and were dropped: - `handler_test.go` — file doesn't exist here (modify/delete conflict) - `export_test.go` — no `NewTestHandler` / migration-state exports - `generator.go` — no `UpdateFutureActionTimes` - `scheduler.go` — no CHASM `ListMatchingTimes` - `workflow_test.go` — the 7 CHASM-migration tests don't exist here - `metric_defs.go` — took only the two new counters; the ~12 surrounding V2 metrics in the conflict block aren't on this branch Adapted: - `spec_processor.go` — `checkNextScheduleResult` uses `s.metricsHandler`; main's namespace-tagged `metricsHandler` local doesn't exist here, so the parameter was dropped. Also dropped `droppedCount` / `recordedGenerateLatency` / `limitReached` (main-only). - `workflow.go`, `export_test.go` — `schedulerWorkflowWithSpecBuilder` keeps its 3-arg signature (no CHASM-migration closures). - `helper_test.go` — the upstream diff added `newLegacySpecBuilder` against a different harness; reset the file and added just that helper. - `spec_processor_test.go` — the two new tests used `newTestEnv(t)` and an error-returning `NewScheduler`; ported to this branch's `setupSchedulerForTest(t)`. ## Omitted **`TestMirroredIncludeExcludeSpec`** (functional, 217 lines) is not included — it's written against `testcore.NewEnv` + `testcore.WithDynamicConfig`, neither of which exists on this branch (only `WithDynamicConfigOverrides` on the old suite base). Porting it means a rewrite in the old suite idiom. Happy to do that if we want it before merge. The mechanism is still covered by unit tests that did land: `TestGetNextTimeComputeLimit{Exceeded,Warning,WarningThenResolves}`, `TestProcessTimeRange_ComputeLimit{Exceeded,Warning}`, and `TestReplaysWithDynamicConfigChange` with its new corpus. ## How did you test it? - [x] built (`go build ./...`) - [x] covered by existing tests - [x] added new unit test(s) — ported from the original PR - [ ] added new functional test(s) — see Omitted above `go test` passes on `service/worker/scheduler`, `chasm/lib/scheduler`, `common/dynamicconfig`, `common/metrics`, `service/frontend`. `golangci-lint run --new-from-rev=HEAD` is clean (the 12 findings in these packages are all pre-existing on the branch). `gendynamicconfig` shows no drift. ## Potential risks Same as the original: this touches V1 next-time computation, so nondeterminism is the main hazard. The replay corpus tests pass, and the error is swallowed on the `getNextTimeV1` / `getNextTime` side-effect paths, so cached results are unchanged in shape. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
## What changed? Cherry-pick of c10c730 ("List matching perf", #11014) onto `release/v1.31.x`. Adds a compute bound to the schedule spec next-time search (`scheduler.specMaxIterations` hard bound, `scheduler.specWarnIterations` warn threshold) so over-excluded specs can't burn unbounded CPU, plus the `schedule_compute_limit_exceeded` / `schedule_compute_limit_warning` metrics. ## Cherry-pick deviations The commit did not apply cleanly. Resolutions, all mechanical: - **`service/worker/scheduler/workflow.go`** — `schedulerWorkflowWithSpecBuilder` takes `enableCHASMMigration bool` on 1.31.x rather than main's two `func() bool` closures. Kept the release-branch signature; only the `NewSpecBuilder(...)` construction was taken from the cherry-pick. - **`service/worker/scheduler/export_test.go`** (new file) — same signature adaptation. - **`service/worker/scheduler/workflow_test.go`** — took the release-branch content and applied only this commit's real change (`NewSpecBuilder()` → `newSpecBuilderForTest(0, 0)`). The conflict hunks were drift from the migration-closure change, which is not part of this commit. - **`common/metrics/metric_defs.go`** — the conflict region spanned a large block of metrics 1.31.x does not have. Took only the two metrics this commit adds. - **`chasm/lib/scheduler/scheduler_test.go`** — no change needed; 1.31.x's copy does not reference `legacyscheduler.NewSpecBuilder`. - **`tests/schedule_test.go` — DROPPED.** The four added functional tests (`TestMirroredIncludeExcludeSpec`, `TestMirroredIncludeExcludeSpecOnUpdate`, `TestScheduleFarFutureActionTimes`, `TestScheduleManyCalendars`) depend on `tests/` harness helpers that only exist on main (`createSchedule`, `startWorkflowAction`, `chasmContextFactory`, `registerCountingWorkflow`, `intervalSpec`, `calendarSpec`, `await.RequireTruef`, and a `scheduleCommonOpts(t)` signature 1.31.x does not have). Back-porting them would drag in the functional-test harness refactor — out of scope for a release branch. The behaviour is still covered by the unit tests below. ## How did you test it? - [X] `go build ./...` clean - [X] `go vet` on all touched packages — only pre-existing `admin_handler_test.go` lock-copy warnings, unrelated - [X] `go test ./service/worker/scheduler/...` pass - [X] `go test ./chasm/lib/scheduler/... ./common/dynamicconfig/... ./common/metrics/...` pass - [X] `TestReplays` and `TestReplaysWithDynamicConfigChange` pass, including the new `replay_compute_limit_exceeded.json.gz` fixture — this is the nondeterminism guard for the change - [ ] functional tests (dropped, see above) ## Potential risks Same as the original PR: this touches V1 schedule next-time computation, so the nondeterminism risk is the main concern. The replay test with the new fixture covers it — scheduling decisions live in SideEffect/MutableSideEffect markers, so replay returns recorded values rather than recomputing against new limits. Defaults are permissive (hard bound ~1.2M iterations, warn at 86400), so no existing schedule should hit the cap without an operator lowering it. Reduced coverage vs. main on this branch because the functional tests were dropped. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Lina Jodoin <[email protected]>
What changed?
This addresses a performance concern in listing some schedules with specs which are excessive in what they exclude by adding a bound (credit to @lina-temporal ) .
How did you test it?
Potential risks
Relatively high risk change, risks breaking V1 schedules extensively if we mess up nondeterministism, will have to roll out with care. There's also the (unlikely) risk that some customers may actually hit the cap. For use-cases where this is happening, the operator should raise the limit and rely on warnings first.