Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find performance bottlenecks in C++ code

I have a server application written in C++ and deployed in Cent OS. I haven't wrote any part of its code but i need to optimize its performance. Its current performance is acceptable for few amount of users but when the number of users increase the server's performance decrease dramatically.

Are there any tools, techniques or best practices to find out the bottlenecks?

like image 327
red.clover Avatar asked Oct 04 '09 05:10

red.clover


People also ask

How do you identify performance bottlenecks?

Identifying Performance Bottlenecks lists hardware classes according to relative access speed, implying that slow access points, such as disks, are more likely to be the source of bottlenecks. However, processors that are underpowered to handle large loads are also likely sources of bottlenecks.

How do I find software bottlenecks?

Quite simply, run the application you want, then check your component usage. If you have a single CPU core that is hitting 100% constantly whilst everything else has headroom, your CPU is your bottleneck in that particular application.

Which tool enables you to identify bottlenecks that exist in code?

A value stream map is a tool for evaluating processes to identify bottlenecks, waste, and improvement opportunities.

What is used to investigate and find the performance bottleneck in your game?

The Profiler window is a powerful profiling tool that is built into Unity. This tutorial describes what the Profiler window is used for and how to use it to diagnose performance problems in a game or other application.


2 Answers

People typically use profilers to determine performance bottlenecks. Earlier SO questions asking for C++ profilers are here and here (depending on the operating system and compiler you use). For Linux, people typically use gprof, just because it comes with the system.

like image 96
Martin v. Löwis Avatar answered Oct 04 '22 16:10

Martin v. Löwis


You'll start by building a performance test environment if you don't have one

  • Production-grade hardware. If you do not have the budget for this, you may as well give up.
  • Driver program(s) or hardware devices which throw production-like traffic at it at a high rate - as fast or faster than production. Depending on your protocol and use-case this may be easy or difficult. One technique is to sample some requests from production and replay them - but this may be give unrealistic results as it will give higher cache hit rates.
  • Surrounding infrastructure as similar to production as you can reasonably get

Then reproduce the problem, as it exists in production. Once you've done that, then use a profiler etc, as others have suggested.

like image 26
MarkR Avatar answered Oct 04 '22 14:10

MarkR