git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit acd65bd28b852ab061aad493bc85901d386b2b9b

update benchmark

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 3/24/2018, 10:18:13 PM
Parent: 72a22f7318aa0ad186ba6c2b134f0d45a091a18d

Files changed

benchmark/index.jschanged
systemObjects.jschanged
benchmark/index.jsView
@@ -3,60 +3,50 @@
33
44 const level = require('level-browserify')
55 const RadixTree = require('dfinity-radix-tree')
66 const db = level('./testdb')
7+const {ModuleRef} = require('../systemObjects')
78
8-let numOfMsg = 0
9-const messageOrder = {}
10-
11-class BenchmarkContainer {
12- static validate () {}
13- static compile () {}
14- static get typeId () {
15- return 9
9+class BaseContainer {
10+ constructor (actor) {
11+ this.actor = actor
1612 }
17-
18- static exports (m, id) {
19- return Object.keys(this.functions()).map(name => {
20- return {
21- name,
22- destId: id
23- }
13+ onStartup () {}
14+ static onCreation (code, id) {
15+ const exp = {}
16+ Object.getOwnPropertyNames(this.prototype).filter(name => name !== 'constructor').forEach(name => {
17+ exp[name] = {}
2418 })
19+ return new ModuleRef(exp, id)
2520 }
26- static instance (actor) {
27- return {
28- exports: this.functions(actor)
29- }
21+ onMessage (message) {
22+ return this[message.funcRef.identifier[1]](...message.funcArguments)
3023 }
31- static functions (actor) {
32- return {
33- onMessage: function () {
34- const refs = [...arguments]
35- const ref = refs.pop()
36- // console.log('run queue', this.actor.inbox._queue)
37- // console.log('from', message._fromId.toString('hex'), 'to: ', this.actor.id.toString('hex'), this.actor.ticks, message._fromTicks)
38- // const last = messageOrder[actor.id.toString('hex')]
39- // const message = actor.currentMessage
40- // if (last && last > message._fromTicks) {
41- // console.log(last, message._fromTicks)
42- // // console.log(this.actor.hypervisor.scheduler.instances)
43- // }
44- // messageOrder[actor.id.toString('hex')] = message._fromTicks
45- numOfMsg++
46- actor.incrementTicks(10)
47- if (ref) {
48- return actor.send(new Message({
49- funcRef: ref,
50- funcArguments: refs
51- }))
52- }
53- }
54- }
24+ static get typeId () {
25+ return 9
5526 }
5627 }
5728
5829 async function main (numOfActors, depth) {
30+ // const messageOrder = {}
31+ let numOfMsg = 0
32+ class BenchmarkContainer extends BaseContainer {
33+ main () {
34+ const refs = [...arguments]
35+ const ref = refs.pop()
36+ // const last = messageOrder[this.actor.id.toString('hex')]
37+ // const message = this.actor.currentMessage
38+ // messageOrder[this.actor.id.toString('hex')] = message._fromTicks
39+ numOfMsg++
40+ this.actor.incrementTicks(10)
41+ if (ref) {
42+ this.actor.send(new Message({
43+ funcRef: ref,
44+ funcArguments: refs
45+ }))
46+ }
47+ }
48+ }
5949 const tree = new RadixTree({
6050 db: db
6151 })
6252
@@ -65,12 +55,13 @@
6555
6656 const refernces = []
6757 let _numOfActors = numOfActors
6858 while (_numOfActors--) {
69- const {exports} = await hypervisor.createActor(BenchmarkContainer.typeId)
70- refernces.push(exports[0])
59+ const {
60+ module
61+ } = hypervisor.createActor(BenchmarkContainer.typeId)
62+ refernces.push(module.getFuncRef('main'))
7163 }
72- // console.log(refernces)
7364 _numOfActors = numOfActors
7465 let msgs = []
7566 while (_numOfActors--) {
7667 let _depth = depth
@@ -87,11 +78,10 @@
8778 msgs.push(message)
8879 }
8980
9081 let start = new Date()
91- await Promise.all(msgs.map((msg) => hypervisor.send(msg)))
92- console.log('done sending')
93- hypervisor.scheduler.on('idle', () => {
82+ hypervisor.send(msgs)
83+ await hypervisor.scheduler.on('idle', () => {
9484 const end = new Date() - start
9585 console.info('Execution time: %dms', end)
9686 console.log('messages processed', numOfActors * depth + numOfActors)
9787 console.log('messages processed', numOfMsg)
systemObjects.jsView
@@ -58,11 +58,13 @@
5858 this.id = id
5959 }
6060
6161 getFuncRef (name) {
62+ const params = this.exports[name]
63+
6264 return new FunctionRef({
6365 identifier: [false, name],
64- params: this.exports[name],
66+ params,
6567 id: this.id
6668 })
6769 }
6870

Built with git-ssb-web