Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Read with buffering #15

Merged
merged 1 commit into from
Mar 11, 2019
Merged

Optimize Read with buffering #15

merged 1 commit into from
Mar 11, 2019

Conversation

kixelated
Copy link
Contributor

This avoids channel/lock coordination in favor of performing a copy and
always adding the packet to a queue. Obviously I hate performing copies,
but I think this is the fastest approach with the current API.

Along with switching webrtc to using this package, this reduces packet loss
on the reader size from roughly 8% to 0.5%.

I wrote an implementation similar to the old code for comparison sake.

name                old time/op    new time/op     delta
PacketBuffer14-8       859ns ± 5%      129ns ± 4%   -84.93%
PacketBuffer140-8      832ns ± 4%      154ns ± 4%   -81.43%
PacketBuffer1400-8     825ns ± 8%      351ns ± 4%   -57.49%

name                old speed      new speed       delta
PacketBuffer14-8    16.3MB/s ± 5%  107.8MB/s ± 3%  +561.08%
PacketBuffer140-8    168MB/s ± 4%    904MB/s ± 4%  +436.70%
PacketBuffer1400-8  1.70GB/s ± 8%   3.99GB/s ± 4%  +134.74%

@kixelated kixelated requested a review from Sean-Der March 5, 2019 01:23
@backkem backkem added the review label Mar 5, 2019
@kixelated kixelated force-pushed the read-buffer branch 6 times, most recently from f19847f to 54d1a41 Compare March 7, 2019 01:32
stream_srtp.go Outdated

// Create a buffer with a 1MB limit
r.buffer = packetio.NewBuffer()
r.buffer.SetLimitSize(1000 * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a constant and pull it out of the function (just for visibility)

stream_srtcp.go Outdated

// Create a buffer and limit it to 100KB
r.buffer = packetio.NewBuffer()
r.buffer.SetLimitSize(100 * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constant

@kixelated kixelated changed the title Buffer all reads instead of message passing Optimize Read with buffering Mar 7, 2019
@kixelated kixelated requested a review from Sean-Der March 7, 2019 20:35
@Sean-Der
Copy link
Member

Sean-Der commented Mar 8, 2019

@kixelated

This LGTM! Lets wait to merge until pions/webrtc is ready also though. I don't want master to break for people that don't use modules yet. (this will trickle down buffer full errors otherwise)

This avoids channel/lock coordination in favor of performing a copy and
always adding the packet to a queue. Obviously I hate performing copies,
but I think this is the fastest approach with the current API.

This fixes much of the packet loss on the reader side.
@kixelated kixelated merged commit aa002fa into master Mar 11, 2019
@kixelated kixelated deleted the read-buffer branch March 11, 2019 04:19
@backkem backkem removed the review label Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants