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.js | changed |
systemObjects.js | changed |
benchmark/index.js | ||
---|---|---|
@@ -3,60 +3,50 @@ | ||
3 | 3 | |
4 | 4 | const level = require('level-browserify') |
5 | 5 | const RadixTree = require('dfinity-radix-tree') |
6 | 6 | const db = level('./testdb') |
7 | +const {ModuleRef} = require('../systemObjects') | |
7 | 8 | |
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 | |
16 | 12 | } |
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] = {} | |
24 | 18 | }) |
19 | + return new ModuleRef(exp, id) | |
25 | 20 | } |
26 | - static instance (actor) { | |
27 | - return { | |
28 | - exports: this.functions(actor) | |
29 | - } | |
21 | + onMessage (message) { | |
22 | + return this[message.funcRef.identifier[1]](...message.funcArguments) | |
30 | 23 | } |
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 | |
55 | 26 | } |
56 | 27 | } |
57 | 28 | |
58 | 29 | 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 | + } | |
59 | 49 | const tree = new RadixTree({ |
60 | 50 | db: db |
61 | 51 | }) |
62 | 52 | |
@@ -65,12 +55,13 @@ | ||
65 | 55 | |
66 | 56 | const refernces = [] |
67 | 57 | let _numOfActors = numOfActors |
68 | 58 | 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')) | |
71 | 63 | } |
72 | - // console.log(refernces) | |
73 | 64 | _numOfActors = numOfActors |
74 | 65 | let msgs = [] |
75 | 66 | while (_numOfActors--) { |
76 | 67 | let _depth = depth |
@@ -87,11 +78,10 @@ | ||
87 | 78 | msgs.push(message) |
88 | 79 | } |
89 | 80 | |
90 | 81 | 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', () => { | |
94 | 84 | const end = new Date() - start |
95 | 85 | console.info('Execution time: %dms', end) |
96 | 86 | console.log('messages processed', numOfActors * depth + numOfActors) |
97 | 87 | console.log('messages processed', numOfMsg) |
Built with git-ssb-web