mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
This commit bumps the wireguard-go dependency to incorporate changes to the packet memory model and the tun.Device.Read and conn.ReceiveFunc I/O interfaces. It updates their implementations accordingly. These changes improve throughput in all measured benchmarks and reduce peak RSS in six of eight cases. The two regressions will be addressed in a follow-up commit that reduces peak RSS below the baseline measured at1e69418. That work is kept separate to simplify review. The following throughput and peak RSS benchmarks were performed with iperf3 between two Intel i5-12400 nodes running Ubuntu 24.04 (Linux 6.8). The UDP benchmarks did not use UDP GSO on the sender, so they were roughly equivalent to single packet I/O through wireguard-go. TCP/1 signifies one TCP stream; TCP/128 signifies 128 parallel TCP streams. Throughput (Mb/s) Test1e69418After Change TCP/1 10,371 11,354 +9.5% TCP/128 7,886 8,404 +6.6% UDP/1 2,111 2,853 +35.1% UDP/128 1,747 2,235 +28.0% Peak memory (VmHWM, kB) Test Side1e69418After Change TCP/1 TX 98,240 52,596 -46.5% RX 287,748 73,384 -74.5% TCP/128 TX 101,196 52,812 -47.8% RX 290,420 63,620 -78.1% UDP/1 TX 58,864 160,840 +173.2% RX 137,516 49,900 -63.7% UDP/128 TX 66,148 116,096 +75.5% RX 154,384 56,556 -63.4% Updates tailscale/corp#46716 Updates tailscale/corp#22467 Updates tailscale/corp#36989 Updates tailscale/corp#37878 Signed-off-by: Jordan Whited <[email protected]>
106 lines
3.4 KiB
Go
106 lines
3.4 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package tundevstats
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"os"
|
|
"sync/atomic"
|
|
"testing"
|
|
"testing/synctest"
|
|
"time"
|
|
"unsafe"
|
|
|
|
"github.com/mdlayher/netlink"
|
|
"github.com/mdlayher/netlink/nltest"
|
|
"github.com/tailscale/wireguard-go/tun"
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func Test_getIfIndex(t *testing.T) {
|
|
ifIndex, err := getIfIndex("lo")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if ifIndex != 1 {
|
|
// loopback ifIndex is effectively always 1 on Linux, see
|
|
// LOOPBACK_IFINDEX in the kernel (net/flow.h).
|
|
t.Fatalf("expected ifIndex of 1 for loopback, got: %d", ifIndex)
|
|
}
|
|
}
|
|
|
|
type fakeDevice struct {
|
|
name string
|
|
}
|
|
|
|
func (f *fakeDevice) File() *os.File { return nil }
|
|
func (f *fakeDevice) Read(slab []byte, packets []tun.ReadPacket) (n int, err error) { return 0, nil }
|
|
func (f *fakeDevice) Write(bufs [][]byte, offset int) (int, error) { return 0, nil }
|
|
func (f *fakeDevice) MTU() (int, error) { return 0, nil }
|
|
func (f *fakeDevice) Name() (string, error) { return f.name, nil }
|
|
func (f *fakeDevice) Events() <-chan tun.Event { return nil }
|
|
func (f *fakeDevice) Close() error { return nil }
|
|
func (f *fakeDevice) BatchSize() int { return 0 }
|
|
|
|
func Test_poller(t *testing.T) {
|
|
getTXQDropsMetric().Set(0) // reset for test count > 1
|
|
|
|
var drops atomic.Uint64
|
|
// dial is a [nltest.Func] that returns an RTM_NEWSTATS response with [drops]
|
|
// at the txDropped offset within the [rtnlLinkStats64] attribute payload.
|
|
dial := func(req []netlink.Message) ([]netlink.Message, error) {
|
|
if len(req) != 1 {
|
|
t.Fatalf("unexpected number of netlink request messages: %d", len(req))
|
|
}
|
|
if req[0].Header.Type != unix.RTM_GETSTATS {
|
|
t.Fatalf("unexpected netlink request message type: %d want: %d", req[0].Header.Type, unix.RTM_GETSTATS)
|
|
}
|
|
data := make([]byte, unsafe.Sizeof(ifStatsMsg{}))
|
|
ae := netlink.NewAttributeEncoder()
|
|
ae.Do(iflaStatsLink64, func() ([]byte, error) {
|
|
ret := make([]byte, unsafe.Sizeof(rtnlLinkStats64{}))
|
|
binary.NativeEndian.PutUint64(ret[56:], drops.Load())
|
|
return ret, nil
|
|
})
|
|
attrs, err := ae.Encode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
data = append(data, attrs...)
|
|
return []netlink.Message{
|
|
{
|
|
Header: netlink.Header{
|
|
Type: unix.RTM_NEWSTATS,
|
|
Sequence: req[0].Header.Sequence,
|
|
},
|
|
Data: data,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
lo := &fakeDevice{name: "lo"}
|
|
drops.Store(1)
|
|
synctest.Test(t, func(t *testing.T) {
|
|
closer, err := newPollerWithNetlinkDialer(lo, func(family int, config *netlink.Config) (*netlink.Conn, error) {
|
|
return nltest.Dial(dial), nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
synctest.Wait() // first poll complete, poller.run() durably blocked in select
|
|
if got := getTXQDropsMetric().Value(); got != 1 {
|
|
t.Errorf("got drops: %d want: %d", got, 1)
|
|
}
|
|
drops.Store(2) // increment drops to 2
|
|
time.Sleep(pollInterval)
|
|
synctest.Wait() // second poll complete, poller.run() durably blocked in select again
|
|
if got := getTXQDropsMetric().Value(); got != 2 {
|
|
t.Errorf("got drops: %d want: %d", got, 2)
|
|
}
|
|
closer.Close()
|
|
closer.Close() // multiple calls to Close() shouldn't panic
|
|
})
|
|
|
|
}
|