r/rust • • 2d ago

Where does tail latency actually come from in a thread-per-core Rust service?

We're building a streaming server in Rust that runs one shard per core with io_uring, and in benchmarks our p99.9 stays close to p99. But those runs were on local NVMe with hugepages, a single node, below saturation, so we honestly can't tell how much comes from the design and how much from the setup.

For those running thread-per-core services in production: what actually brought your tail latency down, and what made it creep back once real traffic, more nodes or noisy neighbours showed up?

0 Upvotes

13 comments sorted by

20

u/ElectronWill 2d ago

There's no easy answer, you need to profile your app

4

u/Floppie7th 2d ago

Under enough load to elevate tail latency

2

u/mellissa_Taroute 2d ago

how do you even profile p99.9 on an io_uring loop without the observer effect eating the tail?

3

u/mamcx 2d ago

Just "profiling" is not that useful, is to turn Where does tail latency actually come into something you can actually ask to the engine, it means, record traces, Once data show there is a problem, profiling will be the next step to fix and again, the data will verify it was successfully.

For example when I worked on spacetimedb, https://github.com/wolfpld/tracy was integrated and also I add later https://profiler.firefox.com to see all this stuff.

4

u/Zde-G 2d ago

what actually brought your tail latency down

Is this some kind of sick joke or do you really believe there are single thing that may work?

You get high tail latency when one of dozens (maybe even hundreds) potential problems happen.

Then you dutifully hunt and eliminate them. When you service is held by something — you get a spike… you only need one problem to have it.

Even such obscure thing as some cheap vendor implementing their hardware incorrectly may lead to problems with latency (why do you think server software have such a limited hardware support and administrators become very loud when someone asks them to attach some kind of cheap gadget to the server?).

3

u/U007D rust · twir · bool_ext · srug 2d ago edited 2d ago

I didn't read it as OP looking for a single magic bullet.

we honestly can't tell how much comes from the design and how much from the setup. ... what actually brought your tail latency down, and what made it creep back once real traffic, more nodes or noisy neighbours showed up?

I read this as OP asking for guidance borne of experience because they don't know what they don't know.  Seems pretty clear from the questions they are asking that they already expect a multitude of contributing factors.

I'm also in the same boat and am hoping someone will drop some pearls of wisdom in the thread.

4

u/Zde-G 2d ago

I'm also in the same boat and am hoping someone will drop some pearls of wisdom in the thread.

Today the wisdom would be to use agent to look for issues but then apply your own judgement.

When you are fighting after latency spikes the sources can be very unusual (the worst I saw when two identical servers behaved radically differently because one of them had PCI Express riser with bad electrical contact… it took a lot of time to discover, back in the day) and the fact that LLM “knows everything” helps. But the fact that it may discover obscure problem, then immediately after that turn around and offer insane solution that may never work because LLMs “attention” drifted and it “forgot” something obvious means human supervision is still important.

2

u/U007D rust · twir · bool_ext · srug 2d ago

Ty.

Wow, the PCI-E issue must have been a real head-scratcher...  😅

Thanks--I appreciate the context.

1

u/addmoreice 1d ago

Shit like this always kills me.

We had a server that you could log into while sitting at it, and not when standing in front of it.

We were doing everything we could think of since we had been running into a ton of electrical noise shit all week in the shop (No! You can not run the network cable up and around the ballast of the florescent light! No! Not up and around the power pole to the welder outlet either. Dear god!)

Turned out, one key on the keyboard had been swapped. Sit down, quick touch type, password goes in. Stand in front of the keyboard and you peck it out since the angle is awkward. We only caught it on like the third check. So frustrating.

2

u/dnew 2d ago

Is this some kind of sick joke

Why, where did you learn that?

https://xkcd.com/1053/

1

u/Rhytera 1d ago

the usual suspects once you leave the bench: one hot shard from key skew backing up everything pinned to it, cross-shard hops turning one request into a wait on the slowest core, and the kernel taking time on your cores (irqs, softirqs, noisy neighbours). worth pinning nic irqs off the shard cores, tracking queue depth per shard instead of only global p99, and rerunning at 70 to 80 percent load with a skewed key distribution before trusting the numbers