-
Notifications
You must be signed in to change notification settings - Fork 0
Database Performance Optimizations #8
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
base: db-cleanup-baseline
Are you sure you want to change the base?
Conversation
… deadlocks on MySQL (#80329) * Split subquery when cleaning annotations * update comment * Raise batch size, now that we pay attention to it * Iterate in batches * Separate cancellable batch implementation to allow for multi-statement callbacks, add overload for single-statement use * Use split-out utility in outer batching loop so it respects context cancellation * guard against empty queries * Use SQL parameters * Use same approach for tags * drop unused function * Work around parameter limit on sqlite for large batches * Bulk insert test data in DB * Refactor test to customise test data creation * Add test for catching SQLITE_MAX_VARIABLE_NUMBER limit * Turn annotation cleanup test to integration tests * lint --------- Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
Codoki PR ReviewSummary: Fix batch deletes to avoid deadlocks, correct test compile, tame logging Issues (Critical & High only)
Showing top 1 issues. Critical: 0, High: 1. See inline suggestions for more. Key Feedback (click to expand)
Confidence: 3/5 — Needs work before merge (1 high · status: Requires changes) React with 👍 or 👎 if you found this review useful. |
| } | ||
| return err | ||
| }) | ||
| require.NoError(t, err) |
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.
| require.NoError(t, err) | |
| ```go | |
| end := i + batchsize | |
| if end > len(newAnnotations) { | |
| end = len(newAnnotations) | |
| } | |
| _, err := sess.InsertMulti(newAnnotations[i:end]) |
| ids, err := r.fetchIDs(ctx, "annotation", cond) | ||
| if err != nil { | ||
| return 0, err | ||
| } |
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.
🔷 Medium: Excessive error-level logging with full ID lists will flood logs and slow down cleanup. Use debug level and avoid logging IDs to keep logs lightweight (apply similarly to the other cleanup logs).
| } | |
| ```go | |
| r.log.Debug("Annotations to clean by time", "count", len(ids), "cond", cond) |
| srv.cleanUpTmpFiles(ctx) | ||
|
|
||
| ticker := time.NewTicker(time.Minute * 10) | ||
| ticker := time.NewTicker(time.Minute * 1) |
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.
🔷 Medium: Increasing the cadence to 1 minute may significantly raise background DB load. Unless driven by a config knob, consider keeping 10 minutes for production stability.
| ticker := time.NewTicker(time.Minute * 1) | |
| ```go | |
| ticker := time.NewTicker(time.Minute * 10) |
Mirrors ai-code-review-evaluation#7 for like-for-like benchmarking.
db-cleanup-baselinedb-cleanup-optimizedOriginal PR excerpt: