Skip to content

Commit 2f4e226

Browse files
author
Shlomi Noach
authored
Merge pull request #453 from github/dynamic-dml-batch-size
Dynamic DML batch size; apadting buffer size to match
2 parents d05f0ce + e2c14f5 commit 2f4e226

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

doc/interactive-commands.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Both interfaces may serve at the same time. Both respond to simple text command,
1919
- `sup`: returns a brief status summary of migration progress
2020
- `coordinates`: returns recent (though not exactly up to date) binary log coordinates of the inspected server
2121
- `chunk-size=<newsize>`: modify the `chunk-size`; applies on next running copy-iteration
22+
- `dml-batch-size=<newsize>`: modify the `dml-batch-size`; applies on next applying of binary log events
2223
- `max-lag-millis=<max-lag>`: modify the maximum replication lag threshold (milliseconds, minimum value is `100`, i.e. `0.1` second)
2324
- `max-load=<max-load-thresholds>`: modify the `max-load` config; applies on next running copy-iteration
2425
- The `max-load` format must be: `some_status=<numeric-threshold>[,some_status=<numeric-threshold>...]`'
@@ -52,7 +53,7 @@ While migration is running:
5253
$ echo status | nc -U /tmp/gh-ost.test.sample_data_0.sock
5354
# Migrating `test`.`sample_data_0`; Ghost table is `test`.`_sample_data_0_gst`
5455
# Migration started at Tue Jun 07 11:45:16 +0200 2016
55-
# chunk-size: 200; max lag: 1500ms; max-load: map[Threads_connected:20]
56+
# chunk-size: 200; max lag: 1500ms; dml-batch-size: 10; max-load: map[Threads_connected:20]
5657
# Throttle additional flag file: /tmp/gh-ost.throttle
5758
# Serving on unix socket: /tmp/gh-ost.test.sample_data_0.sock
5859
# Serving on TCP port: 10001
@@ -63,7 +64,7 @@ Copy: 0/2915 0.0%; Applied: 0; Backlog: 0/100; Elapsed: 40s(copy), 41s(total); s
6364
$ echo "chunk-size=250" | nc -U /tmp/gh-ost.test.sample_data_0.sock
6465
# Migrating `test`.`sample_data_0`; Ghost table is `test`.`_sample_data_0_gst`
6566
# Migration started at Tue Jun 07 11:56:03 +0200 2016
66-
# chunk-size: 250; max lag: 1500ms; max-load: map[Threads_connected:20]
67+
# chunk-size: 250; max lag: 1500ms; dml-batch-size: 10; max-load: map[Threads_connected:20]
6768
# Throttle additional flag file: /tmp/gh-ost.throttle
6869
# Serving on unix socket: /tmp/gh-ost.test.sample_data_0.sock
6970
# Serving on TCP port: 10001

go/base/context.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const (
4646
)
4747

4848
const (
49-
HTTPStatusOK = 200
50-
maxBatchSize = 1000
49+
HTTPStatusOK = 200
50+
MaxEventsBatchSize = 1000
5151
)
5252

5353
var (
@@ -451,8 +451,8 @@ func (this *MigrationContext) SetDMLBatchSize(batchSize int64) {
451451
if batchSize < 1 {
452452
batchSize = 1
453453
}
454-
if batchSize > maxBatchSize {
455-
batchSize = maxBatchSize
454+
if batchSize > MaxEventsBatchSize {
455+
batchSize = MaxEventsBatchSize
456456
}
457457
atomic.StoreInt64(&this.DMLBatchSize, batchSize)
458458
}

go/logic/migrator.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ func newApplyEventStructByDML(dmlEvent *binlog.BinlogDMLEvent) *applyEventStruct
5252
return result
5353
}
5454

55-
const (
56-
applyEventsQueueBuffer = 100
57-
)
58-
5955
type PrintStatusRule int
6056

6157
const (
@@ -101,7 +97,7 @@ func NewMigrator() *Migrator {
10197
allEventsUpToLockProcessed: make(chan string),
10298

10399
copyRowsQueue: make(chan tableWriteFunc),
104-
applyEventsQueue: make(chan *applyEventStruct, applyEventsQueueBuffer),
100+
applyEventsQueue: make(chan *applyEventStruct, base.MaxEventsBatchSize),
105101
handledChangelogStates: make(map[string]bool),
106102
}
107103
return migrator
@@ -767,9 +763,10 @@ func (this *Migrator) printMigrationStatusHint(writers ...io.Writer) {
767763
))
768764
maxLoad := this.migrationContext.GetMaxLoad()
769765
criticalLoad := this.migrationContext.GetCriticalLoad()
770-
fmt.Fprintln(w, fmt.Sprintf("# chunk-size: %+v; max-lag-millis: %+vms; max-load: %s; critical-load: %s; nice-ratio: %f",
766+
fmt.Fprintln(w, fmt.Sprintf("# chunk-size: %+v; max-lag-millis: %+vms; dml-batch-size: %+v; max-load: %s; critical-load: %s; nice-ratio: %f",
771767
atomic.LoadInt64(&this.migrationContext.ChunkSize),
772768
atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold),
769+
atomic.LoadInt64(&this.migrationContext.DMLBatchSize),
773770
maxLoad.String(),
774771
criticalLoad.String(),
775772
this.migrationContext.GetNiceRatio(),

go/logic/server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ status # Print a detailed status message
146146
sup # Print a short status message
147147
coordinates # Print the currently inspected coordinates
148148
chunk-size=<newsize> # Set a new chunk-size
149+
dml-batch-size=<newsize> # Set a new dml-batch-size
149150
nice-ratio=<ratio> # Set a new nice-ratio, immediate sleep after each row-copy operation, float (examples: 0 is agrressive, 0.7 adds 70% runtime, 1.0 doubles runtime, 2.0 triples runtime, ...)
150151
critical-load=<load> # Set a new set of max-load thresholds
151152
max-lag-millis=<max-lag> # Set a new replication lag threshold
@@ -187,6 +188,19 @@ help # This message
187188
return ForcePrintStatusAndHintRule, nil
188189
}
189190
}
191+
case "dml-batch-size":
192+
{
193+
if argIsQuestion {
194+
fmt.Fprintf(writer, "%+v\n", atomic.LoadInt64(&this.migrationContext.DMLBatchSize))
195+
return NoPrintStatusRule, nil
196+
}
197+
if dmlBatchSize, err := strconv.Atoi(arg); err != nil {
198+
return NoPrintStatusRule, err
199+
} else {
200+
this.migrationContext.SetDMLBatchSize(int64(dmlBatchSize))
201+
return ForcePrintStatusAndHintRule, nil
202+
}
203+
}
190204
case "max-lag-millis":
191205
{
192206
if argIsQuestion {

0 commit comments

Comments
 (0)