Skip to content

Commit 78f1f81

Browse files
konan-abhibbezak
authored andcommitted
Fix performance glitch while sorting image locations
Some of the available glance stores like file, cinder etc has capability to reuse already initiated driver (DRIVER_REUSABLE = 0b01000000). In Caracal we have added a feature to sort image locations based on store weight. As RBD driver of glance does not have this reuse capability, during image list API call it initializes the RBD driver for each of the available image which is causing noticable delay in list call. To avoid this, using new interface added in glance_store which will directly get the weight of the store from memory and return it back to user. Depends-On: https://review.opendev.org/c/openstack/glance_store/+/940531 Closes-Bug: #2086675 Change-Id: I662ba19697e03917ca999920ea7be93a0b2a8296 (cherry picked from commit ce537e073b2e7efb332d719bb45bf20c403c140a)
1 parent d0be1be commit 78f1f81

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

glance/common/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,12 @@ def get_store_weight(location):
724724
if not store_id:
725725
return 0
726726
try:
727-
store = glance_store.get_store_from_store_identifier(store_id)
727+
return glance_store.get_store_weight(store_id)
728728
except glance_store.exceptions.UnknownScheme:
729729
msg = (_LW("Unable to find store '%s', returning "
730730
"default weight '0'") % store_id)
731731
LOG.warning(msg)
732732
return 0
733-
return store.weight if store is not None else 0
734733

735734
sorted_locations = sorted(locations, key=get_store_weight, reverse=True)
736735
LOG.debug(('Sorted locations: %s'), sorted_locations)

glance/tests/unit/common/test_utils.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_sort_image_locations_multistore_disabled(self):
189189
'url': 'rbd://cccccccc/images/id',
190190
'metadata': {'store': 'rbd3'}
191191
}]
192-
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
192+
mp = "glance.common.utils.glance_store.get_store_weight"
193193
with mock.patch(mp) as mock_get_store:
194194
utils.sort_image_locations(locations)
195195

@@ -215,10 +215,9 @@ def test_sort_image_locations(self):
215215
'url': 'rbd://cccccccc/images/id',
216216
'metadata': {'store': 'rbd3'}
217217
}]
218-
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
218+
mp = "glance.common.utils.glance_store.get_store_weight"
219219
with mock.patch(mp) as mock_get_store:
220-
mock_store = mock_get_store.return_value
221-
mock_store.weight = 100
220+
mock_get_store.return_value = 100
222221
utils.sort_image_locations(locations)
223222

224223
# Since 3 stores are configured, internal method will be called 3 times
@@ -243,7 +242,7 @@ def test_sort_image_locations_without_metadata(self):
243242
'url': 'rbd://cccccccc/images/id',
244243
'metadata': {}
245244
}]
246-
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
245+
mp = "glance.common.utils.glance_store.get_store_weight"
247246
with mock.patch(mp) as mock_get_store:
248247
utils.sort_image_locations(locations)
249248

@@ -270,10 +269,9 @@ def test_sort_image_locations_with_partial_metadata(self):
270269
'url': 'rbd://cccccccc/images/id',
271270
'metadata': {}
272271
}]
273-
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
272+
mp = "glance.common.utils.glance_store.get_store_weight"
274273
with mock.patch(mp) as mock_get_store:
275-
mock_store = mock_get_store.return_value
276-
mock_store.weight = 100
274+
mock_get_store.return_value = 100
277275
utils.sort_image_locations(locations)
278276

279277
# Since 3 stores are configured, but only one location has
@@ -300,7 +298,7 @@ def test_sort_image_locations_unknownscheme(self):
300298
'url': 'rbd://cccccccc/images/id',
301299
'metadata': {'store': 'rbd3'}
302300
}]
303-
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
301+
mp = "glance.common.utils.glance_store.get_store_weight"
304302
with mock.patch(mp) as mock_get_store:
305303
mock_get_store.side_effect = store.UnknownScheme()
306304
sorted_locations = utils.sort_image_locations(locations)

0 commit comments

Comments
 (0)