mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
Better "final read from parent" algorithm in rewriteAppendOnlyFile*(.
We now wait up to 1 second for diff data to come from the parent, however we use poll(2) to wait for more data, and use a counter of contiguous failures to get data for N times (set to 20 experimentally after different tests) as an early stop condition to avoid wasting 1 second when the write traffic is too low.
This commit is contained in:
parent
895409ca78
commit
2de5bab368
19
src/aof.c
19
src/aof.c
@ -1059,17 +1059,20 @@ int rewriteAppendOnlyFile(char *filename) {
|
|||||||
/* Read again a few times to get more data from the parent.
|
/* Read again a few times to get more data from the parent.
|
||||||
* We can't read forever (the server may receive data from clients
|
* We can't read forever (the server may receive data from clients
|
||||||
* fater than it is able to send data to the child), so we try to read
|
* fater than it is able to send data to the child), so we try to read
|
||||||
* some more data in a loop and wait a bit if data is not available, but
|
* some more data in a loop as soon as there is a good chance more data
|
||||||
* don't wait more than 100 ms total. */
|
* will come. If it looks like we are wasting time, we abort (this
|
||||||
|
* happens after 20 ms without new data). */
|
||||||
int nodata = 0;
|
int nodata = 0;
|
||||||
for (j = 0; j < 100; j++) {
|
mstime_t start = mstime();
|
||||||
ssize_t nread_from_parent = aofReadDiffFromParent();
|
while(mstime()-start < 1000 && nodata < 20) {
|
||||||
printf("%lld\n", (long long) nread_from_parent);
|
if (aeWait(server.aof_pipe_read_data_from_parent, AE_READABLE, 1) <= 0)
|
||||||
if (nread_from_parent == 0) {
|
{
|
||||||
nodata++;
|
nodata++;
|
||||||
if (nodata == 10) break;
|
continue;
|
||||||
usleep(10000);
|
|
||||||
}
|
}
|
||||||
|
nodata = 0; /* Start counting from zero, we stop on N *contiguous*
|
||||||
|
timeouts. */
|
||||||
|
aofReadDiffFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ask the master to stop sending diffs. */
|
/* Ask the master to stop sending diffs. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user