git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e08047273f81b45b7107bc0bc4fa2557d9f79eb0

added chunking

wanderer committed on 7/27/2017, 3:48:46 AM
Parent: 6723a3ab125343529593a107313cd31c8eb38d7a

Files changed

index.jschanged
kernel.jschanged
package.jsonchanged
index.jsView
@@ -2,8 +2,10 @@
22 const Message = require('primea-message')
33 const Kernel = require('./kernel.js')
44 const Scheduler = require('./scheduler.js')
55 const DFSchecker = require('./dfsChecker.js')
6+const chunk = require('chunk')
7+const flatten = require('flatten')
68
79 const ROOT_ID = 'zdpuAm6aTdLVMUuiZypxkwtA7sKm7BWERy8MPbaCrFsmiyzxr'
810
911 module.exports = class Hypervisor {
@@ -18,8 +20,10 @@
1820 this.scheduler = new Scheduler()
1921 this.state = state
2022 this._containerTypes = {}
2123 this._nodesToCheck = new Set()
24+
25+ this.MAX_DATA_BYTES = 6553
2226 }
2327
2428 /**
2529 * add a potaintail node in the state graph to check for garbage collection
@@ -57,8 +61,12 @@
5761 async _loadInstance (id) {
5862 const state = await this.graph.get(this.state, id)
5963 const container = this._containerTypes[state.type]
6064
65+ // if (state.code && Array.isArray(state.code[0])) {
66+ // state.code = flatten(state.code)
67+ // }
68+
6169 // create a new kernel instance
6270 const kernel = new Kernel({
6371 hypervisor: this,
6472 state: state,
@@ -122,8 +130,18 @@
122130 resolve(instance)
123131 // send the intialization message
124132 await instance.initialize(message)
125133
134+ if (state.code && state.code.length > this.MAX_DATA_BYTES) {
135+ state.code = chunk(state.code, this.MAX_DATA_BYTES).map(chk => {
136+ return {
137+ '/': chk
138+ }
139+ })
140+ } else {
141+ console.log(state.code)
142+ }
143+
126144 return instance
127145 }
128146
129147 /**
@@ -137,8 +155,9 @@
137155 const unlinked = await DFSchecker(this.graph, this.state, ROOT_ID, this._nodesToCheck)
138156 unlinked.forEach(id => {
139157 delete this.state[id]
140158 })
159+ console.log(this.state)
141160 return this.graph.flush(this.state)
142161 }
143162
144163 /**
kernel.jsView
@@ -72,8 +72,11 @@
7272 }
7373
7474 shutdown () {
7575 this.hypervisor.scheduler.done(this.id)
76+ if (this.container.shutdown) {
77+ this.container.shutdown()
78+ }
7679 }
7780
7881 /**
7982 * run the kernels code with a given enviroment
package.jsonView
@@ -31,8 +31,10 @@
3131 "license": "MPL-2.0",
3232 "dependencies": {
3333 "binary-search-insert": "^1.0.3",
3434 "bn.js": "^4.11.6",
35+ "chunk": "0.0.2",
36+ "flatten": "^1.0.2",
3537 "ipld-graph-builder": "1.2.2",
3638 "primea-abstract-container": "0.0.1",
3739 "primea-message": "0.0.1"
3840 },

Built with git-ssb-web