Skip to content

Commit

Permalink
workaround for issue #46
Browse files Browse the repository at this point in the history
- in Windows prior to 8 and Server 2012 there is no GetSystemTimePreciseAsFileTime(), so in case of
  very fast forking - we take 100ms for calculation of "stat_fork_rate"
- fixes #46
  • Loading branch information
tporadowski committed Dec 28, 2019
1 parent ac17be3 commit 5a40a37
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,14 @@ int rewriteAppendOnlyFileBackground(void) {
#endif
/* Parent */
server.stat_fork_time = ustime()-start;
server.stat_fork_rate = (double) (zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024)); /* GB per second. */ WIN_PORT_FIX
//[tporadowski/redis] issue #46: ustime() -> gettimeofday_highres() uses GetSystemTimePreciseAsFileTime when available (Windows 8, Windows Server 2012) or
// falls back to GetSystemTimeAsFileTime which does not have such high resolution, so "stat_fork_time" may be 0 here
#ifdef _WIN32
if (server.stat_fork_time == 0) {
server.stat_fork_time = 100000; //let's pretend it took 100ms (100000 microseconds)
}
#endif
server.stat_fork_rate = (double)(zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024 * 1024 * 1024)); /* GB per second. */ WIN_PORT_FIX
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
if (childpid == -1) {
closeChildInfoPipe();
Expand Down
18 changes: 16 additions & 2 deletions src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,14 @@ int rdbSaveBackground(char *filename, rdbSaveInfo *rsi) {
#endif
/* Parent */
server.stat_fork_time = ustime()-start;
server.stat_fork_rate = (double) (zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024)); /* GB per second. */
//[tporadowski/redis] issue #46: ustime() -> gettimeofday_highres() uses GetSystemTimePreciseAsFileTime when available (Windows 8, Windows Server 2012) or
// falls back to GetSystemTimeAsFileTime which does not have such high resolution, so "stat_fork_time" may be 0 here
#ifdef _WIN32
if (server.stat_fork_time == 0) {
server.stat_fork_time = 100000; //let's pretend it took 100ms (100000 microseconds)
}
#endif
server.stat_fork_rate = (double)(zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024 * 1024 * 1024)); /* GB per second. */ WIN_PORT_FIX
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
if (childpid == -1) {
closeChildInfoPipe();
Expand Down Expand Up @@ -2019,7 +2026,14 @@ int rdbSaveToSlavesSockets(rdbSaveInfo *rsi) {
closeChildInfoPipe();
} else {
server.stat_fork_time = ustime()-start;
server.stat_fork_rate = (double) (zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024)); /* GB per second. */
//[tporadowski/redis] issue #46: ustime() -> gettimeofday_highres() uses GetSystemTimePreciseAsFileTime when available (Windows 8, Windows Server 2012) or
// falls back to GetSystemTimeAsFileTime which does not have such high resolution, so "stat_fork_time" may be 0 here
#ifdef _WIN32
if (server.stat_fork_time == 0) {
server.stat_fork_time = 100000; //let's pretend it took 100ms (100000 microseconds)
}
#endif
server.stat_fork_rate = (double)(zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024 * 1024 * 1024)); /* GB per second. */ WIN_PORT_FIX
latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);

serverLog(LL_NOTICE,"Background RDB transfer started by pid %d",
Expand Down

0 comments on commit 5a40a37

Please sign in to comment.