Boost C++ Libraries: Ticket #7422: Provide a condition variable with zero-overhead performance penality https://svn.boost.org/trac10/ticket/7422 <p> In boost versions prior to 1.45 condition_variable was a zero-overhead thin wrapper over pthread_cond_t. </p> <p> In version 1.45 an internal mutex was added to condition_variable to improve thread cancellation support as described elsewhere (can't add the link to gmane archive because Trac thinks it's spam). </p> <p> Since version 1.45 calling condition_variable::wait*() and condition_variable::notify*() lock the internal mutex. Doing so causes performance regressions for latency sensitive applications that don't use thread cancellation. To put it in other words, condition_variable was essentially turned into condition_variable_any. </p> <p> Could the old version of condition_variable be added back please? </p> <p> A good idea seems to be requiring a macro, for example BOOST_THREADS_REQUIRE_THREAD_CANCELLATION, to be defined for condition_variable to include the internal mutex or be an alias for condition_variable_any. A call to thread::interrupt() would fail at compile time if BOOST_THREADS_REQUIRE_THREAD_CANCELLATION is not defined. Things may get more complicated if any compiled boost libraries use condition_variable though. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7422 Trac 1.4.3 viboes Wed, 26 Sep 2012 19:05:06 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:1</guid> <description> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7422" title="#7422: Feature Requests: Provide a condition variable with zero-overhead performance penality (closed: fixed)">maxim.yegorushkin@…</a>: </p> <blockquote class="citation"> <p> In boost versions prior to 1.45 condition_variable was a zero-overhead thin wrapper over pthread_cond_t. </p> <p> In version 1.45 an internal mutex was added to condition_variable to improve thread cancellation support as described elsewhere (can't add the link to gmane archive because Trac thinks it's spam). </p> <p> Since version 1.45 calling condition_variable::wait*() and condition_variable::notify*() lock the internal mutex. Doing so causes performance regressions for latency sensitive applications that don't use thread cancellation. To put it in other words, condition_variable was essentially turned into condition_variable_any. </p> <p> Could the old version of condition_variable be added back please? </p> </blockquote> <p> As Anthony explained in the link you mention, we can not do that without breaking existing code. I don't know if defining an additional basic_condition_variable will respond to you expectations? </p> <p> In any case, I don't see as a bug, except if you can find in the documentation a reference to the zero-overhead. </p> <blockquote class="citation"> <p> A good idea seems to be requiring a macro, for example BOOST_THREADS_REQUIRE_THREAD_CANCELLATION, to be defined for condition_variable to include the internal mutex or be an alias for condition_variable_any. A call to thread::interrupt() would fail at compile time if BOOST_THREADS_REQUIRE_THREAD_CANCELLATION is not defined. Things may get more complicated if any compiled boost libraries use condition_variable though. </p> </blockquote> <p> Well this is a different feature that should merit a specific ticket. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 26 Sep 2012 19:06:14 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/7422#comment:2 https://svn.boost.org/trac10/ticket/7422#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sat, 29 Sep 2012 18:41:37 GMT type, summary changed https://svn.boost.org/trac10/ticket/7422#comment:3 https://svn.boost.org/trac10/ticket/7422#comment:3 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> <li><strong>summary</strong> <span class="trac-field-old">condition_variable performance regression</span> → <span class="trac-field-new">Provide a condition variable with zero-overhead performance penality</span> </li> </ul> Ticket viboes Mon, 05 Nov 2012 01:21:57 GMT cc changed https://svn.boost.org/trac10/ticket/7422#comment:4 https://svn.boost.org/trac10/ticket/7422#comment:4 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> </ul> <p> Hi, I have started to implement in trunk <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7594" title="#7594: Feature Requests: Allow to disable thread interruptions (closed: fixed)">#7594</a> Allow to disable thread interruptions. I need to make some tests, but please, could you check if this will work for you. </p> Ticket maxim.yegorushkin@… Mon, 05 Nov 2012 17:40:08 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:5</guid> <description> <p> I can't comment on the actual code changes since I am not familiar well enough with all the internals (the threads library has grown quite significantly over the years). </p> <p> Do I correctly understand that the users should define BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS macro when compiling boost and using the headers? If so, I couldn't ask for more. Thanks a lot. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 01 Dec 2012 11:51:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:5" title="Comment 5">maxim.yegorushkin@…</a>: </p> <blockquote class="citation"> <p> I can't comment on the actual code changes since I am not familiar well enough with all the internals (the threads library has grown quite significantly over the years). </p> <p> Do I correctly understand that the users should define BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS macro when compiling boost and using the headers? If so, I couldn't ask for more. Thanks a lot. </p> </blockquote> <p> Could you check if this works for you in trunk? </p> </description> <category>Ticket</category> </item> <item> <author>maxim.yegorushkin@…</author> <pubDate>Sat, 01 Dec 2012 13:58:37 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build.log.bz2</span> </li> </ul> <p> boost build log </p> Ticket maxim.yegorushkin@… Sat, 01 Dec 2012 14:00:05 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:7</guid> <description> <p> I checked out trunk and tried building it. </p> <p> It builds fine when BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS is not defined. </p> <p> When BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS is defined boost fails to compile. Please see the earlier attached build log. </p> </description> <category>Ticket</category> </item> <item> <author>maxim.yegorushkin@…</author> <pubDate>Sat, 01 Dec 2012 14:13:49 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">build.patch</span> </li> </ul> <p> Patch to fix the build when macro BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS is defined. </p> Ticket maxim.yegorushkin@… Sat, 01 Dec 2012 16:52:27 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:8</guid> <description> <p> I managed to successfully build boost from trunk with macro BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS defined. </p> <p> When running tests from boost_trunk/libs/thread/test by invoking b2 in this directory it runs tests and they seem to freeze. I may be invoking the tests incorrectly. How do you run tests please? </p> <p> I also re-built my proprietary applications against this version of boost and ran unit tests that passed. They do use boost::condition_variable internally, but obviously they don't stress test it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 01 Dec 2012 19:11:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:9</guid> <description> <p> I'm passing the regression test and there are some issues, between others it is needed to lock in the internal mutex </p> <pre class="wiki">#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS //BOOST_THREAD_LOG &lt;&lt; BOOST_THREAD_END_LOG; detail::interruption_checker check_for_interruption(&amp;internal_mutex,&amp;cond); #else boost::pthread2::pthread_mutex_scoped_lock internal_lock2(&amp;internal_mutex); #endif </pre><p> I will commit the fixes as soon as everything is OK. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 01 Dec 2012 22:54:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:10</guid> <description> <p> I have added a patch to ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7594" title="#7594: Feature Requests: Allow to disable thread interruptions (closed: fixed)">#7594</a> that make it possible to use Boost.Thread defining BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS for the user files. No need to recompile the Thread library. </p> <p> This doesn't provide a condition variable with zero-overhead performance penality, but it will be easier now to improve the performances. </p> <p> HTH </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 08 Dec 2012 13:47:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:11</guid> <description> <p> It would be great if you could give some performances figures with and without interruptions so that we can see if something more is needed. </p> </description> <category>Ticket</category> </item> <item> <author>maxim.yegorushkin@…</author> <pubDate>Thu, 13 Dec 2012 13:41:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:12</guid> <description> <p> Okay, I've made a little benchmark. </p> <p> Is is a producer-consumer ping-pong benchmark. It aims to benchmark condition variables with and without thread cancellation support by comparing the time it took to complete the benchmark. </p> <p> Condition variable with thread cancellation support is boost::condition_variable from boost-1.51. Without - std::condition_variable that comes with gcc-4.7.2. </p> <p> One producer, one to CONSUMER_MAX consumers. The benchmark calls condition_variable::notify_all() without holding a mutex to maximize contention within this function. Each benchmark for a number of consumers is run three times and the best time is picked to get rid of outliers. </p> <p> The results are reported for each benchmark for a number of consumers. The most important number is (std - boost) / std * 100. Positive numbers are when boost::condition_variable is faster, negative it is slower. </p> <p> The test shows that boost::condition_variable is around 8% slower than std::condition_variable. I made plots but Trac doesn't allow to post links here. </p> <p> I ran the benchmark on Fedora 17 with gcc-4.7.2 with real-time FIFO priority in init mode 3. </p> </description> <category>Ticket</category> </item> <item> <author>maxim.yegorushkin@…</author> <pubDate>Thu, 13 Dec 2012 13:42:37 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cc</span> </li> </ul> <p> The benchmark </p> Ticket maxim.yegorushkin@… Thu, 13 Dec 2012 13:43:11 GMT attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-pong-compilation.log</span> </li> </ul> <p> Compiler log for the benchmark </p> Ticket maxim.yegorushkin@… Thu, 13 Dec 2012 13:44:13 GMT attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-pong-i870.txt</span> </li> </ul> <p> The output of the benchmark on i870. </p> Ticket viboes Thu, 13 Dec 2012 15:05:35 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:13</guid> <description> <p> Thanks for this benchmark. Please, could you test with Boost.Thread defining BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS. I would expect a little improvement. </p> <p> I will post my results on MacOS soon. </p> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Thu, 13 Dec 2012 20:55:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:14</guid> <description> <p> Good idea, so I re-ran the benchmark on my Fedora 17 workstation with i7-3820. For these two runs I used boost trunk as of revision 81908. One run with the benchmark and boost built with -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS macro and one without. </p> <p> (Forgot to mention that in addition to running the benchmark with real-time priority FIFO 99, I also disable CPU frequency scaling to prevent the CPU from shifting gears while benchmarking). </p> <p> There is a noticeable 35% improvement in median run-time when macro BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS is defined. (Note that I am not being overly scientific here because the analysis of variance is missing, i.e. I can't say I am 95% sure. However on the plot the effect of the macro is quite noticeable) </p> <p> On the other hand, using boost mutex and condition_variable with BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS defined is still around 5% slower than when using the same primitives from std namespace. (Same caveat) </p> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Thu, 13 Dec 2012 20:58:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:15</guid> <description> <p> The path to the benchmark plot is /spreadsheet/ccc?key=0Ai_v0rSH1AXrdHl2RDN4UkFYNHZ2aXBUUk5VWmNfcXc </p> <p> It is docs google com. </p> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Thu, 13 Dec 2012 21:09:03 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-pong-i3820.txt</span> </li> </ul> <p> Benchmark output on i3820 with boost-trunk </p> Ticket Maxim Yegorushkin <maxim.yegorushkin@…> Thu, 13 Dec 2012 21:09:39 GMT attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-pong-i3820-no-interruptions.txt</span> </li> </ul> <p> Benchmark output on i3820 with boost-trunk and -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS </p> Ticket viboes Thu, 13 Dec 2012 21:14:56 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:16</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:14" title="Comment 14">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <p> Good idea, so I re-ran the benchmark on my Fedora 17 workstation with i7-3820. For these two runs I used boost trunk as of revision 81908. One run with the benchmark and boost built with -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS macro and one without. </p> </blockquote> <p> Thanks. </p> <blockquote class="citation"> <p> (Forgot to mention that in addition to running the benchmark with real-time priority FIFO 99, I also disable CPU frequency scaling to prevent the CPU from shifting gears while benchmarking). </p> <p> There is a noticeable 35% improvement in median run-time when macro BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS is defined. (Note that I am not being overly scientific here because the analysis of variance is missing, i.e. I can't say I am 95% sure. However on the plot the effect of the macro is quite noticeable) </p> </blockquote> <p> Glad to hear it. Could you run the test 10 times instead of 3 to reduce the variance? </p> <blockquote class="citation"> <p> On the other hand, using boost mutex and condition_variable with BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS defined is still around 5% slower than when using the same primitives from std namespace. (Same caveat) </p> </blockquote> <p> I was sure that there would be other parts that need to be inspected :( I will try to see what I can do. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 13 Dec 2012 21:15:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:17</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:15" title="Comment 15">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <p> The path to the benchmark plot is /spreadsheet/ccc?key=0Ai_v0rSH1AXrdHl2RDN4UkFYNHZ2aXBUUk5VWmNfcXc </p> <p> It is docs google com. </p> </blockquote> <p> Why you can not add the web link? </p> </description> <category>Ticket</category> </item> <item> <author>maxim.yegorushkin@…</author> <pubDate>Thu, 13 Dec 2012 23:04:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:18</guid> <description> <p> Trac considers external links spam and offers to confirm something. It is not clear what and how to confirm, could be that the message is truncated. </p> <p> I should probably run another benchmark against the boost version before when the thread interruption was introduced to see how it compared to the std primitives at that time. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 14 Dec 2012 07:40:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:19</guid> <description> <p> I have run the no-interruptions benchmark (modified to compile on MacOS) using clang-3.2 without setting any special conditions changing 3 parameters: </p> <ul><li>CONSUMER_MAX: from 20 to 10 </li><li>test iterations: from 3 to 100 </li><li>shared_data iteration : from 100000 to 10000. </li></ul><p> here are the results: </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,-5.063747,44009306,46237826 2,-1.764249,72169561,73442812 3,5.327530,94552244,89514945 4,0.767002,121827567,120893147 5,1.826591,141517038,138932100 6,0.471998,171223003,170414834 7,-0.937626,187902198,189664017 8,-0.840567,220015472,221864850 9,-3.291703,236884513,244682047 10,0.397024,272506100,271424186 </pre><p> I'm sure that the setting of your special condition would change these results. From these results, I don't see a loss of 5% of Boost respect to std. Please could you run the benchmark with these parameters ans your settings: </p> <ul><li>running the benchmark with real-time priority FIFO 99, </li><li>disable CPU frequency scaling to prevent the CPU from shifting gears while benchmarking </li></ul><p> How do you do this? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 14 Dec 2012 08:03:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:20 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:20</guid> <description> <p> Here are the results with gcc-4.7.2 for 200 test iterations </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,-8.720169,40772444,44327870 2,0.644605,71669162,71207179 3,0.793437,91792637,91064320 4,1.379378,119557914,117908759 5,1.398979,140016424,138057624 6,0.824572,164569134,163212143 7,-0.183305,180981210,181312957 8,3.389641,214427927,207159590 9,-2.147819,227430412,232315206 10,-1.823378,263367555,268169742 </pre> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Fri, 14 Dec 2012 10:02:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:21</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:19" title="Comment 19">viboes</a>: </p> <blockquote class="citation"> <p> I have run the no-interruptions benchmark (modified to compile on MacOS) using clang-3.2 without setting any special conditions changing 3 parameters: </p> <ul><li>CONSUMER_MAX: from 20 to 10 </li><li>test iterations: from 3 to 100 </li><li>shared_data iteration : from 100000 to 10000. </li></ul><p> here are the results: </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,-5.063747,44009306,46237826 2,-1.764249,72169561,73442812 3,5.327530,94552244,89514945 4,0.767002,121827567,120893147 5,1.826591,141517038,138932100 6,0.471998,171223003,170414834 7,-0.937626,187902198,189664017 8,-0.840567,220015472,221864850 9,-3.291703,236884513,244682047 10,0.397024,272506100,271424186 </pre></blockquote> <p> This is quite different from what I observe. </p> <p> What kind of implementation of std primitives does clang use? Is it from gnu standard C++ library (the same as g++)? </p> <p> Also the difference may be due to a different process scheduler on Mac OS. </p> <blockquote class="citation"> <p> I'm sure that the setting of your special condition would change these results. </p> </blockquote> <p> You are quite right. Running the benchmark with CPU frequency scaling turned on (the default) makes the results more noisy (increases variance). Running it with the standard scheduler priority also increases variance and make boost primitives perform even worse compared to std ones. </p> <blockquote class="citation"> <p> From these results, I don't see a loss of 5% of Boost respect to std. Please could you run the benchmark with these parameters ans your settings: </p> </blockquote> <p> I ran it with your settings (10 consumers max, 100 repetitions, 10000 iterations) and it didn't change the normalized numbers for me. </p> <blockquote class="citation"> <ul><li>running the benchmark with real-time priority FIFO 99, </li><li>disable CPU frequency scaling to prevent the CPU from shifting gears while benchmarking </li></ul><p> How do you do this? </p> </blockquote> <p> To run it with maximum real-time priority I invoked the benchmark as <code>chrt -f 99 &lt;benchmark&gt;</code>. Depending on your OS settings you may need special privileges to be able to use real-time priorities. </p> <p> On Linux CPU frequency scaling can be disabled by doing: </p> <pre class="wiki">for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance &gt; $f done </pre><p> Not sure how it is done on Mac OS. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 15 Dec 2012 08:25:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:22 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:22</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:21" title="Comment 21">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:19" title="Comment 19">viboes</a>: </p> <blockquote class="citation"> <p> I have run the no-interruptions benchmark (modified to compile on MacOS) using clang-3.2 without setting any special conditions changing 3 parameters: </p> <ul><li>CONSUMER_MAX: from 20 to 10 </li><li>test iterations: from 3 to 100 </li><li>shared_data iteration : from 100000 to 10000. </li></ul><p> here are the results: </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,-5.063747,44009306,46237826 2,-1.764249,72169561,73442812 3,5.327530,94552244,89514945 4,0.767002,121827567,120893147 5,1.826591,141517038,138932100 6,0.471998,171223003,170414834 7,-0.937626,187902198,189664017 8,-0.840567,220015472,221864850 9,-3.291703,236884513,244682047 10,0.397024,272506100,271424186 </pre></blockquote> <p> This is quite different from what I observe. </p> </blockquote> <p> Note that this is similar to what I get for gcc-4.7.2. I will need to check the optimization flags. </p> <blockquote class="citation"> <p> What kind of implementation of std primitives does clang use? Is it from gnu standard C++ library (the same as g++)? </p> </blockquote> <p> I use clang with libc++. </p> <blockquote class="citation"> <p> Also the difference may be due to a different process scheduler on Mac OS. </p> <blockquote class="citation"> <p> I'm sure that the setting of your special condition would change these results. </p> </blockquote> <p> You are quite right. Running the benchmark with CPU frequency scaling turned on (the default) makes the results more noisy (increases variance). Running it with the standard scheduler priority also increases variance and make boost primitives perform even worse compared to std ones. </p> </blockquote> <p> I will check these settings on ubuntu. </p> <blockquote class="citation"> <blockquote class="citation"> <p> From these results, I don't see a loss of 5% of Boost respect to std. Please could you run the benchmark with these parameters ans your settings: </p> </blockquote> <p> I ran it with your settings (10 consumers max, 100 repetitions, 10000 iterations) and it didn't change the normalized numbers for me. </p> </blockquote> <p> Did you observe that there where less % with lower/high numbers? Could you post here your results? </p> <blockquote class="citation"> <blockquote class="citation"> <ul><li>running the benchmark with real-time priority FIFO 99, </li><li>disable CPU frequency scaling to prevent the CPU from shifting gears while benchmarking </li></ul><p> How do you do this? </p> </blockquote> <p> To run it with maximum real-time priority I invoked the benchmark as <code>chrt -f 99 &lt;benchmark&gt;</code>. Depending on your OS settings you may need special privileges to be able to use real-time priorities. </p> <p> On Linux CPU frequency scaling can be disabled by doing: </p> <pre class="wiki">for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance &gt; $f done </pre><p> Not sure how it is done on Mac OS. </p> </blockquote> <p> Thanks anyway. </p> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Mon, 17 Dec 2012 21:11:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:23 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:23</guid> <description> <p> To double check numbers I re-ran the benchmarks with boost-1.44 (the last version with no thread interruption support), trunk and trunk with -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS. It was run with your settings (10 consumers max, 100 repetitions, 10000 iterations) again, they seem to reduce variance well. </p> <p> Median relative times compared to times of std primitives for the three variants respectively are -1.1273285%, -7.804532% and -4.0939795%. The link to plot is the same: /spreadsheet/ccc?key=0Ai_v0rSH1AXrdHl2RDN4UkFYNHZ2aXBUUk5VWmNfcXc on docs.google.com. </p> <p> The benchmark was compiled with gcc-4.7.2, optimization flags are "-O3 -march=native", Fedora 17 and Intel Core i7-3820 CPU. </p> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Mon, 17 Dec 2012 21:12:02 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-ping-boost-1.44.log</span> </li> </ul> Ticket Maxim Yegorushkin <maxim.yegorushkin@…> Mon, 17 Dec 2012 21:12:19 GMT attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-ping-boost-trunk.log</span> </li> </ul> Ticket Maxim Yegorushkin <maxim.yegorushkin@…> Mon, 17 Dec 2012 21:12:30 GMT attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ping-ping-boost-trunk-ni.log</span> </li> </ul> Ticket viboes Mon, 17 Dec 2012 23:40:48 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:24 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:24</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:23" title="Comment 23">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <p> To double check numbers I re-ran the benchmarks with boost-1.44 (the last version with no thread interruption support), trunk and trunk with -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS. It was run with your settings (10 consumers max, 100 repetitions, 10000 iterations) again, they seem to reduce variance well. </p> <p> Median relative times compared to times of std primitives for the three variants respectively are -1.1273285%, -7.804532% and -4.0939795%. The link to plot is the same: /spreadsheet/ccc?key=0Ai_v0rSH1AXrdHl2RDN4UkFYNHZ2aXBUUk5VWmNfcXc on docs.google.com. </p> </blockquote> <p> Thanks for all these figures. I suspect that you mean boost-1.34, isn't it? I think that I have an hint for a possible performance improvement. The implementation since 1.35 is using an additional mutex which I need to see if it can be removed when interruptions are not provided. </p> <blockquote> <p> pthread_mutex_t internal_mutex; </p> </blockquote> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Tue, 18 Dec 2012 08:09:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:25 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:25</guid> <description> <blockquote class="citation"> <p> I suspect that you mean boost-1.34, isn't it? </p> </blockquote> <p> Well, it was definitely boost-1.44, because I wanted to test a version just before thread interruption support was introduced in boost-1.45. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 18 Dec 2012 12:45:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:26 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:26</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:25" title="Comment 25">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <blockquote class="citation"> <p> I suspect that you mean boost-1.34, isn't it? </p> </blockquote> <p> Well, it was definitely boost-1.44, because I wanted to test a version just before thread interruption support was introduced in boost-1.45. </p> </blockquote> <p> I'm seen them introduced in 1.35 "<a href="http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread">http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread</a>" </p> </description> <category>Ticket</category> </item> <item> <author>Maxim Yegorushkin <maxim.yegorushkin@…></author> <pubDate>Tue, 18 Dec 2012 13:29:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:27 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:27</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:26" title="Comment 26">viboes</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:25" title="Comment 25">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <blockquote class="citation"> <p> I suspect that you mean boost-1.34, isn't it? </p> </blockquote> <p> Well, it was definitely boost-1.44, because I wanted to test a version just before thread interruption support was introduced in boost-1.45. </p> </blockquote> <p> I'm seen them introduced in 1.35 "<a href="http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread">http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread</a>" </p> </blockquote> <p> Oh, I see. </p> <p> The critical point was when condition_variable became essentially condition_variable_any, and, if I understand correctly, that happened in boost-1.45. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 18 Dec 2012 16:24:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:28 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:28</guid> <description> <p> Hi, </p> <p> I have reached to improve the performances by removing the internal_mutex (see the attached patch). Here they are the results for clang-3.2: </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,3.163455,442899995,428889051 2,0.416842,736341309,733271929 3,1.203291,941092107,929768034 4,-0.029287,1217358160,1217714683 5,0.896356,1422949963,1410195269 6,0.315211,1734865379,1729396900 7,1.033687,1882941043,1863477335 8,-0.355615,2217150537,2225035057 9,1.051769,2378341849,2353327192 10,0.500550,2721524297,2707901713 </pre><p> I suspect that I have no compiled the library libc++ in release mode :( </p> <p> Please, could you give a try to this patch? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 18 Dec 2012 16:25:31 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">7422_trunk.patch</span> </li> </ul> Ticket Maxim Yegorushkin <maxim.yegorushkin@…> Tue, 18 Dec 2012 20:03:51 GMT <link>https://svn.boost.org/trac10/ticket/7422#comment:29 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:29</guid> <description> <p> With this patch boost::condition_variable performs better than std one in the benchmark: </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,1.738797,17452356,17148895 2,0.818735,26905168,26684886 3,0.909335,58318561,57788250 4,0.929148,45236280,44815968 5,1.255012,54510018,53825911 6,1.410902,63880220,62978933 7,1.094065,72988694,72190150 8,1.073388,82271239,81388149 9,0.915663,91362805,90526230 10,0.991684,100724122,99725257 </pre><p> (I also updated that spreadsheet on docs.google.com) </p> <p> Nicely done! </p> <p> In the patch condition_variable always has internal_mutex member, is it intended? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 18 Dec 2012 21:26:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:30 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:30</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7422#comment:29" title="Comment 29">Maxim Yegorushkin &lt;maxim.yegorushkin@…&gt;</a>: </p> <blockquote class="citation"> <p> With this patch boost::condition_variable performs better than std one in the benchmark: </p> <pre class="wiki">consumers,(std-boost)/std,std,boost 1,1.738797,17452356,17148895 2,0.818735,26905168,26684886 3,0.909335,58318561,57788250 4,0.929148,45236280,44815968 5,1.255012,54510018,53825911 6,1.410902,63880220,62978933 7,1.094065,72988694,72190150 8,1.073388,82271239,81388149 9,0.915663,91362805,90526230 10,0.991684,100724122,99725257 </pre><p> (I also updated that spreadsheet on docs.google.com) </p> <p> Nicely done! </p> </blockquote> <p> Glad to see these nice figures ;-) </p> <blockquote class="citation"> <p> In the patch condition_variable always has internal_mutex member, is it intended? </p> </blockquote> <p> No. I left it to preserve the layout of condition_variable in case I reach to be able to have a single library able to manage with both configurations, but it needs a lot of changes. So for the time been, users will need a build the library with -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS and internal_mutex will not be defined. </p> <p> I appreciate a lot this long walk co-working with you to achieve these results, that I hope are good enough for your application. </p> <p> I will commit it as soon as all the regression test pass and I hope I would be able to merge it the release 1.53. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 19 Dec 2012 10:52:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7422#comment:31 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7422#comment:31</guid> <description> <p> Committed revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/82094" title="Thread: #7422: don't use internal_mutex when interruptions not enabled">[82094]</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 19 Dec 2012 11:13:40 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/7422#comment:32 https://svn.boost.org/trac10/ticket/7422#comment:32 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.53.0</span> </li> </ul> Ticket Maxim Yegorushkin <maxim.yegorushkin@…> Wed, 19 Dec 2012 11:36:22 GMT attachment set https://svn.boost.org/trac10/ticket/7422 https://svn.boost.org/trac10/ticket/7422 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">chart1.png</span> </li> </ul> <p> Benchmarks on the plot </p> Ticket viboes Fri, 21 Dec 2012 22:17:05 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7422#comment:33 https://svn.boost.org/trac10/ticket/7422#comment:33 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Committed merge from trunk <a class="changeset" href="https://svn.boost.org/trac10/changeset/82159" title="Thread: merge from trunk condition_variables no-it + doc">[82159]</a>. </p> Ticket