-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 query building routines of DML event queries, reducing time and allocations #1459
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arthurschreiber
previously approved these changes
Oct 22, 2024
I believe the failing test case |
danieljoos
force-pushed
the
danieljoos-dml-query-builders
branch
from
October 23, 2024 08:43
0c4db0e
to
4608dcb
Compare
arthurschreiber
previously approved these changes
Oct 23, 2024
Find below the results of some synthetic benchmarks, using the Go benchmarking capabilities. Benchmark Build DML Delete QueryBenchmark functionfunc BenchmarkApplierBuildDMLEventQuery_Delete(b *testing.B) {
columns := sql.NewColumnList([]string{"id", "item_id", "name"})
migrationContext := base.NewMigrationContext()
migrationContext.DatabaseName = "test"
migrationContext.OriginalTableName = "test"
migrationContext.OriginalTableColumns = columns
migrationContext.SharedColumns = columns
migrationContext.MappedSharedColumns = columns
migrationContext.UniqueKey = &sql.UniqueKey{
Name: "unique",
Columns: *columns,
}
applier := NewApplier(migrationContext)
applier.prepareQueries() // comment out in current version
columnValues := sql.ToColumnValues([]interface{}{123, 456, "abc"})
binlogEvent := &binlog.BinlogDMLEvent{
DatabaseName: "test",
DML: binlog.DeleteDML,
WhereColumnValues: columnValues,
}
for range b.N {
_ = applier.buildDMLEventQuery(binlogEvent)
}
} Current version
Updated version
Benchmark Build DML Insert QueryBenchmark functionfunc BenchmarkApplierBuildDMLEventQuery_Insert(b *testing.B) {
columns := sql.NewColumnList([]string{"id", "item_id"})
migrationContext := base.NewMigrationContext()
migrationContext.DatabaseName = "test"
migrationContext.OriginalTableName = "test"
migrationContext.OriginalTableColumns = columns
migrationContext.SharedColumns = columns
migrationContext.MappedSharedColumns = columns
migrationContext.UniqueKey = &sql.UniqueKey{
Name: "unique",
Columns: *columns,
}
applier := NewApplier(migrationContext)
applier.prepareQueries() // comment out in current version
columnValues := sql.ToColumnValues([]interface{}{1234, 5678})
binlogEvent := &binlog.BinlogDMLEvent{
DatabaseName: "test",
DML: binlog.InsertDML,
NewColumnValues: columnValues,
}
for range b.N {
_ = applier.buildDMLEventQuery(binlogEvent)
}
} Current version
Updated version
Benchmark Build DML Update QueryBenchmark functionfunc BenchmarkApplierBuildDMLEventQuery_Update(b *testing.B) {
columns := sql.NewColumnList([]string{"id", "item_id"})
migrationContext := base.NewMigrationContext()
migrationContext.DatabaseName = "test"
migrationContext.OriginalTableName = "test"
migrationContext.OriginalTableColumns = columns
migrationContext.SharedColumns = columns
migrationContext.MappedSharedColumns = columns
migrationContext.UniqueKey = &sql.UniqueKey{
Name: "unique",
Columns: *columns,
}
applier := NewApplier(migrationContext)
applier.prepareQueries() // comment out in current version
columnValues := sql.ToColumnValues([]interface{}{1234, 5678})
binlogEvent := &binlog.BinlogDMLEvent{
DatabaseName: "test",
DML: binlog.UpdateDML,
NewColumnValues: columnValues,
WhereColumnValues: columnValues,
}
for range b.N {
_ = applier.buildDMLEventQuery(binlogEvent)
}
} Current version
Updated version
|
danieljoos
requested review from
rashiq,
meiji163 and
timvaillancourt
as code owners
October 23, 2024 11:45
danieljoos
changed the title
Use query builders for DML event queries
Improve query building routines of DML event queries, reducing time and allocations
Oct 23, 2024
arthurschreiber
approved these changes
Oct 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request adapts the query building routines for DML event queries.
Parts that never change throughout the migration will only be computed once.
Measurements
Tests with production load showed an increase in throughput of around 5-10%.
The tests have been conducted on separate testing replicas.
(🔵 blue: current version, 🔴 red: updated version)
The results of synthetic benchmarks can be found here: #1459 (comment)
script/cibuild
returns with no formatting errors, build errors or unit test errors.