KVM test: A memory efficient kvm_config implementation v5
PATCH 1/1 KVM test: A memory efficient kvm_config implementation v5
This patch:
- Makes kvm_config use less memory during parsing, by storing config data compactly in arrays during parsing, and generating the final dicts only when requested.
On my machine this results in 5-10 times less memory being used (depending on the size of the final generated list). This allows the test configuration to keep expanding without having the parser run out of memory.
- Adds config.fork_and_parse(), a function that parses a config file/string in a forked process and then terminates the process. This works around Python's policy of keeping allocated memory to itself even after the objects occupying the memory have been destroyed. If the process that does the parsing is the same one that runs the tests, less memory will be available to the VMs during testing.
- Makes parsing 4-5 times faster as a result of the new internal representation.
Overall, kvm_config's memory usage should now be
negligible in most cases.
Changes from v3:
- Use the homemade 'configreader' class instead of regular files in parse() and parse_variants() (readline() and/or seek() are very slow).
- Use a regex cache dict (regex_cache).
- Use a string cache dict in addition to the list (object_cache_indices).
Changes from v2:
- Merged _get_next_line() and _get_next_line_indent().
- Made _array_get_name() faster.
Changes from v1:
- Added config.get_generator() which is similar to get_list() but returns a dict generator instead of a list. This should save some more memory and will make tests start sooner.
- Use get_generator() in control.
- Call waitpid() at the end of fork_and_parse().
--- client/tests/kvm/control | 33 +- client/tests/kvm/control.parallel | 21 +- client/tests/kvm/kvm_config.py | 837 ++++++++++++++++++++++--------------- 3 files changed, 541 insertions(+), 350 deletions(-)
client/tests/kvm/control +20 -13
@@ -30,34 +30,41 @@ import kvm_utils, kvm_config # set English environment (command output might be localized, need to be safe) os.environ['LANG'] = 'en_US.UTF-8' -build_cfg_path = os.path.join(kvm_test_dir, "build.cfg") -build_cfg = kvm_config.config(build_cfg_path) -# Make any desired changes to the build configuration here. For example: -#build_cfg.parse_string(""" +str = """ +# This string will be parsed after build.cfg. Make any desired changes to the +# build configuration here. For example: #release_tag = 84 -#""") -if not kvm_utils.run_tests(build_cfg.get_list(), job): +""" +build_cfg = kvm_config.config() +# As the base test config is quite large, in order to save memory, we use the +# fork_and_parse() method, that creates another parser process and destroys it +# at the end of the parsing, so the memory spent can be given back to the OS. +build_cfg_path = os.path.join(kvm_test_dir, "build.cfg") +build_cfg.fork_and_parse(build_cfg_path, str) +if not kvm_utils.run_tests(build_cfg.get_generator(), job): logging.error("KVM build step failed, exiting.") sys.exit(1) -tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg") -tests_cfg = kvm_config.config(tests_cfg_path) -# Make any desired changes to the test configuration here. For example: -#tests_cfg.parse_string(""" +str = """ +# This string will be parsed after tests.cfg. Make any desired changes to the +# test configuration here. For example: #display = sdl #install|setup: timeout_multiplier = 3 -#""") +""" +tests_cfg = kvm_config.config() +tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg") +tests_cfg.fork_and_parse(tests_cfg_path, str) pools_cfg_path = os.path.join(kvm_test_dir, "address_pools.cfg") tests_cfg.parse_file(pools_cfg_path) hostname = os.uname()[1].split(".")[0] -if tests_cfg.filter("^" + hostname): +if tests_cfg.count("^" + hostname): tests_cfg.parse_string("only ^%s" % hostname) else: tests_cfg.parse_string("only ^default_host") # Run the tests -kvm_utils.run_tests(tests_cfg.get_list(), job) +kvm_utils.run_tests(tests_cfg.get_generator(), job) # Generate a nice HTML report inside the job's results dir kvm_utils.create_report(kvm_test_dir, job.resultdir)
client/tests/kvm/control.parallel +12 -9
@@ -160,19 +160,22 @@ if not params.get("mode") == "noinstall": # ---------------------------------------------------------- import kvm_config -filename = os.path.join(pwd, "kvm_tests.cfg") -cfg = kvm_config.config(filename) - -# If desirable, make changes to the test configuration here. For example: -# cfg.parse_string("install|setup: timeout_multiplier = 2") -# cfg.parse_string("only fc8_quick") -# cfg.parse_string("display = sdl") +str = """ +# This string will be parsed after tests.cfg. Make any desired changes to the +# test configuration here. For example: +#install|setup: timeout_multiplier = 3 +#only fc8_quick +#display = sdl +""" +cfg = kvm_config.config() +filename = os.path.join(pwd, "tests.cfg") +cfg.fork_and_parse(filename, str) -filename = os.path.join(pwd, "kvm_address_pools.cfg") +filename = os.path.join(pwd, "address_pools.cfg") if os.path.exists(filename): cfg.parse_file(filename) hostname = os.uname()[1].split(".")[0] - if cfg.filter("^" + hostname): + if cfg.count("^" + hostname): cfg.parse_string("only ^%s" % hostname) else: cfg.parse_string("only ^default_host")
client/tests/kvm/kvm_config.py +509 -328
1,019 lines not on this page · raw message
Signature · 1 line
1.6.6.1