diff options
author | antirez <antirez@gmail.com> | 2014-07-05 15:40:08 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-07-05 15:42:24 +0200 |
commit | 2de5bab368fc1ed7630935df8762e3a2679b3453 (patch) | |
tree | dc7f80a8554c38af48ebd99fee71cfb9fa082b32 | |
parent | 895409ca784c38a15719fb6d6a94575212fbc136 (diff) | |
download | redis-2de5bab368fc1ed7630935df8762e3a2679b3453.tar.gz |
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.
-rw-r--r-- | src/aof.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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. */ |