Ghostferry binlog streamer lag with large source write volume due to misconfigured BinlogEventBatchSize?
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 30/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Go
- Estrellas
- 858
- Forks
- 77
- Merge medio
- 10 d 4 h
- PR fusionados (30 d)
- 4
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Shopify/ghostferry
-
Gradual copy throttle recoveryAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
Shopify/ghostferry#471 · 1 comentario ·
-
Trouble with virtual generated columnsPosiblemente ocupada @driv3r la tomó hace 222 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
Shopify/ghostferry#338 · 7 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Shopify/ghostferry#318 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Shopify/ghostferry#306 ·
-
Ghostferry misses data for PK values of <= 0Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoBug
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Shopify/ghostferry#305 · 4 comentarios ·
Todos los issues de Shopify/ghostferry
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
kagent-dev/kagent#3792 ·
Los mantenedores suelen responder en 1 día
-
ai-driven-qa bug claude Minor
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
linagora/cozy-stack#5374 ·
Los mantenedores suelen responder en 1 día
-
Bug: Potential leakageAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
google/certificate-transparency-go#1859 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: gate 缺失Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 64/100
newrelic/newrelic-cli#1958 ·
Los mantenedores suelen responder en 1 día