mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-22 08:24:25 +01:00
make a lil less garbage
This commit is contained in:
@@ -24,6 +24,9 @@ type StdConn struct {
|
|||||||
l *logrus.Logger
|
l *logrus.Logger
|
||||||
batch int
|
batch int
|
||||||
enableGRO bool
|
enableGRO bool
|
||||||
|
|
||||||
|
msgs []rawMessage
|
||||||
|
iovs [][]iovec
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListener(l *logrus.Logger, ip netip.Addr, port int, multi bool, batch int) (Conn, error) {
|
func NewListener(l *logrus.Logger, ip netip.Addr, port int, multi bool, batch int) (Conn, error) {
|
||||||
@@ -63,7 +66,16 @@ func NewListener(l *logrus.Logger, ip netip.Addr, port int, multi bool, batch in
|
|||||||
return nil, fmt.Errorf("unable to bind to socket: %s", err)
|
return nil, fmt.Errorf("unable to bind to socket: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &StdConn{sysFd: fd, isV4: ip.Is4(), l: l, batch: batch}, err
|
msgs := make([]rawMessage, 0, 8192) //todo configure
|
||||||
|
iovs := make([][]iovec, 0, len(msgs))
|
||||||
|
return &StdConn{
|
||||||
|
sysFd: fd,
|
||||||
|
isV4: ip.Is4(),
|
||||||
|
l: l,
|
||||||
|
batch: batch,
|
||||||
|
msgs: msgs,
|
||||||
|
iovs: iovs,
|
||||||
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *StdConn) Rebind() error {
|
func (u *StdConn) Rebind() error {
|
||||||
@@ -207,8 +219,8 @@ func (u *StdConn) WriteBatch(pkts []*packet.Packet) (int, error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
msgs := make([]rawMessage, 0, len(pkts)) //todo recycle
|
u.msgs = u.msgs[:0]
|
||||||
iovs := make([][]iovec, 0, len(pkts))
|
u.iovs = u.iovs[:0]
|
||||||
|
|
||||||
sent := 0
|
sent := 0
|
||||||
const maxIovLen = 48
|
const maxIovLen = 48
|
||||||
@@ -221,26 +233,26 @@ func (u *StdConn) WriteBatch(pkts []*packet.Packet) (int, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
lastIdx := idx - 1
|
lastIdx := idx - 1
|
||||||
if mostRecentPkt != nil && pkt.CompatibleForSegmentationWith(mostRecentPkt) && msgs[lastIdx].Hdr.Iovlen < maxIovLen { //todo math this more good
|
if mostRecentPkt != nil && pkt.CompatibleForSegmentationWith(mostRecentPkt) && u.msgs[lastIdx].Hdr.Iovlen < maxIovLen { //todo math this more good
|
||||||
|
|
||||||
msgs[lastIdx].Hdr.Controllen = uint64(len(mostRecentPkt.Control))
|
u.msgs[lastIdx].Hdr.Controllen = uint64(len(mostRecentPkt.Control))
|
||||||
msgs[lastIdx].Hdr.Control = &mostRecentPkt.Control[0]
|
u.msgs[lastIdx].Hdr.Control = &mostRecentPkt.Control[0]
|
||||||
msgs[lastIdx].Hdr.Iovlen++
|
u.msgs[lastIdx].Hdr.Iovlen++
|
||||||
iovs[lastIdx] = append(iovs[lastIdx], iovec{
|
u.iovs[lastIdx] = append(u.iovs[lastIdx], iovec{
|
||||||
Base: &pkt.Payload[0],
|
Base: &pkt.Payload[0],
|
||||||
Len: uint64(len(pkt.Payload)),
|
Len: uint64(len(pkt.Payload)),
|
||||||
})
|
})
|
||||||
mostRecentPkt.SetSegSizeForTX()
|
mostRecentPkt.SetSegSizeForTX()
|
||||||
} else {
|
} else {
|
||||||
msgs = append(msgs, rawMessage{})
|
u.msgs = append(u.msgs, rawMessage{})
|
||||||
iovs = append(iovs, make([]iovec, 1, maxIovLen)) //todo
|
u.iovs = append(u.iovs, make([]iovec, 1, maxIovLen)) //todo less garbage
|
||||||
iovs[idx][0] = iovec{
|
u.iovs[idx][0] = iovec{
|
||||||
Base: &pkt.Payload[0],
|
Base: &pkt.Payload[0],
|
||||||
Len: uint64(len(pkt.Payload)),
|
Len: uint64(len(pkt.Payload)),
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &msgs[idx]
|
msg := &u.msgs[idx]
|
||||||
iov := &iovs[idx][0]
|
iov := &u.iovs[idx][0]
|
||||||
idx++
|
idx++
|
||||||
|
|
||||||
msg.Hdr.Iov = iov
|
msg.Hdr.Iov = iov
|
||||||
@@ -255,17 +267,17 @@ func (u *StdConn) WriteBatch(pkts []*packet.Packet) (int, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msgs) == 0 {
|
if len(u.msgs) == 0 {
|
||||||
return sent, nil
|
return sent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := 0
|
offset := 0
|
||||||
for offset < len(msgs) {
|
for offset < len(u.msgs) {
|
||||||
n, _, errno := unix.Syscall6(
|
n, _, errno := unix.Syscall6(
|
||||||
unix.SYS_SENDMMSG,
|
unix.SYS_SENDMMSG,
|
||||||
uintptr(u.sysFd),
|
uintptr(u.sysFd),
|
||||||
uintptr(unsafe.Pointer(&msgs[offset])),
|
uintptr(unsafe.Pointer(&u.msgs[offset])),
|
||||||
uintptr(len(msgs)-offset),
|
uintptr(len(u.msgs)-offset),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -284,7 +296,7 @@ func (u *StdConn) WriteBatch(pkts []*packet.Packet) (int, error) {
|
|||||||
offset += int(n)
|
offset += int(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sent + len(msgs), nil
|
return sent + len(u.msgs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *StdConn) encodeSockaddr(dst []byte, addr netip.AddrPort) (uint32, error) {
|
func (u *StdConn) encodeSockaddr(dst []byte, addr netip.AddrPort) (uint32, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user