Commit d0a5ea25b9d19aad6f2be59441be57da023c9c70
make shutdown sync
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 4/14/2018, 7:02:15 PM
Parent: 1cb8325aadecdc8aed5d21bf203f529a4879d5b8
Files changed
actor.js | changed |
benchmark/index.js | changed |
egressDriver.js | changed |
index.js | changed |
package-lock.json | changed |
package.json | changed |
scheduler.js | changed |
tests/index.js | changed |
actor.js | ||
---|---|---|
@@ -27,12 +27,12 @@ | ||
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Runs the shutdown routine for the actor |
30 | 30 | */ |
31 | - async shutdown () { | |
32 | - await this.tree.set(this.id.id, [this.type, this.nonce]) | |
33 | - const state = await this.tree.get(this.id.id) | |
34 | - return this.tree.graph.set(state.root, '2', this.storage) | |
31 | + shutdown () { | |
32 | + // saves the nonce and storage to the state | |
33 | + this.state.value[1] = this.nonce | |
34 | + this.state.node[2] = {'/': this.storage} | |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Runs the startup routine for the actor |
benchmark/index.js | ||
---|---|---|
@@ -25,17 +25,18 @@ | ||
25 | 25 | } |
26 | 26 | } |
27 | 27 | |
28 | 28 | async function main (numOfActors, depth) { |
29 | - // const messageOrder = {} | |
29 | + const tree = new RadixTree({ | |
30 | + db | |
31 | + }) | |
32 | + | |
30 | 33 | let numOfMsg = 0 |
34 | + | |
31 | 35 | class BenchmarkContainer extends BaseContainer { |
32 | 36 | main () { |
33 | 37 | const refs = [...arguments] |
34 | 38 | const ref = refs.pop() |
35 | - // const last = messageOrder[this.actor.id.toString('hex')] | |
36 | - // const message = this.actor.currentMessage | |
37 | - // messageOrder[this.actor.id.toString('hex')] = message._fromTicks | |
38 | 39 | numOfMsg++ |
39 | 40 | this.actor.incrementTicks(10) |
40 | 41 | if (ref) { |
41 | 42 | this.actor.send(new Message({ |
@@ -44,22 +45,19 @@ | ||
44 | 45 | })) |
45 | 46 | } |
46 | 47 | } |
47 | 48 | } |
48 | - const tree = new RadixTree({ | |
49 | - db: db | |
50 | - }) | |
51 | 49 | |
52 | - const hypervisor = new Hypervisor(tree) | |
50 | + const hypervisor = new Hypervisor({tree}) | |
53 | 51 | hypervisor.registerContainer(BenchmarkContainer) |
54 | 52 | |
55 | 53 | const refernces = [] |
56 | 54 | let _numOfActors = numOfActors |
57 | 55 | while (_numOfActors--) { |
58 | - const { | |
59 | - module | |
60 | - } = hypervisor.createActor(BenchmarkContainer.typeId) | |
61 | - refernces.push(module.getFuncRef('main')) | |
56 | + const {module} = hypervisor.createActor(BenchmarkContainer.typeId) | |
57 | + const funcRef = module.getFuncRef('main') | |
58 | + funcRef.gas = 1000 | |
59 | + refernces.push(funcRef) | |
62 | 60 | } |
63 | 61 | _numOfActors = numOfActors |
64 | 62 | let msgs = [] |
65 | 63 | while (_numOfActors--) { |
@@ -75,9 +73,8 @@ | ||
75 | 73 | funcRef: refernces[_numOfActors] |
76 | 74 | }) |
77 | 75 | msgs.push(message) |
78 | 76 | } |
79 | - | |
80 | 77 | let start = new Date() |
81 | 78 | hypervisor.send(msgs) |
82 | 79 | await hypervisor.scheduler.on('idle', () => { |
83 | 80 | const end = new Date() - start |
egressDriver.js | ||
---|---|---|
@@ -6,8 +6,10 @@ | ||
6 | 6 | super() |
7 | 7 | this.id = new ID(Buffer.from([0])) |
8 | 8 | } |
9 | 9 | |
10 | + startup () {} | |
11 | + | |
10 | 12 | runMessage (message) { |
11 | 13 | this.emit('message', message) |
12 | 14 | } |
13 | 15 | } |
index.js | ||
---|---|---|
@@ -146,8 +146,9 @@ | ||
146 | 146 | * register a driver with the hypervisor |
147 | 147 | * @param {driver} driver |
148 | 148 | */ |
149 | 149 | registerDriver (driver) { |
150 | + driver.startup(this) | |
150 | 151 | this.scheduler.drivers.set(driver.id.toString(), driver) |
151 | 152 | } |
152 | 153 | } |
153 | 154 |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 365133 bytes New file size: 365090 bytes |
package.json | ||
---|---|---|
@@ -36,9 +36,9 @@ | ||
36 | 36 | "safe-buffer": "^5.1.1" |
37 | 37 | }, |
38 | 38 | "devDependencies": { |
39 | 39 | "coveralls": "^3.0.0", |
40 | - "dfinity-radix-tree": "^0.2.1", | |
40 | + "dfinity-radix-tree": "^0.2.2", | |
41 | 41 | "documentation": "^6.0.0", |
42 | 42 | "level-browserify": "^1.1.2", |
43 | 43 | "nyc": "^11.6.0", |
44 | 44 | "standard": "11.0.1", |
scheduler.js | ||
---|---|---|
@@ -39,11 +39,9 @@ | ||
39 | 39 | const message = this._messages.shift() |
40 | 40 | await this._processMessage(message) |
41 | 41 | } |
42 | 42 | this._running = false |
43 | - const promises = [] | |
44 | - this.actors.forEach(actor => promises.push(actor.shutdown())) | |
45 | - await Promise.all(promises) | |
43 | + this.actors.forEach(actor => actor.shutdown()) | |
46 | 44 | this.actors.clear() |
47 | 45 | this.emit('idle') |
48 | 46 | } |
49 | 47 |
Built with git-ssb-web