Description
Performance Analysis
Testing the performance of an HTTP server involves measuring its handling of various loads.
CPU Usage Profiling
We can use perf
to collect statistics about the CPU usage of our server with the stat
command.
$ sudo perf stat -p <pid_of_server>
perf stat
will then start monitoring our server. We can let it run while sending requests to our server. Once we've collected enough data, we can stop perf stat
which will print a summary of the performance statistics.
These are the statistics for CPU usage obtained after running our server under a load of 100 requests with a concurrency level of 10 using ApacheBench tool :
Hotspot Analysis
perf record
and perf report
can be used together to identify the functions in our code that consume the most CPU time.
$ sudo perf record -g -p <pid_of_server> -o perf.data
After running our server under load (For example, using ApacheBench tool), we can stop the recording and analyze the data using:
sudo perf report -i perf.data
After generating a file named perf.data
which contains the profiling data, we can visualize it using FlameGraph
tool. It's particularly useful for identifying the most expensive code-paths and inspect where our application is spending the most time.
To do this, we need to convert the perf.data
to a format that FlameGraph can understand:
sudo perf script | ~/FlameGraph/stackcollapse-perf.pl > out.perf-folded
And, then, generate the Flame Graph:
~/FlameGraph/flamegraph.pl out.perf-folded > flamegraph.svg
We can view flamegraph.svg using a web browser.
We are continuously working to enhance the design and performance of our server. One of the major modifications involves making our server more asynchronous, which is expected to save significant resources.
We will analyze the impact of this improvement by comparing CPU profiling data that we generated using perf, and we will visualize it using a Flame Graph.