Ant Farm - A concurrent M:N jobs distributor
Nathan Riddick
nathan.judge at gmail.com
Sun Oct 25 20:44:28 UTC 2026
On Friday, 23 October 2026 at 16:20:48 UTC, Nathan Riddick wrote:
> On Monday, 24 August 2026 at 23:04:33 UTC, Nathan Riddick wrote:
>> Hello, I had an idea for a non-FIFO concurrent callback-jobs
>> thing based on a ring buffer. It seems to have strong
>> performance and utility for my next set of tinkerings. I came
>> up with ~90% of the spec and made some attempts at a clean
>> implementation, but Kimi K3 ultimately came through with an
>> initial clean version and various other LLMs were very useful
>> at grinding out late-night debug sessions with infinite
>> patience.
>>
>> tl;dr synthetic throughput sits between moodycamel no-tokens
>> and with-tokens at a few million items/sec, seems to prefer
>> more concurrency rather than less, the latency at reaching
>> one-more item after a big block of work crushes FIFO designs
>> generally, it's adaptive to a homogenous thread pool that
>> shrinks or grows over time, API is @nogc nothrow @system and
>> probably thread-safe.
>>
>> https://github.com/nriddick/antfarm
>
> More work done, and I think it's in a pretty good spot. The
> core features and parallel-for/actors/fork-join are betterC and
> work without DRuntime, and a C ABI includes those with or
> without the worker pool host (leaving out the DRuntime Fibers).
>
> Ryzen 9 5900XT (16 cores, two L3 groups):
> One Farm: 2.49 billion one-word payloads singly delivered per
> second at 24 threads, above two billion from 8 threads up.
> Private child lifecycles, which are spawn, dispatch, retire and
> refill, peak at 517 million per second at 16 threads.
> One Farm per L3 group: 4.09 billion payloads per second at 32
> threads, and 886 million child lifecycles per second.
>
> Coding agents (Opus 5.5 and Sonnet 5.5 at medium and high
> effort) implemented Game of Life and a composite scheduler
> frame against Ant Farm, oneTBB and Rayon. At 30 to 40 threads
> Ant Farm led the small frame by about 10 to 15% over oneTBB and
> tied it on the heavy frame; at 8 and 15 threads the three were
> within a few percent. Harness and prompts for reproduction:
> github.com/nriddick/antfarm-bench
I shamelessly copied citor's
(https://github.com/Lallapallooza/citor) work-stealing deque
design as a synchronous complement that handles recursion much
better than the ring. And my previous studiousness of host-group
topology, and obsessiveness around things like nothrow actually
favors the slopped up D implementation over the C++ libraries:
Ryzen 5900XT (16 cores / 32 threads / 2 CCDs)
| Benchmark | Runtime | 1 | 2 | 8 | 16 | 24 | 32 |
|---|---|---:|---:|---:|---:|---:|---:|
| fib(39) | citor 0.4.5 | 1,858.2 | 998.5 | 257.6 | 141.0 | 140.7
| 107.8 |
| fib(39) | libfork | 1,973.5 | 1,045.1 | 275.1 | 157.3 | 147.9 |
141.3 |
| fib(39) | TooManyCooks | 2,603.8 | 1,319.9 | 351.4 | 211.5 |
209.8 | 205.7 |
| fib(39) | TBB | 6,985.9 | 3,558.5 | 953.2 | 557.0 | 542.0 |
533.4 |
| fib(39) | Ant Farm fork-join | **1,163.0** | **703.7** |
**190.2** | **111.7** | **106.9** | **103.7** |
| skynet | citor 0.4.5 | 569.6 | 485.1 | 126.0 | 68.9 | 69.0 |
54.2 |
| skynet | libfork | 1,244.0 | 655.0 | 167.3 | 97.3 | 96.7 | 96.3
|
| skynet | TooManyCooks | 1,181.1 | 606.4 | 162.6 | 96.5 | 92.9 |
90.4 |
| skynet | TBB | 4,192.5 | 2,096.1 | 562.5 | 321.7 | 310.8 |
301.6 |
| skynet | Ant Farm fork-join | **338.7** | **334.4** | **89.4**
| **52.2** | **51.1** | **49.0** |
| nqueens | citor 0.4.5 | 2,787.1 | 1,582.2 | 411.2 | 217.4 |
218.0 | 168.5 |
| nqueens | libfork | 2,312.0 | 1,210.5 | 316.3 | 167.2 | 153.3 |
141.6 |
| nqueens | TooManyCooks | 2,556.8 | 1,277.4 | 340.5 | 188.7 |
175.7 | 162.0 |
| nqueens | TBB | 4,163.9 | 2,094.0 | 569.6 | 310.6 | 280.7 |
259.0 |
| nqueens | Ant Farm fork-join | **2,059.4** | **1,019.2** |
**272.0** | **148.0** | **134.6** | **124.3** |
| matmul 2048 | citor 0.4.5 | 1,334.6 | 676.0 | 176.9 | 104.1 |
104.0 | 69.8 |
| matmul 2048 | libfork | **1,168.8** | 609.4 | 165.7 | **90.3**
| **70.1** | **60.3** |
| matmul 2048 | TooManyCooks | 1,208.9 | **607.9** | **160.8** |
93.5 | 72.1 | 62.4 |
| matmul 2048 | TBB | 1,249.3 | 630.3 | 178.8 | 103.1 | 82.4 |
72.2 |
| matmul 2048 | Ant Farm fork-join | 1,181.2 | 611.4 | 162.0 |
93.3 | 71.3 | 60.8 |
More information about the Digitalmars-d
mailing list