Switch to wait-free FIFO instead of mutex + double-buffering for sidechain sample submission.

Bug #1179027 reported by RJ Skerry-Ryan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mixxx
Fix Released
Low
RJ Skerry-Ryan

Bug Description

Writing to the sidechain locks mutexes. Also the double-buffering waits for a full buffer of 65536 samples to be processed before recording/shoutcast processes it. This adds about .75 seconds of latency to internet broadcasting.

RJ Skerry-Ryan (rryan)
Changed in mixxx:
milestone: none → 1.12.0
assignee: nobody → RJ Ryan (rryan)
importance: Undecided → Low
Revision history for this message
RJ Skerry-Ryan (rryan) wrote :

I've experimented with this and subjectively it's an improvement. At 1ms latency on my macbook, recording causes xruns using lp:mixxx but with this FIFO change there are none.

The timing change is a little confusing to interpret:

lp:mixxx

Debug [Main]: Stat("EngineSideChain:submitSamples","count=56730,sum=2.0621e+07ns,average=363.493ns,min=103ns,max=31814ns,variance=428647ns^2,stddev=654.712ns")

lp:mixxx with sidechain FIFO:

Debug [Main]: Stat("EngineSideChain:writeSamples","count=55378,sum=4.1629e+08ns,average=7517.24ns,min=335ns,max=149221ns,variance=1.2783e+07ns^2,stddev=3575.33ns")

Not using a mutex is enough of a reason to make this change even if this code is a 25x slow-down. But why is it slower?

This change actually signals the sidechain thread to wake on every write. The slowdown is actually due to the signaling. The FIFO write should be about the same as the original code since it's mostly a memcpy.

To prove this, I changed the code to only signal the sidechain thread once the FIFO was 4/5ths full:

Debug [Main]: Stat("EngineSideChain:writeSamples","count=60029,sum=2.42839e+07ns,average=404.536ns,min=171ns,max=25886ns,variance=345917ns^2,stddev=588.147ns")

So this is approximately performance neutral if we keep the old behavior of submitting once we have ~65536 samples.

Now the question for me is how often should we wake the sidechain? The sooner we wake it the lower latency shoutcast will have.

Changed in mixxx:
status: New → In Progress
Revision history for this message
Owen Williams (ywwg) wrote :

Streaming services like shoutcast often have a buffer of multiple seconds. Filling the buffer more than once a second is a waste of time for such a non-performance-sensitive task.

Revision history for this message
RJ Skerry-Ryan (rryan) wrote : Re: [Bug 1179027] Re: Switch to wait-free FIFO instead of mutex + double-buffering for sidechain sample submission.

Good point -- I'll delay the processing but double the buffer size and
process at half full so we can try to avoid overruns. I'm also working on
getting rid of sleep() in EngineShoutcast because that is a source of
overruns.
On May 11, 2013 7:58 PM, "Owen Williams" <email address hidden> wrote:

> Streaming services like shoutcast often have a buffer of multiple
> seconds. Filling the buffer more than once a second is a waste of time
> for such a non-performance-sensitive task.
>
> --
> You received this bug notification because you are a member of Mixxx
> Development Team, which is subscribed to Mixxx.
> https://bugs.launchpad.net/bugs/1179027
>
> Title:
> Switch to wait-free FIFO instead of mutex + double-buffering for
> sidechain sample submission.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/mixxx/+bug/1179027/+subscriptions
>

RJ Skerry-Ryan (rryan)
Changed in mixxx:
status: In Progress → Fix Committed
RJ Skerry-Ryan (rryan)
Changed in mixxx:
status: Fix Committed → Fix Released
Revision history for this message
Swiftb0y (swiftb0y) wrote :

Mixxx now uses GitHub for bug tracking. This bug has been migrated to:
https://github.com/mixxxdj/mixxx/issues/7022

lock status: Metadata changes locked and limited to project staff
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.