获取云硬盘列表bug
有段时间没写博客了,主要还是刚进新公司,多少有点不适应(真会给自己找理由,明明是手里没技术,肚子里没货,能写啥!)。前面几个星期都在修一修horizon的bug,这个没啥很大难度,就是用了一个django的框架,然后再嵌套一些js框架,简明易懂。不扯远了,来点干货。。


浏览器抓包可以看到,这样一个请求耗时2.4秒,再把日志打到horizon代码中,看下结果如何:
class GetVolumes(APIMeta):
def handle(self):
status = self.request.POST.get('status', '')
tenant_id = self.request.POST.get('tenant_id', '')
data = []
instances_info = {}
LOG.error("step1:%s" % time.time())
# import pdb
# pdb.set_trace()
volumes_obj = api.cinder.volume_list(self.request,
{'all_tenants': 1})
LOG.error("step2:%s" % time.time())
volumes = filters.add_tenant_info(self.request,
volumes_obj,
"os-vol-tenant-attr:tenant_id")
LOG.error("step3:%s" % time.time())
instances = api.nova.server_list(self.request, all_tenants=True)
LOG.error("step4:%s" % time.time())
for ins in instances[0]:
instances_info[ins.id] = ins.name
if status:
volumes = filter(lambda x: status in x.status, volumes)
if tenant_id:
volumes = filter(lambda x: \
getattr(x, 'os-vol-tenant-attr:tenant_id') == tenant_id,
volumes)
LOG.error("step5:%s" % time.time())
for volume in volumes:
if volume.attachments:
instance_id = volume.attachments[0]['server_id']
instance_name = instances_info.get(instance_id,
instance_id)
else:
instance_name = ''
tenant = getattr(volume, 'tenant', '')
data.append({'volume_id': volume.id,
'display_name': volume.display_name,
'display_description': volume.display_description,
'bootable': volume.bootable,
'size': volume.size,
'status': volume.status,
'volume_type': volume.volume_type,
'host': getattr(volume,
"os-vol-host-attr:host", None),
'tenant_name': getattr(tenant, "name", None),
'tenant_id': getattr(tenant, "id", None),
'instance_name': instance_name,
})
LOG.error("step6:%s" % time.time())
return sorted(data, key = lambda x: x['display_name'], reverse = False)
测试结果如下:
-- ::, openstack_dashboard.dashboards.admin.volumes.json_views[line:] ERROR step1:1430963063.15
-- ::, openstack_dashboard.dashboards.admin.volumes.json_views[line:] ERROR step2:1430963064.71
-- ::, openstack_dashboard.dashboards.admin.volumes.json_views[line:] ERROR step3:1430963064.8
-- ::, openstack_dashboard.dashboards.admin.volumes.json_views[line:] ERROR step4:1430963066.29
-- ::, openstack_dashboard.dashboards.admin.volumes.json_views[line:] ERROR step5:1430963066.29
-- ::, openstack_dashboard.dashboards.admin.volumes.json_views[line:] ERROR step6:1430963066.29
可以看到,主要的耗时在step1-step2 step3-step4时间,定位到相应代码段:
# step1与step2之间耗时:
volumes_obj = api.cinder.volume_list(self.request,{'all_tenants': 1})
# step3与step4之间耗时:
instances = api.nova.server_list(self.request, all_tenants=True)
再在cinderclient做时间戳:
def volume_list(request, search_opts=None):
"""
To see all volumes in the cloud as an admin you can pass in a special
search option: {'all_tenants': 1}
"""
c_client = cinderclient(request)
if c_client is None:
return []
import time
LOG.error("horizon_start time: %s " % time.time())
result = c_client.volumes.list(search_opts=search_opts)
LOG.error("horizon_end time: %s " % time.time())
return result
# return c_client.volumes.list(search_opts=search_opts)
结果如下:
-- ::, openstack_dashboard.api.cinder[line:] ERROR horizon_start time: 1431069736.4
-- ::, openstack_dashboard.api.cinder[line:] ERROR horizon_end time: 1431069739.85
再在cinder服务端设置时间戳:/cinder/api/v1/volumes.py
def _items(self, req, entity_maker):
# import pdb
# pdb.set_trace()
"""Returns a list of volumes, transformed through entity_maker.""" #pop out limit and offset , they are not search_opts
LOG.debug(_("time1------------------------%s" % time.time()))
search_opts = req.GET.copy()
search_opts.pop('limit', None)
search_opts.pop('offset', None) if 'metadata' in search_opts:
search_opts['metadata'] = ast.literal_eval(search_opts['metadata']) context = req.environ['cinder.context']
remove_invalid_options(context,
search_opts, self._get_volume_search_options()) volumes = self.volume_api.get_all(context, marker=None, limit=None,
sort_key='created_at',
sort_dir='desc', filters=search_opts) volumes = [dict(vol.iteritems()) for vol in volumes]
LOG.debug(_("time2------------------------%s" % time.time())) for volume in volumes:
self._add_visible_admin_metadata(context, volume) limited_list = common.limited(volumes, req)
LOG.debug(_("time3------------------------%s" % time.time()))
req.cache_resource(limited_list)
res = [entity_maker(context, vol) for vol in limited_list]
LOG.debug(_("time4------------------------%s" % time.time()))
return {'volumes': res}
结果如下:
time1------------------------1431069737.57
time2------------------------1431069738.02
time3------------------------1431069738.02
time4------------------------1431069738.05
显而易见,时间都消耗在cinder服务端向cinder客户端返回数据上面了,下面分析一下返回的数据:
{'migration_status': None,
'availability_zone': u'nova',
'terminated_at': None,
'updated_at': datetime.datetime(, , , , , ),
'provider_geometry': None,
'snapshot_id': None,
'ec2_id': None,
'mountpoint': None,
'deleted_at': None,
'id': u'69400200-6dea-41ec-ab7f-e3719fc9b18f',
'size': 3L,
'user_id': u'33d5edff940f4812b5368e54499991e4',
'attach_time': None,
'attached_host': None,
'display_description': u'',
'encryption_key_id': None,
'project_id': u'01f2a2e8594342d78865376cd81e2c67',
'launched_at': datetime.datetime(, , , , , ),
'scheduled_at': datetime.datetime(, , , , , ),
'status': u'available',
'volume_type_id': u'3a255382-1da3-4449-ad5b-5f37a4cf3d2c',
'deleted': False,
'provider_location': None,
'host': u'test1',
'source_volid': None,
'provider_auth': None,
'display_name': u'disk-102',
'instance_uuid': None,
'bootable': False,
'created_at': datetime.datetime(, , , , , ),
'attach_status': u'detached',
'volume_type': <cinder.db.sqlalchemy.models.VolumeTypes object at 0x44277d0>,
'_name_id': None, 'volume_metadata': []},
上面字段基本都会用到,看来解决方案不能在精简数据上面了,或者可以在cinder客户端做一个缓存,未完待续。。
获取云硬盘列表bug的更多相关文章
- 复盘价值1000万的腾讯云硬盘固件"BUG"
摘要: 除了吃瓜,还是得吸取教训啊同学们! 这次,我从纯技术角度分析腾讯云与前沿数控的磁盘数据丢失事件,不站队. 硬盘门 这里说的硬盘门不是10年前陈老师的那一次,而聊的是最近"腾讯云&qu ...
- 阿里云使用js 实现OSS图片上传、获取OSS图片列表、获取图片外网访问地址(读写权限私有、读写权限公共);
详情请参考:https://help.aliyun.com/document_detail/32069.html?spm=a2c4g.11186623.6.763.ZgC59a 或者https://h ...
- [转] Android SDK manager 无法获取更新版本列表
打开这个网址(LINK)就可以看到adt的详细信息. 或者直接在你的eclipse的Help > Install New Software里面add,地址直接输入 https://dl-ss ...
- android SDK manager 无法获取更新版本列表【转载】
http://mirrors.neusoft.edu.cn/eclipse/releases/luna/打开这个网址就可以看到adt的详细信息: http://developer.android.c ...
- OpenStack实践系列⑨云硬盘服务Cinder
OpenStack实践系列⑨云硬盘服务Cinder八.cinder8.1存储的三大分类 块存储:硬盘,磁盘阵列DAS,SAN存储 文件存储:nfs,GluserFS,Ceph(PB级分布式文件系统), ...
- 完整部署CentOS7.2+OpenStack+kvm 云平台环境(2)--云硬盘等后续配置
继上一篇博客介绍了完整部署CentOS7.2+OpenStack+kvm 云平台环境(1)--基础环境搭建,本篇继续讲述后续部分的内容 1 虚拟机相关1.1 虚拟机位置介绍 openstack上创建的 ...
- 容器服务 TKE 存储插件与云硬盘 CBS 最佳实践应用
引言 随着自研上云的深入,越来越多的有状态服务对于在 TKE 集群中使用云上存储能力的需求也越来越强烈. 目前腾讯云容器服务 TKE(Tencent Kubernetes Engine已支持在 TKE ...
- 云硬盘error、error deleting、deleting状态(数据库基本操作小记)
起因是发现云硬盘显示删光了,但还是创建不了新的云硬盘,在api节点上用cinder list可以看到已经没有硬盘了,但是创建硬盘时,还是会提示配额满了,这是因为数据库里的记录没有更新,对数据库的操作记 ...
- Discuz! X3.1直接进入云平台列表的方法
Discuz! X3.1已经改版,后台不能直接进云平台列表,不方便操作,操作云平台服务时,大家可以这样操作: 1.登录后台:2.访问域名进入云平台列表http://你域名/admin.php?fram ...
随机推荐
- Coherence的NameService
Coherence*Extend模式下客户端需要连接一个或多个proxy Server从而接入集群,在一些比较大型的环境中,Proxy Server往往比较多,一旦修改起来需要修改每个配置文件,在Co ...
- WebLogic Server 12.1.2后的字符型安装模式
weblogic Server 12.1.1全部都可以用原来方式. WebLogic Server 12.1.2后已经取消了console安装模式,目前只有gui和静默安装模式.并且安装方式下也有很大 ...
- C++之string学习
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <list> #include <string& ...
- hive操作记录
hive是依赖于hdfs和yarn的一个数据仓库 数据库和数据仓库的区别: 数据库在存储数据的同时,允许实时的增删改查等操作 数据仓库在存储数据的同时还执行着计算和分析数据的工作,但是并不能实时的进行 ...
- python使用pickle,json等序列化dict
import pickle, json, csv, os, shutil class PersistentDict(dict): ''' Persistent dictionary with an A ...
- ffmpeg 复用
aa 将mkv中的音视频复用成ts流: ffmpeg -i 32_mkv_h264_718x480_ac3.mkv -codec copy -bsf:v h264_mp4toannexb -f m ...
- javascript入门系列演示·三种弹出对话框的用法实例
对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...
- oracle加入not null约束
在创建表时.为列加入not null约束,形式例如以下: column_name data_type [constraint constraint_name] not null 当中,constrai ...
- 用gradle把springboot项目打包成jar
``` 用gradle把springboot项目打包成jar ```### build.gradle 中添加 buildscript { repositories { mavenLocal() mav ...
- css3中-moz、-ms、-webkit,-o分别代表的意思
这种方式在业界上统称:识别码.前缀 //-ms代表[ie]内核识别码 //-moz代表火狐[firefox]内核识别码 //-webkit代表谷歌[chrome]/苹果[safari]内核识别码 // ...