Browse Source

Adapt omsimulator to the latest version

Ilya Shakhat 3 years ago
parent
commit
e3584676dc

+ 64
- 16
performa/modules/omsimulator.py View File

@@ -1,9 +1,13 @@
1 1
 #!/usr/bin/python
2
-
2
+import copy
3 3
 import os
4 4
 import tempfile
5 5
 
6
-ATOP_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.atop')
6
+import signal
7
+
8
+SERVER_PID = os.path.join(tempfile.gettempdir(), 'performa.oms.pid')
9
+SERVER_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.oms.srv')
10
+CLIENT_FILE_NAME = os.path.join(tempfile.gettempdir(), 'performa.oms.cln')
7 11
 UNIQUE_NAME = 'performa_omsimulator'
8 12
 DIR = '/tmp/performa/oslo.messaging/tools/'
9 13
 
@@ -45,18 +49,51 @@ def chdir(module):
45 49
 
46 50
 
47 51
 def start_daemon(module, cmd):
48
-    cmd = ('daemon -n %(name)s -D %(dir)s -- %(cmd)s' %
49
-           dict(name=UNIQUE_NAME, dir=DIR, cmd=cmd))
52
+    cmd = ('daemon -n %(name)s -D %(dir)s -F %(pid)s -- %(cmd)s' %
53
+           dict(name=UNIQUE_NAME, dir=DIR, pid=SERVER_PID, cmd=cmd))
50 54
 
51 55
     rc, stdout, stderr = module.run_command(cmd)
52 56
     result = dict(changed=True, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
53 57
 
54 58
     if rc:
55
-        module.fail_json(msg='Failed to start OMSimulator', **result)
59
+        module.fail_json(msg='Failed to start omsimulator', **result)
60
+
61
+
62
+def stop_daemon(module):
63
+    rc, stdout, stderr = module.run_command('/bin/cat %s' % SERVER_PID)
64
+
65
+    if rc:
66
+        return
67
+
68
+    rc, stdout, stderr = module.run_command('pgrep -P %s' % stdout)
69
+    os.kill(int(stdout), signal.SIGINT)
70
+
71
+    time.sleep(2)
72
+
73
+
74
+def read_file(filename):
75
+    fd = None
76
+    try:
77
+        fd = open(filename)
78
+        return json.loads(fd.read())
79
+    except IOError:
80
+        raise
81
+    finally:
82
+        if fd:
83
+            fd.close()
84
+
85
+
86
+def transform_series(series):
87
+    result = []
88
+    for k, v in series.items():
89
+        for x in v:
90
+            x['name'] = k
91
+        result += v
92
+    return result
56 93
 
57 94
 
58 95
 def run(module):
59
-    params = module.params
96
+    params = copy.deepcopy(module.params)
60 97
 
61 98
     if params['mode'] == 'notify':
62 99
         server_tool = 'notify-server'
@@ -67,13 +104,16 @@ def run(module):
67 104
 
68 105
     params['server_tool'] = server_tool
69 106
     params['client_tool'] = client_tool
107
+    params['server_file'] = SERVER_FILE_NAME
108
+    params['client_file'] = CLIENT_FILE_NAME
70 109
 
71 110
     server = ('python simulator.py '
72 111
               '--url %(url)s '
73
-              '%(server_tool)s '
74
-              '--show-stats true') % params
112
+              '--json %(server_file)s '
113
+              '%(server_tool)s ') % params
75 114
     client = ('python simulator.py '
76 115
               '--url=%(url)s '
116
+              '--json %(client_file)s '
77 117
               '-l %(duration)s '
78 118
               '%(client_tool)s '
79 119
               '-p %(threads)s ') % params
@@ -86,22 +126,30 @@ def run(module):
86 126
 
87 127
     start_daemon(module, server)
88 128
 
89
-    start = int(time.time())
90 129
     rc, stdout, stderr = module.run_command(client)
91
-    end = int(time.time())
92 130
 
93 131
     if rc:
