Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 58f4e51

Browse files
theoleblondkasal
authored andcommitted
Sleep 1 millisecond in poll() to avoid busy wait
I played around with this quite a bit. After trying some more complex schemes, I found that what worked best is to just sleep 1 millisecond between iterations. Though it's a very short time, it still completely eliminates the busy wait condition, without hurting perf. There code uses SleepEx(1, TRUE) to sleep. See this page for a good discussion of why that is better than calling SwitchToThread, which is what was used previously: http://stackoverflow.com/questions/1383943/switchtothread-vs-sleep1 Note that calling SleepEx(0, TRUE) does *not* solve the busy wait. The most striking case was when testing on a UNC share with a large repo, on a single CPU machine. Without the fix, it took 4 minutes 15 seconds, and with the fix it took just 1:08! I think it's because git-upload-pack's busy wait was eating the CPU away from the git process that's doing the real work. With multi-proc, the timing is not much different, but tons of CPU time is still wasted, which can be a killer on a server that needs to do bunch of other things. I also tested the very fast local case, and didn't see any measurable difference. On a big repo with 4500 files, the upload-pack took about 2 seconds with and without the fix.
1 parent d4c3651 commit 58f4e51

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compat/poll/poll.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout)
605605

606606
if (!rc && timeout == INFTIM)
607607
{
608-
SwitchToThread();
608+
/* Sleep 1 millisecond to avoid busy wait */
609+
SleepEx(1, TRUE);
610+
609611
goto restart;
610612
}
611613

0 commit comments

Comments
 (0)