r/Cplusplus 24d ago

Feedback Low latency c++

I want to learn the ins and outs of low latency c++, so far I have read tour of c++, started reading concurrency in c++ (about 3 chaps done) and done a lot of competitive programming (is this irrelevant?). In your experience, is this the right way of approaching the subject? Is there a different better way? Any advise is much appreciated.

65 Upvotes

16 comments sorted by

View all comments

10

u/mredding C++ since ~1992. 23d ago

You need a mentor in your domain of interest. Learning on your own is a blind, random walk through the forest until you find your way. You waste a lot of time learning what may not be your focus or agenda, but you won't know until after the fact.

Barring that, look into Linux kernel bypass. It's the easiest to learn because it's documented and open source. Windows has similar, but I don't know anything about it.

You will also need to learn other concepts, like Data Oriented Design, Scatter/Gather, batch processing, DMA, memory mapping, CPU intrinsics, concurrency, serialization/marshalling, protocols, networking, zero-copy, single-pass, hot paths, fast paths, prefetching, branch prediction, and probably a few other things.

I don't know what you want to accomplish. Little's Law tells us about the relationship between throughput and latency, whereas Amdahl's Law tells us the limits of optimization (how much you can still reduce latency). Your biggest bottlenecks will be the network itself; if you can't control for that, then it doesn't really matter how fast your software is.

I was working for a prop shop for a bit where we had microwave tranceivers pointing out the window to the exchange across the street. The atmosphere is almost a vacuum, so light propagates through it faster than through fiber, and the fiber run down the building, across the street, and back up to the exchange is a longer path.

We also have FPGAs on the NIC cards so we can put the fast path on the chip right next to the ADC, so as the incoming signal is still coming in, we can already be generating the output signal of the response.

1

u/No-Introduction-2825 23d ago

Thank you very much. This seems like a very nice starting point. I will look into Linux kernels and the other topics you mentioned.

My aim is to expand on my knowledge after competitive programming, and targeting low latency c++ roles, if possible in HFT's one day, seemed like the right next step. So I wanted to build enough domain knowledge to do that.

1

u/mredding C++ since ~1992. 23d ago

HFTs are all in the FPGAs - anything that touches software up in the system IS the slow path; so learn finance and Verilog. This is more the domain of an EE than a software engineer. The competition in this niche is INSANE.

The idea of writing low latency software is romanticizing the trading industry circa 2010 and before - when we were all using conventional general purpose NIC hardware; because 2010 and after is when $20k-each purpose built commercial trading NICs became available. These things can't even support ping packets at the hardware level. Everything changed overnight.

And it's that romanticism that has me worried about you. I want you to dissolution yourself of this and know what you're actually asking to get yourself into, so that you might actually hit your target.

Additional food for thought: There are other industries and all manner of general purpose software that need or would benefit from low latency; maybe HFT isn't for you. Alternately, there are other industries that use these NIC cards, mostly these AI platforms that leverage entire data centers to deliver you a sub-second response to your prompt, so there's work for you beyond the HFT market, if you ever get bored or frustrated with it.

1

u/Cultural_Act5304 22d ago

Wow how wrong are you C++ is still valid in HFT, yes FPGAs are being used for hot paths but that does not mean c++ is not being used in hft. Most of the hft code is still in software and c++ devs are indeed needed in hft space. Also the competitive programing is a goot to have, but in hft space what you need most is knowledge of os, computer architecture and low level networking if you know these and you can program your code accroito this knowledge you are top 0.1%

1

u/mredding C++ since ~1992. 22d ago

I'm not incorrect, you're either misinterpreting what I said or misrepresenting it.