Ghostferry binlog streamer lag with large source write volume due to misconfigured BinlogEventBatchSize?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 30/100
Direzione di ricerca
Start with binlog_writer.go, especially the BinlogStreamer channel setup and the BinlogWriter read/write loop described in the issue, then inspect how BinlogEventBatchSize is configured. Use the blocking-profile evidence and the stated m, R, and o model to define how batch sizing or capacity measurement should work. Done should include a concrete way to prevent avoidable streamer lag or detect when the target cannot keep up.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Whne the source experiences high load, it can sometimes fail to keep up and lag. This is unusable, as binlog streamer lag must be zero during cutover.
Thinking carefully about how Ghostferry works shows us why lag may occur. Ghostferry streams the binlog via the BinlogStreamer component. Once a binlog is read, it is put into a channel with a size of BinlogEventBatchSize (set in the config). This channel is read from the BinlogWriter, a separate go routine, with the following pseudo code:
- The event is read from the channel and appended into a buffer.
- If there are no more events, or if the buffer exceeds
BinlogEventBatchSize, then write to the target.
We can note that during step 2 (during writing to MySQL), the BinlogWriter is not emptying from the channel, but the BinlogStreamer continues to fill the channel. If it takes a long time to write to MySQL, then the channel may be full. This means if the channel is full, the BinlogStreamer will be blocked, as the channel effectively serves as a buffer. In a recent move where we had lag, I took a profile via pprof for 5 seconds and graphed the Synchronization blocking profile, which showed that for 4.84s, the BinlogStreamer is blocked.
Math
There is a possible solution to this: if the buffer is larger, then the write (step 1) may finish before the buffer is full. This means the BinlogStreamer will never block. We can analyze this condition mathematically:
- Let's say the write time taken is denoted as
T. - The
BinlogEventBatchSizeis denoted asB. - The rate at which binlog event is generated on the source is
R. - We can calculate the "optimal" batch size to be
B = T * R(orB = TR) - We know the time it takes to write
Tis a function of theB, as larger batch sizes will take longer to write. - We can assume a simple linear model, where
T = mB + o. We can interpret the parametermto be the (marginal) time needed for writing a single binlog event on the target, andoto be the overhead of a single write operation (think network round trip and other overhead).
Combining the equations from 6 and 4:
B = TR
T = mB + o
B = (mB + o)R
B = mBR + oR
B - mRB = oR
(1 - mR)B = oR
B = oR / (1 - mR)
So the optimal batch size is B = oR / (1 - mR). Unfortunately, we don't have the values to any of these terms. Perhaps in the future Ghostferry can measure these.
However, if MySQL is too slow, Ghostferry cannot keep up at all. This is also shown in the equations. Specifically, if mR >= 1, then B will be a negative number. This is non-physical and thus doesn't work. This "magical expression" is more clear if I give an example. Recall m is the time required to write one event. Suppose m = 0.01 second / event. Recall R is the number of events / second on the source and suppose it is R = 200 events / second. This obviously doesn't work, because the target can only write a maximum of 100 events / second. The generation rate in this example is 200 events / second. mR = 2, which means the optimal batch size doesn't exist.
Recommendations
- For cases where you see binlog streamer lag, try to increase the batch size. If that doesn't work, make MySQL write faster.
- In the future, ghostferry should compute
m,R, ando, to automatically determine "optimal" batch size, and possibly detect cases where it is not possible to keep up.
- Lingua principale
- Go
- Stelle
- 858
- Fork
- 77
- Merge medio
- 10g 4h
- PR unite (30g)
- 4
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Shopify/ghostferry
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
Shopify/ghostferry#471 · 1 commento ·
-
Trouble with virtual generated columnsForse già presa @driv3r l’ha presa 222 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
Shopify/ghostferry#338 · 7 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Shopify/ghostferry#318 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Shopify/ghostferry#306 ·
-
Ghostferry misses data for PK values of <= 0Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaBug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Shopify/ghostferry#305 · 4 commenti ·
Tutte le issue di Shopify/ghostferry
Issue simili
-
[Bug]: gate 缺失Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
Generated cask uses deprecated `postflight` stanza; Homebrew 7 warns on every commandForse già presa @k4kratik l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
sachincool/cruft#4 ·
-
help wanted kind/good-first-issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
knative/func#4191 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
VictoriaMetrics/VictoriaLogs#1965 ·
I maintainer di solito rispondono entro 1 giorno
-
kind/bug sig/ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
kubermatic/dashboard#8540 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno