#worker-thread #media-server #sans-io #run-time #sdn #task #controller

sans-io-runtime

An opinionated SANS-IO runtime for SDN and media servers

4 releases (2 breaking)

0.3.0 Nov 8, 2024
0.2.1 Aug 23, 2024
0.2.0 Jul 22, 2024
0.1.0 Jul 18, 2024

#775 in Network programming

Download history 433/week @ 2024-08-18 96/week @ 2024-08-25 67/week @ 2024-09-01 223/week @ 2024-09-08 204/week @ 2024-09-15 276/week @ 2024-09-22 387/week @ 2024-09-29 93/week @ 2024-10-06 49/week @ 2024-10-13 106/week @ 2024-10-20 90/week @ 2024-10-27 399/week @ 2024-11-03 178/week @ 2024-11-10 250/week @ 2024-11-17 450/week @ 2024-11-24 62/week @ 2024-12-01

1,018 downloads per month
Used in 2 crates

MIT license

180KB
3.5K SLoC

Rust 3K SLoC // 0.0% comments JavaScript 602 SLoC // 0.3% comments

License: MIT Discord

SANS-I/O runtime (Working in progress)

(This module is in very early stage of development. It is not ready for production use.)

This is a simple, lightweight, and fast runtime for the SansIo mechanism.

Goal

The goal of this project is to provide a simple, lightweight, and fast runtime for the SansIo mechanism. The runtime should be able to run on any platform with variables network library like: mio, io_uring, af_xdp.

How it works

Controller will spawn some threads and each thread will run a worker. The workers

Features

Impl C/I Works Benchmark Group Description
[x] [ ] [x] [ ] Control Cross tasks communication
[x] [ ] [x] [x] Control Controller to worker communication
[x] [ ] [x] [ ] Control Controller to task communication
[x] [ ] [x] [ ] Control Workers status monitoring
[x] [ ] [x] [ ] I/O Udp
[x] [ ] [x] [ ] I/O Tun/Tap
[ ] [ ] [ ] [ ] I/O Tcp
[ ] [ ] [ ] [ ] I/O Rpc
[x] [ ] [x] [ ] Backend mio
[x] [ ] [x] [ ] Backend raw poll
[x] [ ] [x] [ ] Backend polling
[ ] [ ] [ ] [ ] Backend io_uring
[ ] [ ] [ ] [ ] Backend af_xdp
[x] [ ] [x] [ ] Example Udp echo server
[x] [ ] [x] [ ] Example Udp echo client
[x] [ ] [x] [ ] Example Simple Whip/Whep server

Benchmarking

  • External communication can archive 1.5M messages (1500 bytes) per second, that is 1.5M * 1500 * 8 = 18Gbps, this is just enough for almost of application. The latency is 2.5ms, because of we doing in polling base, maybe it can improve by using interrupt base.

Design

Design

Single task

Bellow is state diagram of a single task.

stateDiagram
    [*] --> Created
    Created --> Waiting : attach to worker
    Waiting --> OnTick : timer fired
    OnTick --> Waiting : no output
    OnTick --> PopOutput : has output
    PopOutput --> PopOutput : has output
    PopOutput --> Waiting : no output
    Waiting --> OnInput : I/O, Bus
    OnInput --> Waiting : no output
    OnInput --> PopOutput : has output

The idea is in SAN/IO style, each task will reduce memory by create output immediately after input. We need to pop the output before we can receive the next input.

Multi tasks

With idea of SAN/IO is we need to pop the output before we can receive the next input. This is a problem when we have multiple tasks. We need to have a way to control the order of the tasks.

stateDiagram
    [*] --> Created
    Created --> Waiting : attach groups to worker
    Waiting --> OnTick : timer fired
    OnTick --> OnTickSingleTask : next task
    OnTick --> Waiting : no task
    OnTickSingleTask --> OnTick : no output
    OnTickSingleTask --> PopCurrentTickTaskOutput : has output
    PopCurrentTickTaskOutput --> PopCurrentTickTaskOutput : has output
    PopCurrentTickTaskOutput --> OnTick : no output

    Waiting --> OnInput : I/O, Bus
    OnInput --> OnInputSingleTask : has task
    OnInputSingleTask --> Waiting : no output
    OnInputSingleTask --> PopCurrentInputTaskOutput : has output
    PopCurrentInputTaskOutput --> PopCurrentInputTaskOutput : has output
    PopCurrentInputTaskOutput --> Waiting : no output

Dependencies

~2–30MB
~456K SLoC