public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* App runs 8x slower on dual core machine (with test case to replicate issue)
@ 2012-08-09  8:17 Zach Saw
  2012-08-09  9:22 ` Corinna Vinschen
  2013-01-22  4:51 ` Zach Saw
  0 siblings, 2 replies; 16+ messages in thread
From: Zach Saw @ 2012-08-09  8:17 UTC (permalink / raw)
  To: cygwin

Hi all,

While trying to compile my multithreaded app written for Linux on
Cygwin to run on Windows, I discovered the app would perform 8x slower
on a machine with the same specs. I then went on to triage the issue
and found that if I set CPU affinity of that process to 1 (i.e. single
core), I'd get it to speed up to almost the speed I'd get under Linux
(set to single core too).

I dug deeper and had my suspicion on a Cygwin bug. I suspected a
problem in its thread singalling (condvar). So to test my hypothesis,
I created a minimal test case to show case this issue. This minimal
test case compiled on MSVC++ too and the difference is staggering.
What you'll find is if you started the process with CPU Aff = 1,
you'll get it to run >8x as fast as the default.

On my machine, it took 4300ms to run in dual core mode, 460ms to run
when CPU Aff = 1.

Setup:
Cygwin
WinXP SP3
2GB RAM
Core2Duo 2.33GHz
All firewalls disabled
Virus / Malware scanners disabled
Boost 1.48.0 (as per official Cygwin installation)
[Only for test case app] Boost.Threadpool - http://threadpool.sourceforge.net

Code to replicate the issue (get Boost.Threadpool from above):

#include <boost/threadpool.hpp>
#include <iostream>
#include <time.h>

inline int GetTickCount()
{
    timespec t;
    clock_gettime(CLOCK_MONOTONIC, &t);
    return (((int)t.tv_sec) * 1000) + (t.tv_nsec / 1000000);
}

class Test
{
public:
    void Add()
    {
    }
    void Delete()
    {
    }
};

int main(int argc, char** argv)
{
    int start;
    {
        boost::threadpool::pool tp(50);
        Test test;

        start = GetTickCount();
        for (int i=0; i<100000; i++)
        {
            tp.schedule(boost::bind(&Test::Add, &test));
            tp.schedule(boost::bind(&Test::Delete, &test));
        }

        tp.wait();
    }

    int elapsed = GetTickCount() - start;
    std::cout << elapsed << std::endl;

    std::cin.get();

    return 0;
}


Cheers,
Zach

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: App runs 8x slower on dual core machine (with test case to replicate issue)
@ 2012-08-09 13:03 Zach Saw
  0 siblings, 0 replies; 16+ messages in thread
From: Zach Saw @ 2012-08-09 13:03 UTC (permalink / raw)
  To: cygwin

Unfortunately, I'm not paid to minimize test cases for Cygwin.
It already took me quite some time to create the test case to
demonstrate a multicore issue in Cygwin.
And Boost 1.48.0 that I used is officially released as part of Cygwin
(i.e. Cygwin patched - which is different from official Boost).
Another finding - When under WOW64 (Win7-64-bit), the test case fails
(i.e. runs slow) regardless of CPU affinity.
I already found that I could set CPU affinity to fix the issue, so I'm good.

--
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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-01-22  8:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-09  8:17 App runs 8x slower on dual core machine (with test case to replicate issue) Zach Saw
2012-08-09  9:22 ` Corinna Vinschen
2012-08-10  3:39   ` Zach Saw
2012-08-10  3:45     ` Daniel Colascione
2012-08-10  4:04       ` Zach Saw
2012-08-10 16:37         ` Andrew DeFaria
2012-08-11  1:14           ` Zach Saw
2012-08-11  2:32             ` Christopher Faylor
2012-08-10  3:52     ` Larry Hall (Cygwin)
2012-08-10  4:10       ` Zach Saw
2012-08-10  3:56     ` Linda Walsh
2012-08-10  4:13       ` Zach Saw
2012-08-10  6:31         ` Zach Saw
2013-01-22  4:51 ` Zach Saw
2013-01-22  8:51   ` Corinna Vinschen
2012-08-09 13:03 Zach Saw

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).