94
-        module.fail_json(msg='Failed to run omsimulator client', stderr=stderr)
132
+        module.fail_json(msg='Failed to start omsimulator',
133
+                         stderr=stderr, rc=rc, cmd=client)
134
+
135
+    stop_daemon(module)
95 136
 
96 137
     try:
97
-        parsed = parse_output(stdout)
98
-        parsed['start'] = start
99
-        parsed['end'] = end
138
+        client_data = read_file(CLIENT_FILE_NAME)
139
+        server_data = read_file(SERVER_FILE_NAME)
140
+
141
+        client_summary = client_data['summary']['client']
142
+        client_summary['component'] = 'client'
143
+        server_summary = server_data['summary']
144
+        server_summary['component'] = 'server'
145
+
146
+        series = transform_series(client_data['series'])
147
+        series.extend(transform_series(server_data['series']))
100 148
 
101
-        result = dict(records=[parsed])
149
+        result = dict(records=[client_summary, server_summary], series=series)
102 150
         module.exit_json(**result)
103 151
     except Exception as e:
104
-        msg = 'Failed to start omsimulator client %s' % e
152
+        msg = 'Failed to read omsimulator output: %s' % e
105 153
         module.fail_json(msg=msg, rc=rc, stderr=stderr, stdout=stdout)
106 154
 
107 155
 

+ 6
- 3
performa/scenarios/mq/omsimulator.rst View File

@@ -14,14 +14,17 @@ Messages per second depending on threads count:
14 14
     axes:
15 15
       x: threads
16 16
       y: messages per sec
17
+      y2: latency
17 18
     chart: line
18 19
     pipeline:
19 20
     - { $match: { task: omsimulator, status: OK }}
20 21
     - { $group: { _id: { threads: "$threads" },
21
-                  msg_sent_per_sec: { $avg: { $divide: ["$msg_sent", "$duration"] }}
22
+                  msg_sent_per_sec: { $avg: { $divide: ["$count", "$duration"] }},
23
+                  latency: { $avg: "$latency" }
22 24
                 }}
23 25
     - { $project: { x: "$_id.threads",
24
-                    y: "$msg_sent_per_sec"
26
+                    y: "$msg_sent_per_sec",
27
+                    y2: { $multiply: ["$latency", 1000] }
25 28
                   }}
26 29
     - { $sort: { x: 1 }}
27 30
 ''' | chart
@@ -39,7 +42,7 @@ Messages per second and rabbit CPU consumption depending on threads count:
39 42
     pipeline:
40 43
     - { $match: { task: omsimulator, status: OK }}
41 44
     - { $group: { _id: { threads: "$threads" },
42
-                  msg_sent_per_sec: { $avg: { $divide: ["$msg_sent", "$duration"] }},
45
+                  msg_sent_per_sec: { $avg: { $divide: ["$count", "$duration"] }},
43 46
                   rabbit_total: { $avg: "$rabbit_total" }
44 47
                 }}
45 48
     - { $project: { x: "$_id.threads",

+ 10
- 2
performa/scenarios/mq/omsimulator.yaml View File

@@ -7,19 +7,27 @@ setup:
7 7
   -
8 8
     hosts: $target
9 9
     tasks:
10
+    - apt: name=git
11
+      become: yes
10 12
     - name: installing omsimulator
11 13
       git: repo=git://git.openstack.org/openstack/oslo.messaging
12 14
            dest=/tmp/performa/oslo.messaging
15
+    - command: git fetch https://review.openstack.org/openstack/oslo.messaging refs/changes/91/291191/2
16
+      args:
17
+        chdir: /tmp/performa/oslo.messaging
18
+    - command: git checkout FETCH_HEAD
19
+      args:
20
+        chdir: /tmp/performa/oslo.messaging
13 21
     - apt: name=atop
14 22
       become: yes
15 23
     - apt: name=daemon
16 24
       become: yes
25
+
26
+execution:
17 27
   -
18 28
     hosts: $target
19 29
     tasks:
20 30
     - atop: command=start
21
-
22
-execution:
23 31
   -
24 32
     hosts: $target
25 33
     matrix:

Loading…
Cancel
Save