HomePhorge

(PUP-3389) Do not list all directories when getting an environment
c19ec229bc73Unpublished

Unpublished Commit · Learn More

Repository Importing: This repository is still importing.

Description

(PUP-3389) Do not list all directories when getting an environment

The Puppet::Environment::Directories loader had a stable but naive
implementation for obtaining a valid directory env. It relied on its
list function to provide the set of all valid directory environments in
its root directory, and then returned the one that matched. This worked
fine for small numbers of directory environments, but became costly for
hundred or thousands of environments. The impact was exacerbated by the
need to lookup the environment.conf for each directory environment, in
the context of a Puppet::Settings values object that could interpolate
the settings in the environment.conf. Each such lookup relied on yet
another pass through the list of all directory environments, causing
num_of_direnvs^2 calls for each initial lookup of a new environment.

This commit fixes that, separating validation of a directory environment
entry and creation of a new environment from the act of listing all
valid directory environments.

A benchmark is added as well, testing the time it takes to look up one
environment out of a thousand available environments after base settings
initialization.

Prior to this patch, 10 passes of the benchmark test took ~100s on a
4 core Intel 2.9Ghz machine with 8GB. After the patch, it's down to
about 0.01s, so about a 10^4 boost...which is probably the best
performance boost I've ever managed out of fairly minor patch :)

Details

Event Timeline

Josh Partlow <joshua.partlow@puppetlabs.com> committed rPUc19ec229bc73: (PUP-3389) Do not list all directories when getting an environment (authored by Josh Partlow <joshua.partlow@puppetlabs.com>).Dec 5 2014, 5:53 AM