Show notes: The agent is in - Episode 30 - Profiling CFEngine policy

Posted by Nick Anderson
October 19, 2023

Imagine having the power to identify the exact lines of your CFEngine policy that are slowing down your executions. In this episode, we’ll guide you through the art of profiling CFEngine policy for improved performance.

In Episode 30 of “The agent is in,” Nick and team dives into the topic of profiling CFEngine policy. We explore tools and techniques to identify performance bottlenecks and optimize CFEngine deployments. The episode covers the following main points:

  1. Introduction to cf-profile: A useful tool for identifying long-running bundles in CFEngine policy. cf-profile analyzes the verbose log messages and provides a summary of the most time-consuming bundles.

  2. Using cf-profile: Demonstration of how to install and use cf-profile interactively with cf-agent. By running cf-profile with the execution tree and summary options, users can get a high-level overview of bundle execution time and identify areas that require further investigation.

  3. Fine-Grained Analysis: To dig deeper into individual promises within a bundle using the timestamp option of cf-agent. This allows users to track the execution time of each promise and pinpoint any performance issues.

  4. Profiling in CFEngine Enterprise: For CFEngine Enterprise users, the benchmarks table, provides execution time and standard deviation metrics. Nick explains how to access this table through the Mission portal and highlight the usefulness of attaching an action body with the measurement_class to measure specific promises.

  5. Demonstrating Custom Measurement: Nick shows an example of attaching an action body using the measurement_class attribute on a command’s promise and demonstrates how the measurement appears in the benchmarks table.

The episode caters to both new and experienced CFEngine users, providing tips and tools for analyzing and optimizing CFEngine policies.

Video

The video recording is available on YouTube:

Notes

cf-profile

Provides high level summary of execution time in policy surfacing the bundles in which the most time was spent. Find it in contrib/cf-profile of the core repository.

curl -s https://raw.githubusercontent.com/cfengine/core/master/contrib/cf-profile/cf-profile.pl --output /var/cfengine/bin/cf-profile
chmod 755 /var/cfengine/bin/cf-profile
cf-agent -Kv | /var/cfengine/bin/cf-profile -t -s

Note: The script requires perl, and the POSIX, Time::HiRes, Data::Dumper, and Getopt::Std modules.

--timestamp options adds a timestamp to CFEngine logs

Useful for digging down into the execution time of individual promises.

cf-agent -Kv --timestamp

Note: it does not prefix lines emitted by reports promises with a timestamp.

CFEngine Enterprise benchmarks table

Provides last, average, and standard deviation for execution times of various things, including the Agent execution time per policy entry as well as the promise execution time for any promise using an action body with the measurement_class attribute defined.

body action measure_promise_time(identifier)
# @brief Performance will be measured and recorded under identifier
#
# @param identifier Measurement name.
{
      measurement_class => "$(identifier)";
}
commands:
    "sleep $(i)"
      inform => "false",
      contain => in_shell,
      handle => "bundle_agent_two_sleep",
      action => measure_promise_time("measure_my_command_that_is_slow");

Post show discussion

At the end of every webinar, we stop the recording for a nice and relaxed, off-the-record chat with attendees. Join the next webinar to not miss this discussion.

Config Management Camp CFP is open

Where is the CFEngine Merch Shop?

Need some CFEngine swag? Contact us.

History of CFEngine & differences in level of publicity with other tools

We discussed the history of CFEngine, covering the software, the company (now Northern.tech), user personalities (both individual and organization), as well as differences in company strategy in comparison to other products.