ice
ice copied to clipboard
Reduce `candidateBase.writeTo` CPU cost
Summary

Motivation
reduce candidateBase.writeTo cpu cost
Describe alternatives you've considered
Maybe we can use bufio in candidateBase.writeTo, like:
https://github.com/grpc/grpc-go/pull/1544/commits/30d8f0749874c54017578cf0760e18c01d27a3a2
Additional context
https://github.com/pion/ice/blob/master/candidate_base.go#L152
https://github.com/xtaci/kcp-go/blob/9f0f2bc5547c9ae7943d1a729f382494e4a2fd65/tx_linux.go#L25 Maybe good solution! https://github.com/golang/net/blob/master/ipv4/batch.go#L108 call https://github.com/golang/net/blob/master/internal/socket/sys_linux.go#L24:6 http://man7.org/linux/man-pages/man2/sendmmsg.2.html
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
:fire: 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.
🔥 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 :)
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.
How much does it increase latency?
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.