Linux中cinder的作用,osprofiler在OpenStack Cinder里的使用

最近在做OpenStack Cinder driver的性能调试, 之前一直是通过在driver里面加入decorator,完成driver各个接口的执行时间的统计。

其实在openstack,已经在孵化一个叫osprofiler的project,然后这个可以通过与OpenStack Ceilometer的集成,可以轻松完成性能数据的统计,大幅的节省性能调优的时间.

osprofiler原理:

通过在OpenStack不同Component之间使用osprofiler的trace,记录所有的wsgi,rpc,driver各个接口的开始和结束时间,然后通过rpc message把记录到的数据发送到Ceilometer数据库进行存储。

这样用户可以在执行完OpenStack的操作后,通过osprofiler的CLI接口,以html或者JSON的格式可视化的显示出各个接口的执行顺序和时间,从而发现一个call stack的瓶颈。

[NOTE]: 有网友反映和本人自己的实验,在最新的master branch上,不能正确产生正确的osprofiler数据,error如下:

[待增加]

解决方案是使用kilo版本:

cd ~/devstack

# 保存当前的change

git stash

git checkout stable/kilo

# 重新应用change

git stash pop

# 其他配置保持不变

# 让后在./stack.sh./stack.sh

#升级Python-cinderclient,安装python-ceilometerclient

sudo pip install python-cinderclient --upgrade

sudo pip install python-ceilometerclient

基本的使用:

from osprofiler importprofiler#使用前,一定要init,否则不会用任何的数据记录

profiler.init("SECRET_HMAC_KEY", base_id='sadfsdafasdfasdfas', parent_id='dsafafasdfsadf')defsome_func():

profiler.start("point_name", {"any_key": "with_any_value"})#your code

print "I am between some_func"profiler.stop({"any_info_about_point": "in_this_dict"})

@profiler.trace("point_name",

info={"any_info_about_point": "in_this_dict"},

hide_args=False)def some_func2(*args, **kwargs):#If you need to hide args in profile info, put hide_args=True

print "Hello, osprofiler"

pass

defsome_func3():

with profiler.Trace("point_name",

info={"any_key": "with_any_value"}):#some code here

pass@profiler.trace_cls("point_name", info={}, hide_args=False,

trace_private=False)classTracedClass(object):deftraced_method(self):print "Trace me"

pass

def_traced_only_if_trace_private_true(self):pass

#把所有的记录写入到json文件里面

def send_info_to_file_collector(info, context=None):

with open("traces", "a") as f:

f.write(json.dumps(info))

notifier.set(send_info_to_file_collector)#下面的函数调用都会被一一记录

some_func()

some_func2(test='asdfasdf', adf=313)

trace=TracedClass()

trace.traced_method()

然后,你在当前目录的 traces 文件问发现很多的log,有个问题数据的可读性比较差,那么OpenStack是怎么解决的呢?

下面以lvm 的cinder driver为例,说明如何配置Cinder,osprofiler以及Ceilometer的集成,,

