Skip to content

Commit c37e54c

Browse files
authored
benchmark_cortex.py, change eval -> storm (#3550)
1 parent 1497e59 commit c37e54c

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

scripts/benchmark_cortex.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ async def acount(genr):
8080
count += 1
8181
return count
8282

83+
async def acountPodes(genr):
84+
'''Count storm node messages'''
85+
count = 0
86+
async for (m, _) in genr:
87+
if m == 'node':
88+
count += 1
89+
return count
90+
8391
syntest = s_t_utils.SynTest()
8492

8593
async def layerByName(prox: s_telepath.Proxy, name: str):
@@ -316,76 +324,76 @@ async def getCortexAndProxy(self) -> AsyncIterator[Tuple[Any, Any]]:
316324
@benchmark({'remote'})
317325
async def do00EmptyQuery(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
318326
for _ in range(self.workfactor // 10):
319-
count = await acount(prox.eval('', opts=self.opts))
327+
count = await acountPodes(prox.storm('', opts=self.opts))
320328

321329
assert count == 0
322330
return self.workfactor // 10
323331

324332
@benchmark({'remote'})
325333
async def do00NewQuery(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
326334
for i in range(self.workfactor):
327-
count = await acount(prox.eval(f'$x={i}', opts=self.opts))
335+
count = await acountPodes(prox.storm(f'$x={i}', opts=self.opts))
328336

329337
assert count == 0
330338
return self.workfactor
331339

332340
@benchmark({'official', 'remote'})
333341
async def do01SimpleCount(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
334-
count = await acount(prox.eval('inet:ipv4 | count | spin', opts=self.opts))
342+
count = await acountPodes(prox.storm('inet:ipv4 | count | spin', opts=self.opts))
335343
assert count == 0
336344
return self.workfactor
337345

338346
@benchmark({'official', 'remote'})
339347
async def do02LiftSimple(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
340-
count = await acount(prox.eval('inet:ipv4', opts=self.opts))
348+
count = await acountPodes(prox.storm('inet:ipv4', opts=self.opts))
341349
assert count == self.workfactor
342350
return count
343351

344352
@benchmark({'official', 'remote'})
345353
async def do02LiftFilterAbsent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
346-
count = await acount(prox.eval('inet:ipv4 | +#newp', opts=self.opts))
354+
count = await acountPodes(prox.storm('inet:ipv4 | +#newp', opts=self.opts))
347355
assert count == 0
348356
return 1
349357

350358
@benchmark({'official', 'remote'})
351359
async def do02LiftFilterPresent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
352-
count = await acount(prox.eval('inet:ipv4 | +#all', opts=self.opts))
360+
count = await acountPodes(prox.storm('inet:ipv4 | +#all', opts=self.opts))
353361
assert count == self.workfactor
354362
return count
355363

356364
@benchmark({'official', 'remote'})
357365
async def do03LiftBySecondaryAbsent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
358-
count = await acount(prox.eval('inet:dns:a:fqdn=newp', opts=self.opts))
366+
count = await acountPodes(prox.storm('inet:dns:a:fqdn=newp', opts=self.opts))
359367
assert count == 0
360368
return 1
361369

362370
@benchmark({'official', 'remote'})
363371
async def do03LiftBySecondaryPresent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
364-
count = await acount(prox.eval('inet:dns:a:fqdn=blackhole.website', opts=self.opts))
372+
count = await acountPodes(prox.storm('inet:dns:a:fqdn=blackhole.website', opts=self.opts))
365373
assert count == self.workfactor // 10
366374
return count
367375

368376
@benchmark({'official', 'remote'})
369377
async def do04LiftByTagAbsent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
370-
count = await acount(prox.eval('inet:ipv4#newp', opts=self.opts))
378+
count = await acountPodes(prox.storm('inet:ipv4#newp', opts=self.opts))
371379
assert count == 0
372380
return 1
373381

374382
@benchmark({'official', 'remote'})
375383
async def do04LiftByTagPresent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
376-
count = await acount(prox.eval('inet:ipv4#even', opts=self.opts))
384+
count = await acountPodes(prox.storm('inet:ipv4#even', opts=self.opts))
377385
assert count == self.workfactor // 2
378386
return count
379387

380388
@benchmark({'official', 'remote'})
381389
async def do05PivotAbsent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
382-
count = await acount(prox.eval('inet:ipv4#odd -> inet:dns:a', opts=self.opts))
390+
count = await acountPodes(prox.storm('inet:ipv4#odd -> inet:dns:a', opts=self.opts))
383391
assert count == 0
384392
return self.workfactor // 2
385393

386394
@benchmark({'official', 'remote'})
387395
async def do06PivotPresent(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
388-
count = await acount(prox.eval('inet:ipv4#even -> inet:dns:a', opts=self.opts))
396+
count = await acountPodes(prox.storm('inet:ipv4#even -> inet:dns:a', opts=self.opts))
389397
assert count == self.workfactor // 2 + self.workfactor // 10
390398
return count
391399

@@ -466,21 +474,21 @@ async def do08LocalAddNodes(self, core: s_cortex.Cortex, prox: s_telepath.Proxy)
466474

467475
@benchmark({'official', 'remote'})
468476
async def do09DelNodes(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
469-
count = await acount(prox.eval('inet:url | delnode', opts=self.opts))
477+
count = await acountPodes(prox.storm('inet:url | delnode', opts=self.opts))
470478
assert count == 0
471479
return self.workfactor
472480

473481
@benchmark({'remote'})
474482
async def do10AutoAdds(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
475483
q = "inet:ipv4 $val=$lib.str.format('{num}.rev', num=$(1000000-$node.value())) [:dns:rev=$val]"
476-
count = await acount(prox.eval(q, opts=self.opts))
484+
count = await acountPodes(prox.storm(q, opts=self.opts))
477485
assert count == self.workfactor
478486
return self.workfactor
479487

480488
@benchmark({'remote'})
481489
async def do10SlashAdds(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) -> int:
482490
q = '[ inet:ipv4=1.2.0.0/16 ] | spin'
483-
count = await acount(prox.eval(q, opts=self.opts))
491+
count = await acountPodes(prox.storm(q, opts=self.opts))
484492
assert count == 0
485493
return 2 ** 16
486494

@@ -490,7 +498,7 @@ async def do10Formatting(self, core: s_cortex.Cortex, prox: s_telepath.Proxy) ->
490498
The same as do10AutoAdds without the adds (to isolate the autoadd part)
491499
'''
492500
q = "inet:ipv4 $val=$lib.str.format('{num}.rev', num=$(1000000-$node.value()))"
493-
count = await acount(prox.eval(q, opts=self.opts))
501+
count = await acountPodes(prox.storm(q, opts=self.opts))
494502
assert count == self.workfactor
495503
return self.workfactor
496504

0 commit comments

Comments
 (0)