Skip to content

Commit ae6eb97

Browse files
committed
Do not lazy-load the extra specs for each flavor
When we access the extra specs for a flavor with the .get_keys() method the attributes are lazy-loaded each time, meaning that if we have a large number of servers we are hitting the API for each of those servers. Since the client does not allow to load the extra specs, we do it manually, thus hitting the API only when the flavors are loaded for the first time. By doing so we have passed from 50s to 20s (extracting 700 records).
1 parent 08e1471 commit ae6eb97

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

caso/extract/nova.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def build_record(self, server, vo, images, flavors, users):
6060

6161
flavor = flavors.get(server.flavor["id"])
6262
if flavor:
63-
bench_name = flavor.get_keys().get(CONF.benchmark_name_key)
64-
bench_value = flavor.get_keys().get(CONF.benchmark_value_key)
63+
bench_name = flavor["extra"].get(CONF.benchmark_name_key)
64+
bench_value = flavor["extra"].get(CONF.benchmark_value_key)
6565
else:
6666
bench_name = bench_value = None
6767

@@ -114,7 +114,10 @@ def extract_for_project(self, project, extract_from, extract_to):
114114
users = self._get_keystone_users(ks_client)
115115
project_id = nova.client.session.get_project_id()
116116

117-
flavors = {flavor.id: flavor for flavor in nova.flavors.list()}
117+
flavors = {}
118+
for flavor in nova.flavors.list():
119+
flavors[flavor.id] = flavor.to_dict()
120+
flavors[flavor.id]["extra"] = flavor.get_keys()
118121

119122
servers = []
120123
limit = 200

0 commit comments

Comments
 (0)