-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make deno multithreaded #782
Conversation
2388d35
to
18266ba
Compare
9d95bee
to
10448cd
Compare
src/isolate.rs
Outdated
pub fn event_loop(&self) { | ||
// Main thread event loop. | ||
loop { | ||
match self.rx.try_recv() { |
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 think this can go.
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 tried it.. but it fails on 001_hello.js - which is a program that doesn't send any messages. So it blocks forever trying to receive something.
loop {
let box_u8 = self.rx.recv().unwrap();
if self.state.is_idle() {
break;
} else {
// There are futures, so block main thread waiting for a new
// message (a response from a future).
self.send(box_u8);
}
}
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.
did you try:
while !self.state.is_idle() {
let box_u8 = self.rx.recv().unwrap();
self.send(box_u8);
}
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.
Thanks - that works.
07848c7
to
e036a68
Compare
src/handlers.rs
Outdated
|
||
pub extern "C" fn msg_from_js(i: *const isolate, buf: deno_buf) { | ||
let bytes = unsafe { std::slice::from_raw_parts(buf.data_ptr, buf.data_len) }; | ||
// Hopefully Rust optimizes this away. |
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.
That seems a little unlikely. If you returned an &'static Buf it probably would be. But I don't think it's all that important.
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.
Box is always 'static
. I doubt this is anything that will ever show up in a profile, I'd rather not complicate the function now without doing benchmarks.
src/isolate.rs
Outdated
pub argv: Vec<String>, | ||
pub flags: flags::DenoFlags, | ||
ntasks: Mutex<i32>, |
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 don't think the tasks count should be modified from any thread other than the main thread.
If this PR does that, I object to it: the code that calls is_idle()
cannot conceptually be made thread safe w.r.t. the ntasks counter (imagine that you call .recv()
and then another thread decrements the tasks counter - you'd have a hanging application).
So this mutex is unnecessary.
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.
Fixed in ab50c33
src/isolate.rs
Outdated
isolate.set_response(buf); | ||
} | ||
} else { | ||
// Execute op asynchornously. |
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.
"asynchronously"
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.
Fixed.
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.
See comments. Other than that, LGTM.
You should demand a test that calls Isolate dispatch : ) |
f4e2e28
to
4c5a9fd
Compare
Working around a bug that I think has been here a while, but is somehow made more promentent with denoland#782.
Working around a bug that I think has been here a while, but is somehow made more promentent with denoland#782.
Working around a bug that I think has been here a while, but is somehow made more promentent with denoland#782.
Working around a bug that I think has been here a while, but is somehow made more promentent with denoland#782.
And rename net.rs to http.rs Share HTTP connection.
By using the tokio default runtime. This patch makes all of the ops thread safe. Adds libdeno to JS globals to make for easier testing. Preliminary work for denoland#733.
To be used for a timers implementation soon.
@piscisaureus PTAL I had to disable a test in order to get this patch to pass CI. I'm not sure what exactly is going on, but it seems to be related to hyper's independent thread pool for DNS resolution. I will be replacing this thread pool and use non-blocking DNS soon - but it’s going to take a bit of development. I want to land this patch despite this regression because it will help us move forward with other development. Also - the benchmark numbers are going to be painful to look at - there is a fairly large jump in the warm startup benchmark as a result of this patch: |
- Adds deno.stdin, deno.stdout, deno.stderr, deno.open(), deno.write(), deno.read(), deno.Reader, deno.Writer, deno.copy() denoland#846 - Print 'Compiling' when compiling TS. - Support zero-copy for writeFile() writeFileSync() denoland#838 - Fixes eval error bug denoland#837 - Make Deno multithreaded denoland#782 - console.warn() goes to stderr denoland#810 - Add deno.readlink()/readlinkSync() denoland#797 - Add --recompile flag denoland#801 - Use constructor.name to print out function type denoland#664 - Rename deno.argv to deno.args - Add deno.trace() denoland#795 - Continuous benchmarks https://denoland.github.io/deno/
- Adds deno.stdin, deno.stdout, deno.stderr, deno.open(), deno.write(), deno.read(), deno.Reader, deno.Writer, deno.copy() #846 - Print 'Compiling' when compiling TS. - Support zero-copy for writeFile() writeFileSync() #838 - Fixes eval error bug #837 - Make Deno multithreaded #782 - console.warn() goes to stderr #810 - Add deno.readlink()/readlinkSync() #797 - Add --recompile flag #801 - Use constructor.name to print out function type #664 - Rename deno.argv to deno.args - Add deno.trace() #795 - Continuous benchmarks https://denoland.github.io/deno/
V8 uses the default context for internal things https://chromium.googlesource.com/v8/v8/+/refs/heads/main/src/inspector/v8-inspector-impl.cc#356 With this PR, deno_core will create a new default context during snapshot and add deno_core's context separately (as the last context of the snapshot) Ref denoland#24204 Fixes denoland#24196
No description provided.