Skip to content

Commit 44b43ef

Browse files
author
Shlomi Noach
authored
Merge pull request #87 from github/nice
added nice-ratio
2 parents b9e5548 + c116d84 commit 44b43ef

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
#
4-
RELEASE_VERSION="0.9.8"
4+
RELEASE_VERSION="0.9.9"
55

66
buildpath=/tmp/gh-ost
77
target=gh-ost

doc/interactive-commands.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ replication lag on to determine throttling
2121
- `max-load=<max-load-thresholds>`: modify the `max-load` config; applies on next running copy-iteration
2222
The `max-load` format must be: `some_status=<numeric-threshold>[,some_status=<numeric-threshold>...]`. For example: `Threads_running=50,threads_connected=1000`, and you would then write/echo `max-load=Threads_running=50,threads_connected=1000` to the socket.
2323
- `critical-load=<load>`: change critical load setting (exceeding given thresholds causes panic and abort)
24+
- `nice-ratio=<ratio>`: change _nice_ ratio: 0 for aggressive, positive integer `n`: for any unit of time spent copying rows, spend `n` units of time sleeping.
2425
- `throttle-query`: change throttle query
2526
- `throttle-control-replicas`: change list of throttle-control replicas, these are replicas `gh-ost` will cehck
2627
- `throttle`: force migration suspend

go/base/context.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type MigrationContext struct {
5858

5959
defaultNumRetries int64
6060
ChunkSize int64
61+
NiceRatio int64
6162
MaxLagMillisecondsThrottleThreshold int64
6263
ReplictionLagQuery string
6364
ThrottleControlReplicaKeys *mysql.InstanceKeyMap

go/cmd/gh-ost/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func main() {
7171
flag.BoolVar(&migrationContext.SwitchToRowBinlogFormat, "switch-to-rbr", false, "let this tool automatically switch binary log format to 'ROW' on the replica, if needed. The format will NOT be switched back. I'm too scared to do that, and wish to protect you if you happen to execute another migration while this one is running")
7272
chunkSize := flag.Int64("chunk-size", 1000, "amount of rows to handle in each iteration (allowed range: 100-100,000)")
7373
defaultRetries := flag.Int64("default-retries", 60, "Default number of retries for various operations before panicking")
74+
flag.Int64Var(&migrationContext.NiceRatio, "nice-ratio", 0, "force being 'nice', imply sleep time per chunk time. Example values: 0 is aggressive. 3: for every ms spend in a rowcopy chunk, spend 3ms sleeping immediately after")
7475

7576
flag.Int64Var(&migrationContext.MaxLagMillisecondsThrottleThreshold, "max-lag-millis", 1500, "replication lag at which to throttle operation")
7677
flag.StringVar(&migrationContext.ReplictionLagQuery, "replication-lag-query", "", "Query that detects replication lag in seconds. Result can be a floating point (by default gh-ost issues SHOW SLAVE STATUS and reads Seconds_behind_master). If you're using pt-heartbeat, query would be something like: SELECT ROUND(UNIX_TIMESTAMP() - MAX(UNIX_TIMESTAMP(ts))) AS delay FROM my_schema.heartbeat")

go/logic/migrator.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ func (this *Migrator) onServerCommand(command string, writer *bufio.Writer) (err
790790
fmt.Fprintln(writer, `available commands:
791791
status # Print a status message
792792
chunk-size=<newsize> # Set a new chunk-size
793+
nice-ratio=<ratio> # Set a new nice-ratio, integer (0 is agrressive)
793794
critical-load=<load> # Set a new set of max-load thresholds
794795
max-load=<load> # Set a new set of max-load thresholds
795796
throttle-query=<query> # Set a new throttle-query
@@ -813,6 +814,16 @@ help # This message
813814
this.printStatus(ForcePrintStatusAndHint, writer)
814815
}
815816
}
817+
case "nice-ratio":
818+
{
819+
if niceRatio, err := strconv.Atoi(arg); err != nil {
820+
fmt.Fprintf(writer, "%s\n", err.Error())
821+
return log.Errore(err)
822+
} else {
823+
atomic.StoreInt64(&this.migrationContext.NiceRatio, int64(niceRatio))
824+
this.printStatus(ForcePrintStatusAndHint, writer)
825+
}
826+
}
816827
case "max-load":
817828
{
818829
if err := this.migrationContext.ReadMaxLoad(arg); err != nil {
@@ -963,11 +974,12 @@ func (this *Migrator) printMigrationStatusHint(writers ...io.Writer) {
963974
))
964975
maxLoad := this.migrationContext.GetMaxLoad()
965976
criticalLoad := this.migrationContext.GetCriticalLoad()
966-
fmt.Fprintln(w, fmt.Sprintf("# chunk-size: %+v; max lag: %+vms; max-load: %s; critical-load: %s",
977+
fmt.Fprintln(w, fmt.Sprintf("# chunk-size: %+v; max lag: %+vms; max-load: %s; critical-load: %s; nice-ratio: %d",
967978
atomic.LoadInt64(&this.migrationContext.ChunkSize),
968979
atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold),
969980
maxLoad.String(),
970981
criticalLoad.String(),
982+
atomic.LoadInt64(&this.migrationContext.NiceRatio),
971983
))
972984
if this.migrationContext.ThrottleFlagFile != "" {
973985
fmt.Fprintln(w, fmt.Sprintf("# Throttle flag file: %+v",
@@ -1264,10 +1276,16 @@ func (this *Migrator) executeWriteFuncs() error {
12641276
select {
12651277
case copyRowsFunc := <-this.copyRowsQueue:
12661278
{
1279+
copyRowsStartTime := time.Now()
12671280
// Retries are handled within the copyRowsFunc
12681281
if err := copyRowsFunc(); err != nil {
12691282
return log.Errore(err)
12701283
}
1284+
if niceRatio := atomic.LoadInt64(&this.migrationContext.NiceRatio); niceRatio > 0 {
1285+
copyRowsDuration := time.Now().Sub(copyRowsStartTime)
1286+
sleepTime := copyRowsDuration * time.Duration(niceRatio)
1287+
time.Sleep(sleepTime)
1288+
}
12711289
}
12721290
default:
12731291
{

0 commit comments

Comments
 (0)