-
Notifications
You must be signed in to change notification settings - Fork 6
Do Not Merge: Move kernel to dedicated worker #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
17bf8ef to
ed408be
Compare
c68bf18 to
c5dce79
Compare
FUDCo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not done looking at this, but after making three or four comments I realized that since it's a big PR it would be better to issue these comments as they come instead of letting the pile up.
c5dce79 to
13ccd91
Compare
FUDCo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason GitHub spontaneously put me into review mode when I tried to post an individual comment.
| case CommandMethod.LaunchVat: | ||
| await kernel | ||
| .launchVat({ | ||
| id: params, | ||
| port: command.ports[0], | ||
| }) | ||
| .then((vat) => params === defaultVatId && resolveDefaultVat(vat)); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further thought: my comments above notwithstanding, I don't think the port should be parameter to LaunchVat in this way at all. The kernel should never even see a port (quite possibly this is already on your roadmap). Instead (1) the communications pathway to the vat should already be whatever our general abstraction for a communications pathway is (a stream, I think? Or a stream pair? I'm still a little fuzzy on the unidirectional vs. bidirectional affordances of the stream abstraction), and (2) the kernel ought to be in the driver's seat, in that the invoker of LaunchVat should not be assumed to be the provider of the run-time container (iframe, process, whatever) that the vat will run in, but that should be separately provisioned for the kernel in response to a service call that the kernel makes; the entity that provides the kernel with this service should be provisioned at kernel startup time as an initialization parameter by whoever creates the kernel in the first place. This way the we decouple the Kernel class itself from the fact that in the base use case it runs in a web browser. In the standalone server use case, a vat process may get launched by an entirely different entity from the entity that launched the kernel itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with both thoughts you've laid out and hope to see the kernel there soon. I think a clean worker provisioning service falls under #99, though to the best of my knowledge it will need to implement something similar to what I have here to set up both ends of the channel. To (2), in this PR the background does not have access to launchVat, rather createVat, and the provision of the worker is handled via communications between the glue and the kernel. But this should definitely go away in the future. To (1), I think our ideal path forward involves reading and writing messages over a stream, but since we cannot pass a stream over *.postMessage or a message port over a (generic) stream I am willing to be a little in the ditch in this PR as long as we're getting closer to our destination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This PR doesn't have to be the final word. I just wanted to make sure we were pointed in the same direction, which it sounds like we are.
| const { method, params } = systemCall; | ||
| console.log('received message: ', method, params); | ||
|
|
||
| switch (method) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a good spot to point out something that's been bothering me for a while about how we have defined the various message types: I don't think we should be dispatching to reply handlers based on method, but rather on the specific request that they are the reply to, and probably used to resolve a promise from the original message send operation that issued the request in the first place.
13ccd91 to
329cfd7
Compare
| const command = port | ||
| ? { params: paramsArg, method: methodArg, ports: [port] } | ||
| : { params: paramsArg, method: methodArg }; | ||
|
|
||
| if (!isKernelCommand(command)) { | ||
| console.error('invalid command', command); | ||
| return; | ||
| } | ||
|
|
||
| const { method, params } = event.data; | ||
| console.log('received message: ', method, params); | ||
| const { method, params } = command as KernelCommand; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why build up the command object only to destructure it again 10 lines later? It seems like its only utility is to have a thing to pass to isKernelCommand, which is already a bit of a mess. At this point I don't think it adds value as a separate function in a separate module. RIght here the default case of the switch checks method and the various method cases should validate their args themselves so that all the logic w.r.t a given command is in just one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle the destructuring enforces that { method, params } is on the diagonal of the product type matrix, which makes the type inference work properly in the switch-case blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like the tail wagging the dog. Probably worth a deeper conversation.
faa3c1f to
f2ce5e6
Compare
e1256d5 to
54a0c2b
Compare
79d13d9 to
09469c3
Compare
54a0c2b to
0d2d329
Compare
09469c3 to
71fcb90
Compare
71fcb90 to
01d8684
Compare
f79d526 to
02999f3
Compare
02999f3 to
cb2391c
Compare
|
All components of this have been merged. |
Closes: #57
Refs: #80
Todo: