summaryrefslogtreecommitdiff
path: root/compat/poll
diff options
context:
space:
mode:
authorTheodore Leblond <theodore.leblond@gmail.com>2012-05-16 13:52:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-04-29 16:55:38 (GMT)
commit76e7c8a7ed58250bb74cf55618a81baed1797eca (patch)
tree6aba7816aa8afe5ada51039c70d648a3977126d5 /compat/poll
parent0bc85abb7aa9b24b093253018801a0fb43d01122 (diff)
downloadgit-76e7c8a7ed58250bb74cf55618a81baed1797eca.zip
git-76e7c8a7ed58250bb74cf55618a81baed1797eca.tar.gz
git-76e7c8a7ed58250bb74cf55618a81baed1797eca.tar.bz2
compat/poll: sleep 1 millisecond to avoid busy wait
SwitchToThread() only gives away the rest of the current time slice to another thread in the current process. So if the thread that feeds the file decscriptor we're polling is not in the current process, we get busy-waiting. 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. [jc: this was first accepted in msysgit tree in May 2012 via a pull request and Paolo Bonzini has also accepted the same fix to Gnulib around the same time; see $gmane/247518 for a bit more detail] Signed-off-by: Stepan Kasal <kasal@ucw.cz> Acked-by: Johannes Sixt <j6t@kdbg.org> Acked-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/poll')
-rw-r--r--compat/poll/poll.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/compat/poll/poll.c b/compat/poll/poll.c
index 31163f2..a9b41d8 100644
--- a/compat/poll/poll.c
+++ b/compat/poll/poll.c
@@ -605,7 +605,7 @@ restart:
if (!rc && timeout == INFTIM)
{
- SwitchToThread();
+ SleepEx (1, TRUE);
goto restart;
}