After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 642720 - audiotestsrc: pipelines with multiple instances with wave=gaussian-noise, white-noise, or pink-noise are very slow
audiotestsrc: pipelines with multiple instances with wave=gaussian-noise, whi...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other All
: Normal normal
: 0.10.33
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-02-18 23:38 UTC by Leo Singer
Modified: 2011-02-19 07:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (6.17 KB, patch)
2011-02-18 23:38 UTC, Leo Singer
committed Details | Review
shell script implementing benchmark (776 bytes, application/x-sh)
2011-02-18 23:38 UTC, Leo Singer
  Details
benchmark results before applying patch (95.63 KB, image/png)
2011-02-18 23:42 UTC, Leo Singer
  Details
benchmark results after applying patch (94.77 KB, image/png)
2011-02-18 23:43 UTC, Leo Singer
  Details

Description Leo Singer 2011-02-18 23:38:00 UTC
Created attachment 181284 [details] [review]
proposed patch

Pipelines which contain more than one instance of audiotestsrc with the "wave" property set to "gaussian-noise", "pink-noise", or "white-noise" are very slow because audiotestsrc uses global, lock-protected random number generators.

For an example of such a global lock, see the glib source code:
<http://git.gnome.org/browse/glib/tree/glib/grand.c?id=fdaaa22b58b20c285bc0c328cd6a97bb6c0f0258#n610>

The attached patch has each instance of audiotestsrc create its own instance of GRand (whose seed is taken from /dev/urandom) so that they don't need to contend over those global locks.

I performed a test in which I had a simple pipeline that looked like this:

gst-launch adder name=add ! \
    audio/x-raw-float,rate=16384,width=64 ! \
    fakesink num-buffers=10000 sync=false \
    audiotestsrc wave=white-noise ! add. \
    audiotestsrc wave=white-noise ! add. \
    audiotestsrc wave=white-noise ! add. \
    ...
    audiotestsrc wave=white-noise ! add.

where I varied the number of instances of audiotestsrc from 1 to 16, and tried setting "wave" to "sine", "gaussian-noise", "pink-noise", or "white-noise".

I found that my patch:
 - had no effect on the performance of "sine" (expected).
 - made "pink-noise" take only 70% of the amount of time it took without the patch
 - made "white-noise" and "gaussian-noise" take less than 1% of the time they took without the patch

So, I got a speedup for all three types of noise, but I got a speedup of better than a factor of 100 for white-noise and gaussian-noise.

I performed this test on a 2.53 GHz Intel Core 2 Duo MacBook Pro.

Another possible resolution (if it was desirable to have all instances of audiotestsrc share the same seed) would be to have the element **class** keep a single instance of GRand, and have the instances block for access to it on the buffer level.  This, however, would not perform as well as this patch on multicore machines.
Comment 1 Leo Singer 2011-02-18 23:38:59 UTC
Created attachment 181285 [details]
shell script implementing benchmark

Here is a bash script to generate the benchmarks.
Comment 2 Leo Singer 2011-02-18 23:42:01 UTC
Created attachment 181286 [details]
benchmark results before applying patch

Figure showing run times before applying the patch.
Comment 3 Leo Singer 2011-02-18 23:43:08 UTC
Created attachment 181287 [details]
benchmark results after applying patch

Figure showing run times after applying the patch.

Note that scale on this figure is different from the previous figure.
Comment 4 Sebastian Dröge (slomo) 2011-02-19 07:39:02 UTC
commit 82199c581506a6ef3f21144c6a7f48aea0f22240
Author: Leo Singer <leo.singer@ligo.org>
Date:   Fri Feb 18 13:27:23 2011 -0800

    audiotestsrc: each element gets its own instance of GRand, if needed
    
    As a result, pipelines that contain multiple instances of audiotestsrc
    with the 'wave' property set to 'white-noise', 'pink-noise', or
    'gaussian-noise' will run much faster, since they won't be competing
    for access to the global, lock-protected instance of GRand.
    
    Fixes bug #642720.