Lighthouse handler optimizations (#320)

We noticed that the number of memory allocations LightHouse.HandleRequest creates for each call can seriously impact performance for high traffic lighthouses. This PR introduces a benchmark in the first commit and then optimizes memory usage by creating a LightHouseHandler struct. This struct allows us to re-use memory between each lighthouse request (one instance per UDP listener go-routine).
This commit is contained in:
Wade Simmons
2020-11-23 14:50:01 -05:00
committed by GitHub
parent 672ce1f0a8
commit 2e7ca027a4
5 changed files with 151 additions and 43 deletions

View File

@ -108,6 +108,8 @@ func (u *udpConn) ListenOut(f *Interface) {
udpAddr := &udpAddr{}
nb := make([]byte, 12, 12)
lhh := f.lightHouse.NewRequestHandler()
for {
// Just read one packet at a time
n, rua, err := u.ReadFromUDP(buffer)
@ -117,7 +119,7 @@ func (u *udpConn) ListenOut(f *Interface) {
}
udpAddr.UDPAddr = *rua
f.readOutsidePackets(udpAddr, plaintext[:0], buffer[:n], header, fwPacket, nb)
f.readOutsidePackets(udpAddr, plaintext[:0], buffer[:n], header, fwPacket, lhh, nb)
}
}