Exadra37

Exadra37

Today I saw this tweet:

https://twitter.com/davidfowl/status/1362962967789072386

While it starts in the context of DOTNET:

Thread pool starvation affects everyone. Learnt about a service that went down because the dns server died and dns queries were hanging (there was no timeout). That in itself is a problem but it causes issues because dns resolution is synchronous… #dotnet

Dns resolution is historically blocking on every OS. See getaddrinfo. Modern operation systems have an asynchronous version of this API. Windows has GetAddrInfoExA/W https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfoexa and Linux has https://linux.die.net/man/3/getaddri

DNS resolution on windows is fully async on .NET if the operation system supports it. In .NET 6, we support it on linux as well. Both of these were external contributions!

Before .NET 6 and in most other platforms I’ve looked at, dns resolution is still blocking. This means that even if you use the async APIs, it’ll kick off a synchronous operation and block a thread pool thread.

I then moves to compare how it is done in NodeJS:

This lead me to look at what nodejs does here. Would it have run into the same problem? Nodejs uses libuv which is a libraries that tries to abstract various OS operations (file, socket, tty, etc) into a single unified API. But what does it do for dns resolution?

Turns out, for the APIs that aren’t truly asynchronous everywhere (file IO, DNS) nodejs uses a threadpool that runs work off the event loop. This means you aren’t blocking the event loop but non-event loop threads are being blocked with dns queries.

What happens when these threads are starved? Well node does this thing where it only uses 1/2 of the threads for this “slow IO”, the other work just queues up behind this blocking work. This results in a similar effect to thread pool starvation as the queue length just grows…

This would manifest as callback not being called and lots of work being scheduled (assuming lots of new DNS requests keep showing up) but never completing. I’m not sure what this is called in the node world, if anyone knows, please let me know.

Now he goes about comparing how its done in Golang:

Let’s see what the other languages do. Go blocks a goroutine and waits on a channel. It’ll eventually spin up a new OS thread if the goroutine blocks too long. Strangely, this logic uses cgo :thinking:

Due to nature of pre-emptive scheduler of the BEAM and the possibility of having millions of BEAM processes running at same time I have the impression that this would not be such a big issue, but now I am curious to understand what would be implications on the BEAM when running DNS service application.

So, what is your take about a DNS service running on the BEAM? Could it lead to OS threads starvation?

Showing Posts 1 to 10

dimitarvp

dimitarvp

It’s not at all an issue unless your OS/kernel hit you with limits – in which case you can’t do anything.

BEAM’s philosophy is to basically allow you to have a million synchronous I/O requests and check which one is ready to go – and it does that really fast (thanks to Linux kernel magic like select / epoll). Golang’s core feature – the goroutines – and Rust libraries like rayon work exactly like your quote described:

Which is a way to be conservative about spawning threads because they are a more expensive operation in terms of CPU, RAM, context switches and what-have-you.

IMO just having a warm thread-pool ever since your program starts – like the BEAM does – is the best policy. Just have anywhere from N to N*4 threads ready (where N = number of CPU cores) when the program starts.


I would caution against using the BEAM for a DNS server; Erlang/Elixir are not known for raw muscle power. Using Rust’s async capabilities is IMO literally the best option of all. A well-written Rust program can saturate a 10Gbps network card on a mid-range server.

AstonJ

AstonJ

Wasn’t there a blog post recently about a DNS service using Elixir/Erlang? Can’t find it now but do remember this - Erlang basically powers the internet :003:

90% of the worlds internet traffic goes through Cisco’s Erlang based routers:

hauleth

hauleth

Through “Erlang controlled” not “implemented in Erlang”. Switches have highly optimised FPGAs as a “core” as even hand written assembly in generic purpose CPU would be way to slow for high throughput switching that is needed at the core of the internet.

And there is nothing about DNS in this talk.

AstonJ

AstonJ

Yes it was more an aside and I’d love for Cisco to blog more about how they use Erlang and how it might help in other related areas, particularly those that underpin the internet.

With regards to Elixir/Erlang and DNS itself, not being able to find that article is going to bug me now :lol: I’m sure they talked about how they went to handling thousands of additional requests a second with Elixir and iirc, it was a very recent article - like a few days or weeks old at most :neutral_face:

AstonJ

AstonJ

YES that is the one! Thank you Derek! It would have driven me nuts otherwise :044:

5 billion DNS queries a month with a huge requirement to have maximum uptime

hauleth

hauleth

I never said that Erlang isn’t good choice for DNS server. In fact I am thinking about writing PiHole alternative in Elixir/Erlang, as the UI of that is quite limiting (for example I can set only A records for local domains or it seems that there is no UI for DHCPv6). Maybe one day I will do that.

sasajuric

sasajuric

Author of Elixir In Action

I already responded on twitter, but for the sake of completeness I’ll redo it here. From what I can tell, Erlang uses its own dns resolver, inet_res, which is written in plain Erlang, so this issue should not surface in Erlang.

More generally, if the runtime uses a potentially long-running syscall, the thread pool can be exhausted. My feeling is that the OTP team tries to avoid these scenarios, and that such issues would already surface in practice, but I don’t have any data to back this claim.

Exadra37

Exadra37 OP

So, @sasajuric invited @garazdawi to the conversation and seems that now we have the answer:

https://twitter.com/garazdawi/status/1365430001210953728?s=20

Exadra37

Exadra37 OP

Today I wake-up and looking to my previous post I am not sure If I totally understand the Tweet I linked above.

Some questions for @garazdawi:

You mean that Erlang can do OS blocking calls that make OS spin threads, thus making possible for the BEAM to starve the OS from threads?

You mean a DNS implementation? Can you link to both? If not can you expand on this?

Where Next? Top

Trending in Discussions Top

AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4663 61218 595
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
515 12931 101
New
sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
gtcode
I’ve been tinkering with Lynx (by José) via hold_ledger. I used AI to write the code, a separate specification, the tests, and the Lean p...
New
AstonJ
A remark @Garrison made… ..has already inspired a thread for the technical side of reclaiming our internet, but there is of course anot...
New
ManuelGarcia
Hi everyone! I’m the developer of PaperForge, and I’ve been working on something alongside it that I’d like your opinion on. I’m conside...
New
bartblast
This is where the projects in the Hologram Showcase get posted: apps built with Hologram and libraries made for it. New ones go up usuall...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews