Adapt omsimulator to the latest version

This commit is contained in:
Ilya Shakhat 2016-03-11 18:25:10 +03:00
parent 3d1f4a6a00
commit e3584676dc
3 changed files with 80 additions and 21 deletions

View File

@ -1,9 +1,13 @@
#!/usr/bin/python #!/usr/bin/python
import copy
import os import os
import tempfile import tempfile
ATOP_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.atop') import signal
SERVER_PID = os.path.join(tempfile.gettempdir(), 'performa.oms.pid')
SERVER_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.oms.srv')
CLIENT_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.oms.cln')
UNIQUE_NAME = 'performa_omsimulator' UNIQUE_NAME = 'performa_omsimulator'
DIR = '/tmp/performa/oslo.messaging/tools/' DIR = '/tmp/performa/oslo.messaging/tools/'
@ -45,18 +49,51 @@ def chdir(module):
def start_daemon(module, cmd): def start_daemon(module, cmd):
cmd = ('daemon -n %(name)s -D %(dir)s -- %(cmd)s' % cmd = ('daemon -n %(name)s -D %(dir)s -F %(pid)s -- %(cmd)s' %
dict(name=UNIQUE_NAME, dir=DIR, cmd=cmd)) dict(name=UNIQUE_NAME, dir=DIR, pid=SERVER_PID, cmd=cmd))
rc, stdout, stderr = module.run_command(cmd) rc, stdout, stderr = module.run_command(cmd)
result = dict(changed=True, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd) result = dict(changed=True, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
if rc: if rc:
module.fail_json(msg='Failed to start OMSimulator', **result) module.fail_json(msg='Failed to start omsimulator', **result)
def stop_daemon(module):
rc, stdout, stderr = module.run_command('/bin/cat %s' % SERVER_PID)
if rc:
return
rc, stdout, stderr = module.run_command('pgrep -P %s' % stdout)
os.kill(int(stdout), signal.SIGINT)
time.sleep(2)
def read_file(filename):
fd = None
try:
fd = open(filename)
return json.loads(fd.read())
except IOError:
raise
finally:
if fd:
fd.close()
def transform_series(series):
result = []
for k, v in series.items():
for x in v:
x['name'] = k
result += v
return result
def run(module): def run(module):
params = module.params params = copy.deepcopy(module.params)
if params['mode'] == 'notify': if params['mode'] == 'notify':
server_tool = 'notify-server' server_tool = 'notify-server'
@ -67,13 +104,16 @@ def run(module):
params['server_tool'] = server_tool params['server_tool'] = server_tool
params['client_tool'] = client_tool params['client_tool'] = client_tool
params['server_file'] = SERVER_FILE_NAME
params['client_file'] = CLIENT_FILE_NAME
server = ('python simulator.py ' server = ('python simulator.py '
'--url %(url)s ' '--url %(url)s '
'%(server_tool)s ' '--json %(server_file)s '
'--show-stats true') % params '%(server_tool)s ') % params
client = ('python simulator.py ' client = ('python simulator.py '
'--url=%(url)s ' '--url=%(url)s '
'--json %(client_file)s '
'-l %(duration)s ' '-l %(duration)s '
'%(client_tool)s ' '%(client_tool)s '
'-p %(threads)s ') % params '-p %(threads)s ') % params
@ -86,22 +126,30 @@ def run(module):
start_daemon(module, server) start_daemon(module, server)
start = int(time.time())
rc, stdout, stderr = module.run_command(client) rc, stdout, stderr = module.run_command(client)
end = int(time.time())
if rc: if rc:
module.fail_json(msg='Failed to run omsimulator client', stderr=stderr) module.fail_json(msg='Failed to start omsimulator',
stderr=stderr, rc=rc, cmd=client)
stop_daemon(module)
try: try:
parsed = parse_output(stdout) client_data = read_file(CLIENT_FILE_NAME)
parsed['start'] = start server_data = read_file(SERVER_FILE_NAME)
parsed['end'] = end
result = dict(records=[parsed]) client_summary = client_data['summary']['client']
client_summary['component'] = 'client'
server_summary = server_data['summary']
server_summary['component'] = 'server'
series = transform_series(client_data['series'])
series.extend(transform_series(server_data['series']))
result = dict(records=[client_summary, server_summary], series=series)
module.exit_json(**result) module.exit_json(**result)
except Exception as e: except Exception as e:
msg = 'Failed to start omsimulator client %s' % e msg = 'Failed to read omsimulator output: %s' % e
module.fail_json(msg=msg, rc=rc, stderr=stderr, stdout=stdout) module.fail_json(msg=msg, rc=rc, stderr=stderr, stdout=stdout)

View File

@ -14,14 +14,17 @@ Messages per second depending on threads count:
axes: axes:
x: threads x: threads
y: messages per sec y: messages per sec
y2: latency
chart: line chart: line
pipeline: pipeline:
- { $match: { task: omsimulator, status: OK }} - { $match: { task: omsimulator, status: OK }}
- { $group: { _id: { threads: "$threads" }, - { $group: { _id: { threads: "$threads" },
msg_sent_per_sec: { $avg: { $divide: ["$msg_sent", "$duration"] }} msg_sent_per_sec: { $avg: { $divide: ["$count", "$duration"] }},
latency: { $avg: "$latency" }
}} }}
- { $project: { x: "$_id.threads", - { $project: { x: "$_id.threads",
y: "$msg_sent_per_sec" y: "$msg_sent_per_sec",
y2: { $multiply: ["$latency", 1000] }
}} }}
- { $sort: { x: 1 }} - { $sort: { x: 1 }}
''' | chart ''' | chart
@ -39,7 +42,7 @@ Messages per second and rabbit CPU consumption depending on threads count:
pipeline: pipeline:
- { $match: { task: omsimulator, status: OK }} - { $match: { task: omsimulator, status: OK }}
- { $group: { _id: { threads: "$threads" }, - { $group: { _id: { threads: "$threads" },
msg_sent_per_sec: { $avg: { $divide: ["$msg_sent", "$duration"] }}, msg_sent_per_sec: { $avg: { $divide: ["$count", "$duration"] }},
rabbit_total: { $avg: "$rabbit_total" } rabbit_total: { $avg: "$rabbit_total" }
}} }}
- { $project: { x: "$_id.threads", - { $project: { x: "$_id.threads",

View File

@ -7,19 +7,27 @@ setup:
- -
hosts: $target hosts: $target
tasks: tasks:
- apt: name=git
become: yes
- name: installing omsimulator - name: installing omsimulator
git: repo=git://git.openstack.org/openstack/oslo.messaging git: repo=git://git.openstack.org/openstack/oslo.messaging
dest=/tmp/performa/oslo.messaging dest=/tmp/performa/oslo.messaging
- command: git fetch https://review.openstack.org/openstack/oslo.messaging refs/changes/91/291191/2
args:
chdir: /tmp/performa/oslo.messaging
- command: git checkout FETCH_HEAD
args:
chdir: /tmp/performa/oslo.messaging
- apt: name=atop - apt: name=atop
become: yes become: yes
- apt: name=daemon - apt: name=daemon
become: yes become: yes
execution:
- -
hosts: $target hosts: $target
tasks: tasks:
- atop: command=start - atop: command=start
execution:
- -
hosts: $target hosts: $target
matrix: matrix: