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
This commit is contained in:
Tobias Henkel 2021-01-22 11:46:17 +01:00
parent bd6dea8f97
commit 61963917a0
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
2 changed files with 11 additions and 1 deletions

View File

@ -9,6 +9,10 @@ libffi6 [platform:dpkg]
libffi [platform:apk] libffi [platform:apk]
libressl-dev [compile test platform:apk] libressl-dev [compile test platform:apk]
libssl-dev [compile test platform:dpkg] 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] linux-headers [compile test platform:apk]
make [compile test platform:apk platform:dpkg] make [compile test platform:apk platform:dpkg]
musl-dev [compile test platform:apk] musl-dev [compile test platform:apk]

View File

@ -24,6 +24,11 @@ from nodepool import zk
from nodepool.driver import ConfigValue from nodepool.driver import ConfigValue
from nodepool.driver import Drivers from nodepool.driver import Drivers
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
class Config(ConfigValue): class Config(ConfigValue):
''' '''
@ -314,7 +319,8 @@ def openConfig(path, env):
while True: while True:
try: try:
with open(path) as f: 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: except IOError as e:
if e.errno == 2: if e.errno == 2:
retry = retry - 1 retry = retry - 1