First Aid Kit for C/C++ server performance

Vladislav Shpilevoy

FOSDEM'24

- Hello, my name is Vlad, I am a C and C++ developer with 10 years of experience, most of which is in the areas of low-level networking, system programming, and databases. - Throughout my career I have had to deal a lot with backend code performance measurement and improvement. - Today I want to show you a few common code performance issues that I see very often, which can cause noticeable perf degradation, and whose fixing might be a low-hanging fruit for you, to quickly regain some of the lost performance. - With benchmarks, of course. ## For readers In the speaker notes the sign (>>) means you need to press 'Space' to go to the next frame.
First Aid Kit for C/C++ server performance Vladislav Shpilevoy FOSDEM '24

FOSDEM 2024: First Aid Kit for C/C++ server performance

By Vladislav Shpilevoy

FOSDEM 2024: First Aid Kit for C/C++ server performance

I categorize the primary sources of code performance degradation into three groups: - Thread contention. For instance, too hot mutexes, overly strict order in lock-free operations, and false sharing. - Heap utilization. Loss is often caused by frequent allocation and deallocation of large objects, and by the absence of intrusive containers at hand. - Network IO. Socket reads and writes are expensive due to being system calls. Also they can block the thread for a long time, resulting in hacks like adding tens or hundreds more threads. Such measures intensify contention, as well as CPU and memory usage, while neglecting the underlying issue. I present a series of concise and straightforward low-level recipes on how to gain performance via code optimizations. While often requiring just a handful of changes, the proposals might amplify the performance N-fold. The suggestions target the mentioned bottlenecks caused by certain typical mistakes. Proposed optimizations might render architectural changes not necessary, or even allow to simplify the setup if existing servers start coping with the load effortlessly. As a side effect, the changes can make the code cleaner and reveal more bottlenecks to investigate.

  • 1,096