mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +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.
|
||||
* 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
|
||||
* some more data in a loop and wait a bit if data is not available, but
|
||||
* don't wait more than 100 ms total. */
|
||||
* some more data in a loop as soon as there is a good chance more data
|
||||
* will come. If it looks like we are wasting time, we abort (this
|
||||
* happens after 20 ms without new data). */
|
||||
int nodata = 0;
|
||||
for (j = 0; j < 100; j++) {
|
||||
ssize_t nread_from_parent = aofReadDiffFromParent();
|
||||
printf("%lld\n", (long long) nread_from_parent);
|
||||
if (nread_from_parent == 0) {
|
||||
mstime_t start = mstime();
|
||||
while(mstime()-start < 1000 && nodata < 20) {
|
||||
if (aeWait(server.aof_pipe_read_data_from_parent, AE_READABLE, 1) <= 0)
|
||||
{
|
||||
nodata++;
|
||||
if (nodata == 10) break;
|
||||
usleep(10000);
|
||||
continue;
|
||||
}
|
||||
nodata = 0; /* Start counting from zero, we stop on N *contiguous*
|
||||
timeouts. */
|
||||
aofReadDiffFromParent();
|
||||
}
|
||||
|
||||
/* Ask the master to stop sending diffs. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user