git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e47dbb585f72b65914431ec10f554e43226dc121

make schedular faster

wanderer committed on 12/12/2017, 10:02:38 PM
Parent: 9a207a1ce69e564a67b6833876ce76b4f3258efa

Files changed

actor.jschanged
inbox.jschanged
scheduler.jschanged
actor.jsView
@@ -74,8 +74,9 @@
7474 // run the next message
7575 await this.runMessage(message)
7676 // wait for state ops to finish
7777 await this.state.done()
78+ await Promise.all([...this._sending.values()])
7879 }
7980
8081 this.running = false
8182 this.container.onIdle()
inbox.jsView
@@ -72,19 +72,20 @@
7272 */
7373 nextMessage (timeout, getCurrent = false) {
7474 if (!this._gettingNextMessage) {
7575 this._gettingNextMessage = this._nextMessage(timeout)
76+ this._gettingNextMessage.then(() => {
77+ this._gettingNextMessage = false
78+ })
7679 } else if (!getCurrent) {
7780 throw new Error('already waiting for next message')
7881 }
7982 return this._gettingNextMessage
8083 }
8184
8285 async _nextMessage (timeout) {
83- await Promise.all([...this.actor._sending.values()])
8486 let message = this._getOldestMessage()
8587 if (message === undefined && timeout === 0) {
86- this._gettingNextMessage = false
8788 return
8889 }
8990
9091 timeout += this.actor.ticks
@@ -121,9 +122,8 @@
121122 })
122123 ])
123124 oldestTime = this.hypervisor.scheduler.leastNumberOfTicks(this.actor.id)
124125 }
125- this._gettingNextMessage = false
126126 return this._deQueueMessage()
127127 }
128128
129129 // returns a promise that resolve when a message older then the given message
scheduler.jsView
@@ -24,8 +24,12 @@
2424 * @param {string} id
2525 * @return {function} the resolve function to call once it to unlock
2626 */
2727 lock (id) {
28+ this.instances.set(id, {
29+ ticks: 0
30+ })
31+ this._running.add(id)
2832 return this._loadingInstances.lock(id)
2933 }
3034
3135 /**
@@ -49,9 +53,9 @@
4953 * @param {String} id
5054 * @return {Object}
5155 */
5256 getInstance (id) {
53- return this.instances.get(id) || this._loadingInstances.get(id)
57+ return this._loadingInstances.get(id) || this.instances.get(id)
5458 }
5559
5660 /**
5761 * deletes an instance from the scheduler
@@ -105,11 +109,8 @@
105109 return
106110 }
107111 this._checkingWaits = true
108112
109- // wait to check waits until all the instances are done loading
110- await [...this._loadingInstances.values()]
111-
112113 // if there are no instances, clear any remaining waits
113114 if (!this.instances.size) {
114115 this._waits.forEach(wait => wait.resolve())
115116 this._waits = []

Built with git-ssb-web