diff --git a/README.md b/README.md index c29afb8..2ec9bbb 100644 --- a/README.md +++ b/README.md @@ -775,7 +775,26 @@ The book [Designing Data-Intensive Applications](https://www.oreilly.com/library --- ### Performance Engineering -⚠️WIP⚠️ +Performance isn't always key to the code we'll be writing. However, it's good to be aware of the tools we have to measure performance for the situations where we do need them. Sometimes some applications will have dedicated benchmarks which facilitate measuring any performance improvements or downgrades, and in such cases those are likely the most reliable tool. However, this is not a given nor necessarily often the case. While what's needed to improve the performance of an application can vary a lot in practice and a good eye for it is often acquired with experience, having some baseline knowledge can be very helpful. For Rust, the [Rust Performance Book](https://nnethercote.github.io/perf-book/) is a very useful resource to get started. For a more in depth read on system performance, [Brendan Gregg's book on it](https://www.amazon.com/Systems-Performance-Enterprise-Brendan-Gregg/dp/0133390098) is a very good resource. + +#### Logging and tracing + +Often logs, combined with measuring time with the built-in standard library methods, will be a powerful and reliable tool to measure the performance of certain parts of your applciation code. In Elixir, you can more easily output logs for said purposes with the [Logger](https://hexdocs.pm/logger/Logger.html) library. In Rust, the [Tokio tracing](https://docs.rs/tracing/latest/tracing/) crate has [various](https://docs.rs/tracing/latest/tracing/macro.info.html) [macros](https://docs.rs/tracing/latest/tracing/macro.debug.html) that let you more easily print out logs at various levels. + +The Tokio tracing crate also includes a variety of tracing tools that can easily instrument parts of the code for better analysis, like the [instrument](https://docs.rs/tracing/latest/tracing/attr.instrument.html) macro for entire functions and [spans](https://docs.rs/tracing/latest/tracing/macro.span.html) for specific code segments. Elixir can similarly do tracing with the [OpenTelemetry](https://hexdocs.pm/opentelemetry_api/readme.html) library, which also allows for the creation of spans. + +#### Flamegraphs + +In some cases however, logging and tracing tools like such might not be enough on their own; for example, if you want to diagnose which part of an application might be causing a performance issue and you don't know a priori what it might be. For those situations, [flamegraphs](https://www.brendangregg.com/flamegraphs.html) can be a really valuable tool; as they allow you to see which functions took up the most time during your run, and which function calls within those were responsible, in a very intuitive manner. + +In Rust, you can easily profile your application with a flamegraph by adding the framegraph crate on a system that has [`perf`](https://perfwiki.github.io/main/) installed and then using the command ```cargo flamegraph``` (like you'd use ```cargo run```) to start your application. Bear in mind to profile your software in a release build, as Rust does extra optimizations when compiling for such. + +For a more detailed profile of your application, you can use [Samply](https://github.com/mstange/samply). Samply similarly generates a flamegraph of your application run, but also allows allows for other visualizations which can provide other useful information. + +#### Monitoring system performance + +In some situations monitoring system performance to measure the load of your application on the system you're testing, or visualize which threads are the busiest, can also be very helpful. [Htop](https://htop.dev/) is very useful for monitoring processes and system resources live, while [sar](https://linux.die.net/man/1/sar) and [atop](https://linux.die.net/man/1/atop) can be very useful to log global system resource usage and the resource usage of individual processes or threads, respectively. + #### Algorithmics - [Big O notation](https://www.youtube.com/watch?v=gCzOhZ_LUps)