From 61963917a02def51202cdf30c3818b09403d93bc Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Fri, 22 Jan 2021 11:46:17 +0100 Subject: [PATCH] Use libyaml parsing when available Nodepool periodically reloads its config. On systems with large configs this can cause a substantial amount of cpu usage. Our profiling of an idle provider revealed that the yaml parsing accounted for ~15% cpu load while the provider was idle. This could be improved by utilizing the native libyaml bindings when available. Change-Id: Icbed393c5aa00abd52d1e13ccbbad8546ec6cf97 --- bindep.txt | 4 ++++ nodepool/config.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bindep.txt b/bindep.txt index f6c019371..058217061 100644 --- a/bindep.txt +++ b/bindep.txt @@ -9,6 +9,10 @@ libffi6 [platform:dpkg] libffi [platform:apk] libressl-dev [compile test platform:apk] libssl-dev [compile test platform:dpkg] +libyaml-0-2 [platform:dpkg platform:suse] +libyaml [platform:redhat] +libyaml-dev [platform:dpkg compile test] +libyaml-devel [platform:rpm compile test] linux-headers [compile test platform:apk] make [compile test platform:apk platform:dpkg] musl-dev [compile test platform:apk] diff --git a/nodepool/config.py b/nodepool/config.py index 119e8f1ba..0dfb66ea0 100644 --- a/nodepool/config.py +++ b/nodepool/config.py @@ -24,6 +24,11 @@ from nodepool import zk from nodepool.driver import ConfigValue from nodepool.driver import Drivers +try: + from yaml import CSafeLoader as SafeLoader +except ImportError: + from yaml import SafeLoader + class Config(ConfigValue): ''' @@ -314,7 +319,8 @@ def openConfig(path, env): while True: try: with open(path) as f: - return yaml.safe_load(substitute_env_vars(f.read(), env)) + return yaml.load( + substitute_env_vars(f.read(), env), SafeLoader) except IOError as e: if e.errno == 2: retry = retry - 1