fib: take best routes from the table 16384 at a time

The kernel task read changes of best route from the routing table 1024
at a time. A poll of the table does two binary searches and takes a read
lock in every shard, however few events the shard has; with the 128
shards of an 8-core machine, that overhead was paid for every 8 events a
shard, and the profile of a full-table load showed 8% to 9% of the
daemon's CPU time in the reader's searches and locks.

This change raises the batch to 16384. In the Linux VM, with four peers
sending the synthetic table of 1.23 million prefixes, the kernel is in
step 2.2 s after the first route instead of 2.9 s, and the daemon's CPU
time over the load falls 13%; the reader's share drops from 9% to under
1%. With one peer the kernel-side share falls the same way and the CPU
time 3%. A batch holds up to 16384 small records between polls, which is
about a megabyte.

Testing: the fib unit tests pass; measured with
scripts/profile/full-table.sh with one and four peers.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Rayhaan JaufeerallyandClaude Fable 5.1 committed 2026-10-09 00:07:46 +02:00
1 parent 5915c8e562
commit 9e9e4f90ef
1 file changed
+5 -2
+5 -2
View File
@@ -34,8 +34,11 @@ use crate::routes::KernelRoutes;
use crate::topology::Topology; use crate::topology::Topology;
use crate::{Fib, FibConfig, FibError, Stop}; use crate::{Fib, FibConfig, FibError, Stop};
/// How many best routes are taken from the routing table at a time. /// How many best routes are taken from the routing table at a time. A
const BATCH: usize = 1024; /// poll of the table costs two binary searches and a lock in every shard,
/// however few events it brings back; with a few hundred shards, a batch
/// of a thousand had that overhead for every eight events a shard.
const BATCH: usize = 16384;
/// How many requests are sent to the kernel in one write. /// How many requests are sent to the kernel in one write.
const WRITE_BATCH: usize = 512; const WRITE_BATCH: usize = 512;