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

Add option to disable synchronization on creation for auto refresh cache #5940

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Sovietaced
Copy link
Contributor

@Sovietaced Sovietaced commented Oct 30, 2024

Why are the changes needed?

We have an interesting usage pattern of the auto refresh cache.

  • New items can be added to the cache up to 1k QPS.
  • Items are synchronized in batches of 500 items.
  • Items are synchronized once every second.

When items are synchronized in single item batches upon creation it disrupts our batch synchronization strategy and puts a lot of load on the server where task state is being read from. You could tune the rate limiter but it will also affect both single item batch and regular batch synchronization. So the solution we found was to add this option which just doesn't try to add a single item batch when items are created in the cache.

What changes were proposed in this pull request?

Adds an option to the auto refresh cache SyncOnCreate which defaults to true for backwards compatibility.

How was this patch tested?

We run this in production but I also added unit tests.

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Built on top of #5813

Summary by Bito

Introduces 'SyncOnCreate' configuration option for auto-refresh cache system to control immediate synchronization behavior. The feature allows disabling immediate item sync on creation, defaulting to true for backward compatibility. This optimization targets high-load scenarios by enabling batch synchronization instead of individual syncs. Implementation includes configuration changes and corresponding test coverage.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 1

Signed-off-by: Jason Parraga <[email protected]>
Signed-off-by: Jason Parraga <[email protected]>
Signed-off-by: Jason Parraga <[email protected]>
@Sovietaced Sovietaced marked this pull request as ready for review October 30, 2024 06:06
@eapolinario eapolinario requested a review from pvditt December 19, 2024 18:42
@pvditt pvditt mentioned this pull request Jan 14, 2025
3 tasks
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 37.06%. Comparing base (1d9cf5f) to head (6bf73a2).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5940   +/-   ##
=======================================
  Coverage   37.06%   37.06%           
=======================================
  Files        1318     1318           
  Lines      132638   132646    +8     
=======================================
+ Hits        49158    49165    +7     
- Misses      79230    79231    +1     
  Partials     4250     4250           
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 54.33% <ø> (ø)
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 62.29% <ø> (ø)
unittests-flyteidl 7.23% <ø> (ø)
unittests-flyteplugins 53.85% <ø> (ø)
unittests-flytepropeller 42.69% <ø> (ø)
unittests-flytestdlib 55.33% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@flyte-bot
Copy link
Collaborator

flyte-bot commented Jan 16, 2025

Code Review Agent Run #8a272a

Actionable Suggestions - 2
  • flytestdlib/cache/in_memory_auto_refresh_test.go - 1
    • Consider adding initial state validation · Line 98-99
  • flytestdlib/cache/in_memory_auto_refresh.go - 1
Review Details
  • Files reviewed - 2 · Commit Range: e13a6e3..6bf73a2
    • flytestdlib/cache/in_memory_auto_refresh.go
    • flytestdlib/cache/in_memory_auto_refresh_test.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Collaborator

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Auto Refresh Cache Synchronization Control

in_memory_auto_refresh.go - Added SyncOnCreate option to control cache synchronization behavior

in_memory_auto_refresh_test.go - Added test cases to verify SyncOnCreate functionality

Comment on lines +98 to +99
// Cache should be processing
assert.NotEmpty(t, cache.processing)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding initial state validation

Consider adding assertions to verify the initial state of cache items before triggering the sync. This would help validate that items are properly initialized with val: 0 before being synced to val: 10.

Code suggestion
Check the AI-generated fix before applying
 @@ -97,6 +97,12 @@
 		}
 		// Cache should be processing
 		assert.NotEmpty(t, cache.processing)
 +		// Verify initial values
 +		for i := 1; i <= 10; i++ {
 +			item, err := cache.Get(fmt.Sprintf("%d", i))
 +			assert.NoError(t, err)
 +			assert.Equal(t, 0, item.(fakeCacheItem).val)
 +		}

Code Review Run #8a272a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +244 to +247
if w.syncOnCreate {
batch := make([]ItemWrapper, 0, 1)
batch = append(batch, itemWrapper{id: id, item: item})
w.workqueue.AddRateLimited(&batch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider nil check for workqueue

Consider adding a check for w.workqueue being nil before using it in GetOrCreate. The workqueue field could potentially be nil if initialization failed.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if w.syncOnCreate {
batch := make([]ItemWrapper, 0, 1)
batch = append(batch, itemWrapper{id: id, item: item})
w.workqueue.AddRateLimited(&batch)
if w.syncOnCreate {
if w.workqueue == nil {
return item, fmt.Errorf("workqueue not initialized")
}
batch := make([]ItemWrapper, 0, 1)
batch = append(batch, itemWrapper{id: id, item: item})
w.workqueue.AddRateLimited(&batch)

Code Review Run #8a272a


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Cold PRs
Development

Successfully merging this pull request may close these issues.

3 participants