Cygwin multithreading performance
Mark Geisert
mark@maxrnd.com
Thu Nov 19 20:24:00 GMT 2015
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
More information about the Cygwin
mailing list