From: Stepan Kasal <kasal@ucw.cz>
To: git@vger.kernel.org
Cc: theoleblond <theodore.leblond@gmail.com>
Subject: [PATCH] Sleep 1 millisecond in poll() to avoid busy wait
Date: Mon, 28 Apr 2014 10:39:31 +0200 [thread overview]
Message-ID: <20140428083931.GA10257@camelia.ucw.cz> (raw)
From: theoleblond <theodore.leblond@gmail.com>
Date: Wed, 16 May 2012 06:52:49 -0700
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.
---
This is one of the patches that lives in msysGit, could it be
accepted upstream?
It modifies the Windows compat function only.
Have a nice day,
Stepan
compat/poll/poll.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/compat/poll/poll.c b/compat/poll/poll.c
index 31163f2..c5a9a93 100644
--- a/compat/poll/poll.c
+++ b/compat/poll/poll.c
@@ -605,7 +605,9 @@ restart:
if (!rc && timeout == INFTIM)
{
- SwitchToThread();
+ /* Sleep 1 millisecond to avoid busy wait */
+ SleepEx(1, TRUE);
+
goto restart;
}
--
1.9.2.msysgit.0.158.g6070cee
next reply other threads:[~2014-04-28 8:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-28 8:39 Stepan Kasal [this message]
2014-04-28 9:07 ` [PATCH] Sleep 1 millisecond in poll() to avoid busy wait Erik Faye-Lund
2014-04-28 11:38 ` Stepan Kasal
2014-04-28 11:42 ` [PATCH] poll/select: prevent busy-waiting Stepan Kasal
2014-04-28 11:44 ` Erik Faye-Lund
2014-04-28 14:29 ` [PATCH] Windows: Always normalize paths to Windows-style Stepan Kasal
2014-04-28 15:26 ` Stepan Kasal
2014-05-07 18:44 ` Heiko Voigt
2014-05-07 20:40 ` Junio C Hamano
2014-05-08 10:11 ` Stepan Kasal
2014-05-08 20:13 ` Junio C Hamano
2014-05-08 20:36 ` [PATCH] Revert "submodules: fix ambiguous absolute paths under Windows" Stepan Kasal
2014-04-28 15:05 ` [PATCH] poll/select: prevent busy-waiting Johannes Sixt
2014-04-28 15:35 ` [PATCH v2] Sleep 1 millisecond in poll() to avoid busy wait Stepan Kasal
2014-04-28 15:37 ` Erik Faye-Lund
2014-04-28 18:58 ` Junio C Hamano
2014-04-29 3:47 ` Stepan Kasal
2014-04-29 16:51 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140428083931.GA10257@camelia.ucw.cz \
--to=kasal@ucw.cz \
--cc=git@vger.kernel.org \
--cc=theodore.leblond@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).