Skip to content

Commit

Permalink
Fix performance glitch while sorting image locations
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
konan-abhi authored and bbezak committed Feb 6, 2025
1 parent d0be1be commit 78f1f81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions glance/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,12 @@ def get_store_weight(location):
if not store_id:
return 0
try:
store = glance_store.get_store_from_store_identifier(store_id)
return glance_store.get_store_weight(store_id)
except glance_store.exceptions.UnknownScheme:
msg = (_LW("Unable to find store '%s', returning "
"default weight '0'") % store_id)
LOG.warning(msg)
return 0
return store.weight if store is not None else 0

sorted_locations = sorted(locations, key=get_store_weight, reverse=True)
LOG.debug(('Sorted locations: %s'), sorted_locations)
Expand Down
16 changes: 7 additions & 9 deletions glance/tests/unit/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_sort_image_locations_multistore_disabled(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {'store': 'rbd3'}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
utils.sort_image_locations(locations)

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

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

Expand All @@ -270,10 +269,9 @@ def test_sort_image_locations_with_partial_metadata(self):
'url': 'rbd://cccccccc/images/id',
'metadata': {}
}]
mp = "glance.common.utils.glance_store.get_store_from_store_identifier"
mp = "glance.common.utils.glance_store.get_store_weight"
with mock.patch(mp) as mock_get_store:
mock_store = mock_get_store.return_value
mock_store.weight = 100
mock_get_store.return_value = 100
utils.sort_image_locations(locations)

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

0 comments on commit 78f1f81

Please sign in to comment.