Skip to contentSkip to conversation

KVM test: A memory efficient kvm_config implementation

RFC PATCH Superseded Michael Goldish 1 participant 1 message Feb 25, 2010 KVM

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 KVM test: A memory efficient kvm_config implementation

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.

This patch has only been tested outside autotest so it may contain bugs.

---
 client/tests/kvm/control          |   16 +-
 client/tests/kvm/control.parallel |    2 +-
 client/tests/kvm/kvm_config.py    |  652 ++++++++++++++++++++++---------------
 3 files changed, 407 insertions(+), 263 deletions(-)
client/tests/kvm/control +9 -7
index 163286e..bb4b258 100644
@@ -32,7 +32,7 @@ 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:
+# Make any desired changes to the build configuration here.  For example:
 #build_cfg.parse_string("""
 #release_tag = 84
 #""")
@@ -40,18 +40,20 @@ if not kvm_utils.run_tests(build_cfg.get_list(), 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 configuration changes
+# you want here.  For example:
 #display = sdl
 #install|setup: timeout_multiplier = 3
-#""")
+"""
+tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg")
+tests_cfg = kvm_config.config()
+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")
client/tests/kvm/control.parallel +1 -1
index 343f694..2fe91e0 100644
@@ -172,7 +172,7 @@ filename = os.path.join(pwd, "kvm_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 +397 -255

859 lines not on this page · raw message

Signature · 1 line
1.5.4.1