public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mark Geisert <mark@maxrnd.com>
To: cygwin@cygwin.com
Subject: Re: Cygwin multithreading performance
Date: Thu, 19 Nov 2015 20:24:00 -0000	[thread overview]
Message-ID: <564E3017.90205@maxrnd.com> (raw)
In-Reply-To: <CABPLASTtRK4mNxh0M_AnZgjJQ15kWPx+L=U=VCU3Wwi7jV_57A@mail.gmail.com>

Kacper Michajlow wrote:
> I recently noticed that Cygwin multithreading is very inefficient. I
> was repacking few git repositories and with Cygwin's git, it spawns
> threads but they are so badly synchronized that there is no speed gain
> over one thread and possible loose because of the overhead. On my
> machine I got 7-10% CPU usage while with git build with mingw easily
> uses 100%.
>
> You can find the code in question here
> https://github.com/git/git/blob/master/builtin/pack-objects.c#L1967-L2094
>
> Do you have any suggestions? Is there any chance to get MT workloads
> improved in Cygwin? In present days it is really big problem in my
> opinion.

Although there have been some issues with Cygwin pthreads reported and 
resolved, I can't recall complaints about their performance.  You don't 
supply much specific info so I had to guess that you must be doing 
something like 'git gc' to provoke calls to the code you quote.  Please 
give more info if I was mistaken.

I did an strace of 'git gc' over a small source tree I have and found:

> ~/src/cygwin-cygutils strace --mask=debug+syscall+thread -o git.strace git gc
> Counting objects: 1691, done.
> Delta compression using up to 4 threads.
> Compressing objects: 100% (398/398), done.
> Writing objects: 100% (1691/1691), done.
> Total 1691 (delta 1250), reused 1691 (delta 1250)
>
> ~/src/cygwin-cygutils grep "fork(" git.strace
>   350  111164 [main] git 360 fork: 0 = fork()
>    59  113379 [main] git 4980 fork: 360 = fork()
>   496  242346 [main] git 4980 fork: 368 = fork()
>   513  242585 [main] git 368 fork: 0 = fork()
>   828  589040 [main] git 4980 fork: 4968 = fork()
>   685  589341 [main] git 4968 fork: 0 = fork()
>   591  126631 [main] git 4968 fork: 1784 = fork()
>   483  126866 [main] git 1784 fork: 0 = fork()
>   618 2320996 [main] git 4980 fork: 2912 = fork()
>   558 2321259 [main] git 2912 fork: 0 = fork()
>   555 3023781 [main] git 4980 fork: 1612 = fork()
>   500 3024002 [main] git 1612 fork: 0 = fork()
>   766 3112383 [main] git 4980 fork: 1756 = fork()
>   681 3112655 [main] git 1756 fork: 0 = fork()

There's your problem.  Git is for some reason fork()ing to do its 
parallel operations.  fork() is very complicated to emulate on Windows 
and Cygwin's fork() is already known to be slow compared to native OS 
implementations.

Why is mingw faster?  Inspection of run-command.c in the git source tree 
(BTW thanks for the github link) shows that start_command() has two code 
paths divided by "#ifndef GIT_WINDOWS_NATIVE".  The Windows native path 
(e.g. mingw) doesn't fork() but instead spawns subprocesses.  On Cygwin 
the fork() path is used.  Git probably ought to use the spawn code path 
on Cygwin too.

I don't know offhand if this is something Cygwin's git maintainer would 
want to tackle or if it should be handled upstream but I'd guess the latter.
Hope this helps,

..mark

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2015-11-19 20:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-14  0:24 Kacper Michajlow
2015-11-19 20:24 ` Mark Geisert [this message]
2015-11-20 14:25   ` Kacper Michajlow
2015-11-21  9:21     ` Mark Geisert
2015-11-21 10:53       ` Corinna Vinschen
2015-11-23  7:45         ` Mark Geisert
2015-11-23 10:27           ` John Hein
2015-11-24  1:05             ` Mark Geisert
2015-11-26  9:49               ` Corinna Vinschen
2015-11-26 10:49                 ` Mark Geisert
2015-12-05 10:51                   ` Mark Geisert
2015-12-05 13:07                     ` Kacper Michajlow
2015-12-05 13:59                       ` Kacper Michajlow
2015-12-05 22:40                       ` Mark Geisert
2015-12-06  2:35                         ` Kacper Michajlow
2015-12-06  8:02                           ` Mark Geisert
2015-12-06 20:56                             ` Kacper Michajlow
2015-12-08 10:51                               ` Mark Geisert
2015-12-08 15:34                                 ` Corinna Vinschen
2015-12-08 17:02                                   ` Corinna Vinschen
2015-12-18 15:06 ` Achim Gratz

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=564E3017.90205@maxrnd.com \
    --to=mark@maxrnd.com \
    --cc=cygwin@cygwin.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 read-only IMAP folder(s) and NNTP newsgroup(s).