Commit ecaeb56
Speed up parallel row-copy: overlap range calc, drop per-batch barrier, cut per-chunk round-trips
The --chunk-concurrent-size parallel row-copy only ran the INSERTs in
parallel; the boundary calculation and the per-chunk transaction overhead
serialized work and capped the achievable speedup well below the hardware's
parallel-insert ceiling. This addresses three of those caps.
Prefetch range producer (overlap serialized boundary calc with INSERTs):
- A single dedicated producer goroutine is the sole caller of
CalculateNextIterationRangeEndValues and streams pre-computed ranges into a
buffered channel, so boundary scans now overlap the parallel INSERTs of
earlier work instead of stalling between batches.
- Split iterateChunks into iterateChunksSingle (unchanged single-threaded
semantics) and iterateChunksConcurrent.
- Size the applier pool for concurrentSize + producer + headroom.
#1 Per-chunk round-trips (applier.go):
- ApplyIterationInsertQuery sent BEGIN / SET SESSION / INSERT / COMMIT as four
round-trips per chunk. It now sends "SET SESSION ...; INSERT ..." as a single
autocommit, multi-statement round-trip on one pinned connection. The applier
pool already enables multiStatements + interpolateParams + autocommit;
RowsAffected() reports the INSERT (last statement), and the optional
SHOW WARNINGS runs on the same pinned connection. 4 round-trips -> 1.
#2 Persistent worker pool (migrator.go):
- Replace the per-batch errgroup+g.Wait barrier (which stalled N workers on
the slowest chunk every N chunks) with continuous dispatch to an errgroup
bounded by SetLimit(concurrentSize) for a 200ms time quantum. Workers stay
saturated; the only barrier is at the quantum boundary. The time bound keeps
executeWriteFuncs returning to apply binlog events and re-check throttling,
preserving row-copy/event mutual exclusion.
Checkpoints record the last contiguous completed range (not the producer's
prefetched cursor), so resume restarts from fully-copied data.
Benchmarked on MySQL 8.0.46 (innodb_autoinc_lock_mode=2), 2.1M rows: copy time
vs the prior parallel impl improved up to 32% (chunk=200, conc=4: 22s->15s;
chunk=1000, conc=8: 8s->6s). Data integrity verified by row count + checksum.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent de32943 commit ecaeb56
3 files changed
Lines changed: 278 additions & 137 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
| |||
958 | 963 | | |
959 | 964 | | |
960 | 965 | | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
961 | 973 | | |
962 | 974 | | |
963 | 975 | | |
| |||
981 | 993 | | |
982 | 994 | | |
983 | 995 | | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
984 | 1001 | | |
985 | | - | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
986 | 1005 | | |
987 | 1006 | | |
988 | 1007 | | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
| 1008 | + | |
993 | 1009 | | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
| 1010 | + | |
998 | 1011 | | |
999 | 1012 | | |
1000 | 1013 | | |
1001 | 1014 | | |
1002 | 1015 | | |
1003 | 1016 | | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
| 1017 | + | |
1015 | 1018 | | |
1016 | 1019 | | |
1017 | 1020 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | 1021 | | |
1039 | 1022 | | |
1040 | 1023 | | |
| |||
1054 | 1037 | | |
1055 | 1038 | | |
1056 | 1039 | | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
1057 | 1075 | | |
1058 | 1076 | | |
1059 | 1077 | | |
| |||
0 commit comments