GNOME Bugzilla – Bug 642720
audiotestsrc: pipelines with multiple instances with wave=gaussian-noise, white-noise, or pink-noise are very slow
Last modified: 2011-02-19 07:39:06 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.
Created attachment 181285 [details] shell script implementing benchmark Here is a bash script to generate the benchmarks.
Created attachment 181286 [details] benchmark results before applying patch Figure showing run times before applying the patch.
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.
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.