nox-rss#
Receive Side Scaling (RSS): the Toeplitz flow hash a NIC uses to steer a packet to a receive queue, plus the pieces a share-nothing software stack needs to do the same across cores.
The opam name is
nox-rssbecauserssis already the RSS feed library. This is Receive Side Scaling, not Really Simple Syndication.
Overview#
Distributing a network flow across N independent owners (NIC queues, CPU cores, share-nothing stacks) needs three things, and this library is exactly those three:
- A flow hash. The Toeplitz hash over the connection tuple, with Microsoft's 40-byte default key -- the exact hash hardware RSS computes (Intel 82599 datasheet 7.1.2.8.3). Exposed both asymmetric (what a NIC computes; swapping the endpoints changes the result) and symmetric (the endpoints are ordered first, so both directions of a flow hash equal -- what a NAT or per-core stack needs to keep a bidirectional flow on one owner).
- An owner reduction. The RSS indirection that folds a 32-bit hash onto
countowners. - Ephemeral-port lanes (RFC 6335). Each owner allocates its source/NAT ports from its own stride of the dynamic range (49152-65535), so a reply addressed to one of those ports steers back to the owner that opened the flow -- the piece that makes NAT and connect() shardable.
I/O-free and dependency-light (ipaddr only): it computes indices and ports,
it does not touch the network. Framing and dispatch belong to the caller.
Usage#
$ opam install nox-rss
Steer a flow to one of count share-nothing owners, both directions alike:
let steer ~count ~src ~dst ~src_port ~dst_port =
let h = Rss.hash ~symmetric:true ~src ~dst ~ports:(src_port, dst_port) () in
Rss.owner ~count h
An owner allocates its ports from its own lane so replies come back to it:
let my_first_port ~count ~owner = Rss.first_port ~count ~owner
let owner_of_reply ~count port = Rss.port_owner ~count port
API#
Rss.toeplitz ~key data- the raw 32-bit Toeplitz hash (asymmetric).Rss.hash ~src ~dst ?ports ()- hash a flow tuple;~symmetric:truefor direction-independent flow affinity.Rss.owner ~count hash- reduce a hash to one ofcountowners.Rss.port_owner ~count port/Rss.first_port ~count ~owner- RFC 6335 dynamic-port lanes.Rss.encode_flow_id/decode_flow_id/owner_of_flow_id- embed the owner in a cross-owner flow identifier.
Related Work#
RSS and its symmetric variant are standard practice; this is a pure-OCaml implementation of the same algorithms.
- Microsoft RSS - the original NDIS RSS specification and the Toeplitz hash / default key.
- DPDK
rte_thash- DPDK's Toeplitz hash; itsapp/test/test_thash.ccarries the Intel 82599 verification vectors this library is tested against. - Linux RSS / RPS / RFS - hardware and software receive steering; the symmetric-hash technique for bidirectional flow affinity.
rss- the unrelated OCaml RSS/Atom feed library that owns therssopam name.
License#
ISC License. See LICENSE.md for details.