標簽: cinder openstack 翻譯
Openstack塊存儲有一個可選的功能,鏡像緩存,可以提升從鏡像創(chuàng)建卷的性能。這個改進依賴很多因素,主要看存儲的后端克隆卷的速度有多快。
當一個卷第一次從鏡像創(chuàng)建的時候,塊存儲的內(nèi)部租戶也會創(chuàng)建一個image-volume緩存。之后如果再請求從這個image創(chuàng)建volume的話就直接clone這個緩存,不需要再下載鏡像的內(nèi)容然后復(fù)制數(shù)據(jù)到卷里了。
每個后端可以配置自己的緩存,可以包含大部分常用的鏡像。
設(shè)置內(nèi)部租戶
image-volume緩存需要配置塊存儲的內(nèi)部租戶。這個租戶擁有這些緩存并且可以進行管理。這可以保護用戶不必看到這些緩存,但是也沒有全局隱藏。
使塊存儲服務(wù)能進入內(nèi)部租戶,需要在conder.conf配置:
cinder_internal_tenant_project_id = PROJECT_ID
cinder_internal_tenant_user_id = USER_ID
為內(nèi)部租戶配置的用戶和項目不需要特殊的額權(quán)限。可以使塊存儲服務(wù)的租戶或者是其他任何的項目和用戶。
配置image-volume cache
在cinder.conf中配置如下:
image_volume_cache_enabled = True
每個后端可以獨立定義或者在默認項里定義。
緩存的大小和數(shù)量限制也可以在每個后端獨立定義,或者在默認項里定義。
image_volume_cache_max_size_gb = SIZE_GB
image_volume_cache_max_count = MAX_COUNT
默認被設(shè)置為0,表示不限制。
通知
緩存操作會觸發(fā)Telemetry消息。這幾種會被發(fā)送:
- image_volume_cache.miss - 創(chuàng)建卷時,沒有從緩存中找到相應(yīng)的鏡像。這意味著一個新的緩存會被創(chuàng)建
- image_volume_cache.hit - 從鏡像創(chuàng)建卷時,在緩存中找到了相應(yīng)的鏡像并將被使用。
- image_volume_cache.evict - 一個鏡像的緩存被刪除。
管理image-volume緩存
通常來說,緩存都是自動管理的,不需要手動干預(yù)。
如果需要,可以手動刪除緩存。通過標準的卷刪除API,塊存儲服務(wù)會執(zhí)行清理。
注意:
代碼可以看出,如果直接clone的話,就不會創(chuàng)建cache了
# vim cinder/volume/flows/manager/create_volume.py
...
def _create_from_image(self, context, volume_ref,
image_location, image_id, image_meta,
image_service, **kwargs):
LOG.debug("Cloning %(volume_id)s from image %(image_id)s "
" at location %(image_location)s.",
{'volume_id': volume_ref['id'],
'image_location': image_location, 'image_id': image_id})
# Create the volume from an image.
#
# First see if the driver can clone the image directly.
#
# NOTE (singn): two params need to be returned
# dict containing provider_location for cloned volume
# and clone status.
model_update, cloned = self.driver.clone_image(context,
volume_ref,
image_location,
image_meta,
image_service)
# Try and clone the image if we have it set as a glance location.
if not cloned and 'cinder' in CONF.allowed_direct_url_schemes:
model_update, cloned = self._clone_image_volume(context,
volume_ref,
image_location,
image_meta)
# Try and use the image cache.
should_create_cache_entry = False
internal_context = cinder_context.get_internal_tenant_context()
if not internal_context:
LOG.warning(_LW('Unable to get Cinder internal context, will '
'not use image-volume cache.'))
----------
if not cloned and internal_context and self.image_volume_cache:
model_update, cloned = self._create_from_image_cache(
context,
internal_context,
volume_ref,
image_id,
image_meta
)
if not cloned:
should_create_cache_entry = True
----------
...