Commit e47dbb585f72b65914431ec10f554e43226dc121
make schedular faster
wanderer committed on 12/12/2017, 10:02:38 PMParent: 9a207a1ce69e564a67b6833876ce76b4f3258efa
Files changed
actor.js | changed |
inbox.js | changed |
scheduler.js | changed |
actor.js | ||
---|---|---|
@@ -74,8 +74,9 @@ | ||
74 | 74 | // run the next message |
75 | 75 | await this.runMessage(message) |
76 | 76 | // wait for state ops to finish |
77 | 77 | await this.state.done() |
78 | + await Promise.all([...this._sending.values()]) | |
78 | 79 | } |
79 | 80 | |
80 | 81 | this.running = false |
81 | 82 | this.container.onIdle() |
inbox.js | ||
---|---|---|
@@ -72,19 +72,20 @@ | ||
72 | 72 | */ |
73 | 73 | nextMessage (timeout, getCurrent = false) { |
74 | 74 | if (!this._gettingNextMessage) { |
75 | 75 | this._gettingNextMessage = this._nextMessage(timeout) |
76 | + this._gettingNextMessage.then(() => { | |
77 | + this._gettingNextMessage = false | |
78 | + }) | |
76 | 79 | } else if (!getCurrent) { |
77 | 80 | throw new Error('already waiting for next message') |
78 | 81 | } |
79 | 82 | return this._gettingNextMessage |
80 | 83 | } |
81 | 84 | |
82 | 85 | async _nextMessage (timeout) { |
83 | - await Promise.all([...this.actor._sending.values()]) | |
84 | 86 | let message = this._getOldestMessage() |
85 | 87 | if (message === undefined && timeout === 0) { |
86 | - this._gettingNextMessage = false | |
87 | 88 | return |
88 | 89 | } |
89 | 90 | |
90 | 91 | timeout += this.actor.ticks |
@@ -121,9 +122,8 @@ | ||
121 | 122 | }) |
122 | 123 | ]) |
123 | 124 | oldestTime = this.hypervisor.scheduler.leastNumberOfTicks(this.actor.id) |
124 | 125 | } |
125 | - this._gettingNextMessage = false | |
126 | 126 | return this._deQueueMessage() |
127 | 127 | } |
128 | 128 | |
129 | 129 | // returns a promise that resolve when a message older then the given message |
scheduler.js | ||
---|---|---|
@@ -24,8 +24,12 @@ | ||
24 | 24 | * @param {string} id |
25 | 25 | * @return {function} the resolve function to call once it to unlock |
26 | 26 | */ |
27 | 27 | lock (id) { |
28 | + this.instances.set(id, { | |
29 | + ticks: 0 | |
30 | + }) | |
31 | + this._running.add(id) | |
28 | 32 | return this._loadingInstances.lock(id) |
29 | 33 | } |
30 | 34 | |
31 | 35 | /** |
@@ -49,9 +53,9 @@ | ||
49 | 53 | * @param {String} id |
50 | 54 | * @return {Object} |
51 | 55 | */ |
52 | 56 | getInstance (id) { |
53 | - return this.instances.get(id) || this._loadingInstances.get(id) | |
57 | + return this._loadingInstances.get(id) || this.instances.get(id) | |
54 | 58 | } |
55 | 59 | |
56 | 60 | /** |
57 | 61 | * deletes an instance from the scheduler |
@@ -105,11 +109,8 @@ | ||
105 | 109 | return |
106 | 110 | } |
107 | 111 | this._checkingWaits = true |
108 | 112 | |
109 | - // wait to check waits until all the instances are done loading | |
110 | - await [...this._loadingInstances.values()] | |
111 | - | |
112 | 113 | // if there are no instances, clear any remaining waits |
113 | 114 | if (!this.instances.size) { |
114 | 115 | this._waits.forEach(wait => wait.resolve()) |
115 | 116 | this._waits = [] |
Built with git-ssb-web