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

Reduce candidateBase.writeTo CPU cost #128

Open
adwpc opened this issue Nov 24, 2019 · 7 comments
Open

Reduce candidateBase.writeTo CPU cost #128

adwpc opened this issue Nov 24, 2019 · 7 comments
Assignees

Comments

@adwpc
Copy link
Member

adwpc commented Nov 24, 2019

Summary

image

Motivation

reduce candidateBase.writeTo cpu cost

Describe alternatives you've considered

Maybe we can use bufio in candidateBase.writeTo, like:
grpc/grpc-go@30d8f07

Additional context

https://github.com/pion/ice/blob/master/candidate_base.go#L152

@adwpc adwpc added the enhancement New feature or request label Feb 13, 2020
@adwpc
Copy link
Member Author

adwpc commented Mar 3, 2020

I have tested PacketConn.WriteBatch in pion/ice package, it reduce 30%~40% cpu in pion/ion
https://godoc.org/golang.org/x/net/ipv4#PacketConn.WriteBatch

This conn.WriteTo conn is from here?
https://github.com/pion/ice/blob/master/candidate_base.go#L152
https://github.com/pion/ice/blob/master/gather.go#L138
https://github.com/pion/transport/blob/master/vnet/net.go#L555

My question is where to finish this code? in the ice package or transport package?
@Sean-Der

@Sean-Der
Copy link
Member

Sean-Der commented Mar 3, 2020

🔥 that's amazing! Yes we need to do this @adwpc

I will take it. I also have benchmarks I am running will post results before/after.

@adwpc
Copy link
Member Author

adwpc commented Mar 4, 2020

🔥 that's amazing! Yes we need to do this @adwpc

I will take it. I also have benchmarks I am running will post results before/after.

@Sean-Der
I can make a PR to pion/ice if you need as a reference, should save your precious time :)

@notedit
Copy link

notedit commented Mar 11, 2020

I think it only work on linux

// WriteBatch writes a batch of messages.
//
// The provided flags is a set of platform-dependent flags, such as
// syscall.MSG_DONTROUTE.
//
// It returns the number of messages written on a successful write.
//
// On Linux, a batch write will be optimized.
// On other platforms, this method will write only a single message.

@jech
Copy link
Member

jech commented Sep 5, 2020

How much does it increase latency?

@dtaht
Copy link

dtaht commented Jul 6, 2021

kernel context switches COST. a single sendmmsg call has nearly no measurable overhead difference between a sendmsg call for a single packet, but you can bundle up a lot of packets.

Also see ngtcp2 which has similar mechanisms in it that just landed for quic.

@stv0g stv0g changed the title reduce candidateBase.writeTo cpu cost Reduce candidateBase.writeTo cpu cost Jan 12, 2023
@stv0g stv0g changed the title Reduce candidateBase.writeTo cpu cost Reduce candidateBase.writeTo CPU cost Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants