mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-15 12:46:52 +01:00
tun: Hold one transmit mode per routine
With staged transmit, an idle reader encrypted and sent a small read itself, while larger reads went to the workers and left from the ordered sender. Each read chose on its own, so under load a routine alternated between the two paths. Their packets left from different CPUs, and the receiver's TCP saw them out of order: on 100 GbE, summed over four hosts, dsack_dups rose from 0-1 on master to about 25k and reord_seen from 0 to 13k-19k. Each routine now holds one mode, inline on the reader or fanout to the workers and the sender. It switches only after tun.staged.gate_hold (default 64) reads in a row want the other mode, and before going inline it waits until every batch in flight is on the wire, so a switch never lets a later packet overtake an earlier one. Going to fanout nothing is in flight. flow.tx.gate_switches counts the switches. On the same hosts dsack_dups fell to 20-52 and reord_seen to 0-2, while throughput matched or beat per-read mixing (many-to-one 34.9 instead of 30.7 Gbit/s). The affinity test waited only for the previous batch's packets to be captured before the next read, but the sender returns the slot after its write, so the reader could still see it in flight and stage the small read. Switching to inline now drains, which makes the inline send deterministic there.
This commit is contained in:
1 parent
d16a52f921
commit
51591b0cec
7 files changed
+232
-23
No files matched your search
+18
-7
@@ -295,6 +295,11 @@ func TestFlowStagedTXAffinity(t *testing.T) {
|
||||
if pin && len(allowed) < 2 {
|
||||
t.Skip("requires at least two allowed CPUs")
|
||||
}
|
||||
if sc.inlineBelow > 0 {
|
||||
// Switch on every read that wants the other mode, so the small read goes inline between
|
||||
// staged ones
|
||||
sc.gateHold = 1
|
||||
}
|
||||
sender, receiver := newFlowTestPair(t, noise.CipherChaChaPoly, sc)
|
||||
f := sender.f
|
||||
f.pinThreads, f.routines = pin, routines
|
||||
@@ -417,20 +422,23 @@ func TestFlowTXBudgetManyReaders(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFlowStagedTXInlineOnlyWhenEmpty: a small read behind a staged batch still in flight must not go inline, it
|
||||
// would overtake that batch.
|
||||
// TestFlowStagedTXInlineOnlyWhenEmpty: a small read behind a staged batch still in flight must not go inline before
|
||||
// that batch is on the wire, it would overtake it.
|
||||
func TestFlowStagedTXInlineOnlyWhenEmpty(t *testing.T) {
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreCurrent())
|
||||
sc := adaptive(2)
|
||||
sc.inlineBelow = 4
|
||||
sc.inlineBelow, sc.gateHold = 4, 1
|
||||
sender, receiver := newFlowTestPair(t, noise.CipherChaChaPoly, sc)
|
||||
p := newStagedTx(sender.f, newFlowBatchQueue(nil), 0)
|
||||
block := make(chan struct{})
|
||||
delayCrypto(sender, func(uint64) { <-block })
|
||||
batches, want := flowTestBatches(1, 4, 1, 3)
|
||||
p.send(batches[0][:3]) // its worker is blocked
|
||||
p.send(batches[0][3:])
|
||||
close(block)
|
||||
p.send(batches[0][:3]) // switches to fanout, its worker is blocked
|
||||
require.Equal(t, 1, p.inFlight)
|
||||
unblock := time.AfterFunc(20*time.Millisecond, func() { close(block) })
|
||||
defer unblock.Stop()
|
||||
p.send(batches[0][3:]) // switches to inline, which waits for the staged batch first
|
||||
require.Zero(t, p.inFlight)
|
||||
p.close()
|
||||
require.Equal(t, want, decryptWire(t, receiver, sender.conn.captured()))
|
||||
}
|
||||
@@ -512,7 +520,10 @@ func TestFlowStagedTXAdaptiveBudget(t *testing.T) {
|
||||
} {
|
||||
t.Run(shape.name, func(t *testing.T) {
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreCurrent())
|
||||
sender, receiver := newFlowTestPair(t, noise.CipherChaChaPoly, adaptive(2))
|
||||
sc := adaptive(2)
|
||||
// p0's large read must go to the workers at once, p1 stays inline
|
||||
sc.gateHold = 1
|
||||
sender, receiver := newFlowTestPair(t, noise.CipherChaChaPoly, sc)
|
||||
sender.f.routines = 2
|
||||
sender.f.writers = []udp.Conn{sender.conn, sender.conn}
|
||||
ci := sender.hostinfo.ConnectionState
|
||||
|
||||
Reference in new issue
Block a user