Skip to content

Commit 83c07b2

Browse files
committed
Add bench test
1 parent eb987ef commit 83c07b2

File tree

9 files changed

+244
-11
lines changed

9 files changed

+244
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ waitISC.log
1717
.env
1818

1919
prof
20+
src/tests/bench/result.txt

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ This proof of concept aims to show how the **iris interoperability framework** c
6666
- [7.11. version](#711-version)
6767
- [7.12. log](#712-log)
6868
- [8. Credits](#8-credits)
69+
- [9. Benchmarks](#9-benchmarks)
6970

7071
## 1.2. Example
7172

@@ -1333,4 +1334,21 @@ output :
13331334

13341335
Most of the code came from PEX for Python by Mo Cheng and Summer Gerry.
13351336

1336-
Works only on IRIS 2021.2 +
1337+
Works only on IRIS 2021.2 +
1338+
1339+
# 9. Benchmarks
1340+
1341+
8 senarios with thoses parameters :
1342+
- 100 messages
1343+
- body : simple string `test`
1344+
1345+
| Scenario | Time (s) |
1346+
| --- | --- |
1347+
| Python BP to Python BO with Iris Message | 0.739 |
1348+
| Python BP to Python BO with Python Message | 0.732 |
1349+
| ObjetScript BP to Python BO with Iris Message | 0.594 |
1350+
| ObjetScript BP to Python BO with Python Message | 0.642 |
1351+
| Python BP to ObjetScript BO with Iris Message | 0.642 |
1352+
| Python BP to ObjetScript BO with Python Message | 0.675 |
1353+
| ObjetScript BP to ObjetScript BO with Iris Message | 0.159 |
1354+
| ObjetScript BP to ObjetScript BO with Python Message | 0.182 |

src/iop/_director.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def test_component(target,message=None,classname=None,body=None):
258258
message = iris.cls("IOP.Message")._New()
259259
message.classname = classname
260260
if body:
261-
message.json = _Utils.string_to_stream(body)
261+
message.json = body
262262
else:
263263
message.json = _Utils.string_to_stream("{}")
264264
# serialize the message

src/iop/_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ def migrate(filename=None):
216216
except AttributeError:
217217
print("No productions to register")
218218
try:
219-
# remove the path from the system path (with or without the trailing slash)
220-
sys.path.remove(path+'/')
221219
sys.path.remove(path)
222220
except ValueError:
223221
pass

src/tests/bench/bp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ class BenchIoPProcess(BusinessProcess):
44
def on_init(self):
55
if not hasattr(self, 'size'):
66
self.size = 100
7+
if not hasattr(self, 'target'):
8+
self.target = 'Python.BenchIoPOperation'
79

810
def on_message(self, request):
911
for _ in range(self.size):
10-
_ = self.send_request_sync("Python.BenchIoPOperation",request)
12+
_ = self.send_request_sync(self.target,request)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Class Bench.Operation Extends Ens.BusinessOperation
2+
{
3+
4+
Parameter INVOCATION = "Queue";
5+
6+
Method Method(
7+
pRequest As Ens.Request,
8+
Output pResponse As Ens.Response) As %Status
9+
{
10+
set tStatus = $$$OK
11+
set pResponse = ##class(Ens.Response).%New()
12+
13+
try{
14+
set pResponse = pRequest
15+
16+
}
17+
catch exp
18+
{
19+
set tStatus = exp.AsStatus()
20+
}
21+
Quit tStatus
22+
}
23+
24+
XData MessageMap
25+
{
26+
<MapItems>
27+
<MapItem MessageType="Ens.Request">
28+
<Method>Method</Method>
29+
</MapItem>
30+
<MapItem MessageType="IOP.Message">
31+
<Method>Method</Method>
32+
</MapItem>
33+
</MapItems>
34+
}
35+
36+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Class Bench.Process Extends Ens.BusinessProcess
2+
{
3+
4+
Property TargetConfigName As %String(MAXLEN = 1000) [ InitialExpression = "Bench.Operation" ];
5+
6+
Property Size As %Integer [ InitialExpression = 100 ];
7+
8+
Parameter SETTINGS = "Size:Basic,TargetConfigName:Basic";
9+
10+
Method OnRequest(
11+
pDocIn As %Library.Persistent,
12+
Output pDocOut As %Library.Persistent) As %Status
13+
{
14+
set status = $$$OK
15+
16+
try {
17+
18+
for i=1:1:..Size {
19+
$$$ThrowOnError(..SendRequestSync(..TargetConfigName,pDocIn,.pDocOut))
20+
}
21+
22+
} catch ex {
23+
set status = ex.AsStatus()
24+
}
25+
26+
Quit status
27+
}
28+
29+
Storage Default
30+
{
31+
<Data name="ProcessDefaultData">
32+
<Subscript>"Process"</Subscript>
33+
<Value name="1">
34+
<Value>TargetConfigNames</Value>
35+
</Value>
36+
<Value name="2">
37+
<Value>Size</Value>
38+
</Value>
39+
<Value name="3">
40+
<Value>TargetConfigName</Value>
41+
</Value>
42+
</Data>
43+
<DefaultData>ProcessDefaultData</DefaultData>
44+
<Type>%Storage.Persistent</Type>
45+
}
46+
47+
}

src/tests/bench/settings.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import os
55

6+
import iris
7+
68
# get current directory
79
current_dir = os.path.dirname(os.path.realpath(__file__))
810
# get working directory
@@ -13,6 +15,10 @@
1315
# create a strings with current_dir and src_dir with a | separator
1416
classpaths = f"{current_dir}|{src_dir}"
1517

18+
# load Cos Classes
19+
iris.cls('%SYSTEM.OBJ').LoadDir(os.path.join(
20+
current_dir, 'cls'), 'cubk', "*.cls", 1)
21+
1622
CLASSES = {
1723
"Python.BenchIoPOperation": BenchIoPOperation,
1824
"Python.BenchIoPProcess": BenchIoPProcess,
@@ -26,6 +32,11 @@
2632
"Description": "",
2733
"ActorPoolSize": "1",
2834
"Item": [
35+
{
36+
"@Name": "Bench.Operation",
37+
"@Category": "",
38+
"@ClassName": "Bench.Operation",
39+
},
2940
{
3041
"@Name": "Python.BenchIoPOperation",
3142
"@Category": "",
@@ -57,8 +68,60 @@
5768
"@Name": "%classpaths",
5869
"#text": classpaths
5970
}
71+
},
72+
{
73+
"@Name": "Python.BenchIoPProcess.To.Cls",
74+
"@Category": "",
75+
"@ClassName": "Python.BenchIoPProcess",
76+
"@PoolSize": "0",
77+
"@Enabled": "true",
78+
"@Foreground": "false",
79+
"@Comment": "",
80+
"@LogTraceEvents": "false",
81+
"@Schedule": "",
82+
"Setting": [{
83+
"@Target": "Host",
84+
"@Name": "%classpaths",
85+
"#text": classpaths
86+
}, {
87+
"@Target": "Host",
88+
"@Name": "%settings",
89+
"#text": "target=Bench.Operation"
90+
}]
91+
},
92+
{
93+
"@Name": "Bench.Process",
94+
"@Category": "",
95+
"@ClassName": "Bench.Process",
96+
"@PoolSize": "1",
97+
"@Enabled": "true",
98+
"@Foreground": "false",
99+
"@Comment": "",
100+
"@LogTraceEvents": "false",
101+
"@Schedule": "",
102+
"Setting": {
103+
"@Target": "Host",
104+
"@Name": "TargetConfigName",
105+
"#text": "Python.BenchIoPOperation"
106+
}
107+
},
108+
{
109+
"@Name": "Bench.Process.To.Cls",
110+
"@Category": "",
111+
"@ClassName": "Bench.Process",
112+
"@PoolSize": "1",
113+
"@Enabled": "true",
114+
"@Foreground": "false",
115+
"@Comment": "",
116+
"@LogTraceEvents": "false",
117+
"@Schedule": "",
118+
"Setting": {
119+
"@Target": "Host",
120+
"@Name": "TargetConfigName",
121+
"#text": "Bench.Operation"
122+
}
60123
}
61124
]
62125
}
63126
}
64-
]
127+
]

src/tests/test_bench.py

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,83 @@ def setup_class(cls):
1919
_Director.set_default_production('Bench.Production')
2020
# start the production
2121
_Director.start_production()
22+
# create a list of results
23+
cls.results = []
24+
25+
def test_bench_iris(self):
26+
# this test is made to preload the production
27+
_Director.test_component('Python.BenchIoPProcess')
28+
2229

2330
def test_bench_iris_message(self):
2431
body = "test"
2532
result = timeit.timeit(lambda: _Director.test_component('Python.BenchIoPProcess','','iris.Ens.StringRequest',body), number=1)
26-
# print the time in pytest output
27-
print(f"Time: {result}")
33+
# set the result in the list
34+
name = 'Python BP to Python BO with Iris Message'
35+
self.results.append((name,result))
36+
# assert the result
37+
assert result > 0
38+
39+
def test_bench_iris_message_to_cls(self):
40+
body = "test"
41+
result = timeit.timeit(lambda: _Director.test_component('Python.BenchIoPProcess.To.Cls','','iris.Ens.StringRequest',body), number=1)
42+
# set the result in the list
43+
name = 'Python BP to ObjetScript BO with Iris Message'
44+
self.results.append((name,result))
2845
# assert the result
2946
assert result > 0
3047

3148
def test_bench_python_message(self):
32-
body = "test"*200000
49+
body = "test"
3350
result = timeit.timeit(lambda: _Director.test_component('Python.BenchIoPProcess','','msg.MyMessage',f'{{"message":"{body}"}}'), number=1)
34-
# print the time in pytest output
35-
print(f"Time: {result}")
51+
# set the result in the list
52+
name = 'Python BP to Python BO with Python Message'
53+
self.results.append((name,result))
54+
# assert the result
55+
assert result > 0
56+
57+
def test_bench_python_message_to_cls(self):
58+
body = "test"
59+
result = timeit.timeit(lambda: _Director.test_component('Python.BenchIoPProcess.To.Cls','','msg.MyMessage',f'{{"message":"{body}"}}'), number=1)
60+
# set the result in the list
61+
name = 'Python BP to ObjetScript BO with Python Message'
62+
self.results.append((name,result))
63+
# assert the result
64+
assert result > 0
65+
66+
def test_bench_cls_iris_message(self):
67+
body = "test"
68+
result = timeit.timeit(lambda: _Director.test_component('Bench.Process','','iris.Ens.StringRequest',body), number=1)
69+
# set the result in the list
70+
name = 'ObjetScript BP to Python BO with Iris Message'
71+
self.results.append((name,result))
72+
# assert the result
73+
assert result > 0
74+
75+
def test_bench_cls_iris_message_to_cls(self):
76+
body = "test"
77+
result = timeit.timeit(lambda: _Director.test_component('Bench.Process.To.Cls','','iris.Ens.StringRequest',body), number=1)
78+
# set the result in the list
79+
name = 'ObjetScript BP to ObjetScript BO with Iris Message'
80+
self.results.append((name,result))
81+
# assert the result
82+
assert result > 0
83+
84+
def test_bench_cls_python_message(self):
85+
body = "test"
86+
result = timeit.timeit(lambda: _Director.test_component('Bench.Process','','msg.MyMessage',f'{{"message":"{body}"}}'), number=1)
87+
# set the result in the list
88+
name = 'ObjetScript BP to Python BO with Python Message'
89+
self.results.append((name,result))
90+
# assert the result
91+
assert result > 0
92+
93+
def test_bench_cls_python_message_to_cls(self):
94+
body = "test"
95+
result = timeit.timeit(lambda: _Director.test_component('Bench.Process.To.Cls','','msg.MyMessage',f'{{"message":"{body}"}}'), number=1)
96+
# set the result in the list
97+
name = 'ObjetScript BP to ObjetScript BO with Python Message'
98+
self.results.append((name,result))
3699
# assert the result
37100
assert result > 0
38101

@@ -43,3 +106,8 @@ def teardown_class(cls):
43106
_Director.stop_production()
44107
# set the default production
45108
_Director.set_default_production('test')
109+
# write the results in a file
110+
current_dir = os.path.dirname(os.path.abspath(__file__))
111+
with open(os.path.join(current_dir,'bench','result.txt'),'w') as f:
112+
for name,result in cls.results:
113+
f.write(f'{name}: {result}\n')

0 commit comments

Comments
 (0)