Skip to content

Commit ffe5acf

Browse files
osamu620claude
andcommitted
revert(wt_bridge): remove recvmmsg batch reads
Go's netpoller wakes the goroutine per-packet, so ReadBatch consistently returns batch=1 — no syscall reduction. The mmsghdrsPacker setup adds overhead for no benefit. Revert to plain ReadFromUDP. The pprof endpoint (--pprof) is kept. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 39d1805 commit ffe5acf

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

tools/wt_bridge/fanout.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"sync"
1313
"sync/atomic"
1414

15-
"golang.org/x/net/ipv4"
1615
)
1716

1817
type fanout struct {
@@ -88,9 +87,8 @@ func (f *fanout) broadcast(pkt []byte) {
8887
}
8988

9089
// runUDPIn binds and drains a UDP socket into the fanout until ctx is done.
91-
// Uses recvmmsg (Linux) to batch up to 64 packets per syscall.
9290
func (f *fanout) runUDPIn(ctx context.Context, listen *net.UDPAddr) error {
93-
conn, err := net.ListenUDP("udp4", listen)
91+
conn, err := net.ListenUDP("udp", listen)
9492
if err != nil {
9593
return err
9694
}
@@ -106,28 +104,19 @@ func (f *fanout) runUDPIn(ctx context.Context, listen *net.UDPAddr) error {
106104
_ = conn.Close()
107105
}()
108106

109-
const batch = 64
110-
pc := ipv4.NewPacketConn(conn)
111-
msgs := make([]ipv4.Message, batch)
112-
for i := range msgs {
113-
msgs[i].Buffers = [][]byte{make([]byte, 2048)}
114-
}
115-
107+
buf := make([]byte, 65536)
116108
for {
117-
n, err := pc.ReadBatch(msgs, 0)
109+
n, _, err := conn.ReadFromUDP(buf)
118110
if err != nil {
119111
if ctx.Err() != nil {
120112
return nil
121113
}
122114
return err
123115
}
124-
for i := 0; i < n; i++ {
125-
pktLen := msgs[i].N
126-
f.packetsIn.Add(1)
127-
f.bytesIn.Add(uint64(pktLen))
128-
pkt := make([]byte, pktLen)
129-
copy(pkt, msgs[i].Buffers[0][:pktLen])
130-
f.broadcast(pkt)
131-
}
116+
f.packetsIn.Add(1)
117+
f.bytesIn.Add(uint64(n))
118+
pkt := make([]byte, n)
119+
copy(pkt, buf[:n])
120+
f.broadcast(pkt)
132121
}
133122
}

0 commit comments

Comments
 (0)