首先,要setup devstack,下面是devstack的local.conf的配置: (如果你是首次使用devstack,请移步 http://www.linuxidc.com/Linux/2016-01/127509.htm)

(注意,我enable了Ceilometer和Neutron的所有组件,在使用这个文件时,要把HOST_IP, SERVICE_HOST改为本机的IP

[[local|localrc]]

HOST_IP=192.168.14.128SERVICE_HOST=192.168.14.128ADMIN_PASSWORD=welcome

DATABASE_PASSWORD=$ADMIN_PASSWORD

RABBIT_PASSWORD=$ADMIN_PASSWORD

SERVICE_PASSWORD=$ADMIN_PASSWORD

SERVICE_TOKEN=$ADMIN_PASSWORD

DEST=/opt/stack

LOGFILE=$DEST/logs/stack.sh.log

SCREEN_LOGDIR=$DEST/logs/screen

OFFLINE=False

RECLONE=False

LOG_COLOR=False

disable_service horizon

enable_service q-svc

enable_service q-agt

enable_service q-dhcp

enable_service q-l3

enable_service q-meta

enable_service neutron

# Enable the ceilometer metering services

enable_service ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector

# Enable the ceilometer alarming services

enable_service ceilometer-alarm-evaluator,ceilometer-alarm-notifier

# Enable the ceilometer api services

enable_service ceilometer-api

# 这个profiler一定要加,是cinder的性能信息记录到Ceilometer的关键

CEILOMETER_NOTIFICATION_TOPICS=notifications,profiler

disable_service n-net

disable_service tempest

disable_service h-eng,h-api,h-api-cfn,h-api-cw

PHYSICAL_NETWORK=physnet1

FIXED_RANGE=192.168.106.0/24FIXED_NETWORK_SIZE=32NETWORK_GATEWAY=192.168.106.1[[post-config|$CINDER_CONF]]

[profiler]

profiler_enabled=True

trace_sqlalchemy=False

[[post-config|/$Q_PLUGIN_CONF_FILE]]

[ml2]

tenant_network_types=vlan

[ml2_type_vlan]

network_vlan_ranges= physnet1:100:110[ovs]

bridge_mappings= physnet1:br-eth1

enable_tunneling= False

然后就是执行 ./stack.sh

产生与收集Cinder操作的性能数据:

peter@Ubuntu:~/devstack$ cinder --profile SECRET_KEY create --name peter 1

+---------------------------------------+--------------------------------------+

| Property | Value |

+---------------------------------------+--------------------------------------+

| attachments | [] |

| availability_zone | nova |

| bootable | false |

| consistencygroup_id | None |

| created_at | 2015-04-04T14:58:51.000000 |

| description | None |

| encrypted | False |

| id | 28857983-3240-445d-a60b-3b91295c31e8 |

| metadata | {} |

| multiattach | False |

| name | peter |

| os-vol-host-attr:host | None |

| os-vol-mig-status-attr:migstat | None |

| os-vol-mig-status-attr:name_id | None |

| os-vol-tenant-attr:tenant_id | ade7584debc54964b4fef737e56e062d |

| os-volume-replication:driver_data | None |

| os-volume-replication:extended_status | None |

| replication_status | disabled |

| size | 1 |

| snapshot_id | None |

| source_volid | None |

| status | creating |

| user_id | 56aac792735046dea02e12e85e0d1a03 |

| volume_type | lvmdriver-1 |

+---------------------------------------+--------------------------------------+Trace ID: aa4903cc-fd0c-42ef-96f1-bd1c5a1740f1

To display trace use next command:

osprofiler trace show--html aa4903cc-fd0c-42ef-96f1-bd1c5a1740f1

导出性能测试的数据为HTML格式

osprofiler trace show --html aa4903cc-fd0c-42ef-96f1-bd1c5a1740f1 --out test.html

html内容如下(需要FQ,这个页面需要访问google.com ^_^)

查看各个接口的执行时间,下图给出了每个被统计的接口在不同的service之间的执行时间

de55ffa4252aaadcc86cd537e67dff99.png

查看接口的参数,可以点击函数,查看具体的参数

f60b2c803a2d34bc4a4bdc8159c52ba4.png

上面的view可以很轻松的实现对openstack各个接口调用执行时间的统计,可视化的显示了特定操作的性能瓶颈在哪里。

Cinder driver的各个接口的性能统计:

上面的工作,还有一个问题没有解决,如果你的driver其实有多个层级的class(如driver.create_volume->AnotherClass.def1->AnotherClass.def2->AnotherClass.defn),那么我只知道入口函数driver.create_volume的执行时间,并不知道在AnotherClass内部各个接口的执行时间(def1多少时间,def2多少时间。这个就要稍微改下lvm driver的代码了,可以为lvm driver的所有class 加上如下的decorator:

@profiler.trace_cls("AnotherClass", info={}, hide_args=False,

trace_private=True)classAnotherClass(object):defdef1:pass

defdef2:pass

这样更改代码后,然后再重启cinder service,你会得到更详细的数据

参考文章及深入阅读:

下面是小编为你精选的Openstack相关知识,看看是否有你喜欢的:

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值