Skip to content
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

script: Make the resource task communication use IPC channels. #6586

Merged
merged 5 commits into from Jul 31, 2015

Conversation

@pcwalton
Copy link
Contributor

pcwalton commented Jul 10, 2015

This change makes Servo use serialized messages over IPC channels for resource loading. The goal is to make it easier to make Servo multiprocess in the future. This patch does not make Servo multiprocess now; there are many other channels that need to be changed to IPC before that can happen. It does introduce a dependency on https://github.com/serde-rs/serde and https://github.com/pcwalton/ipc-channel for the first time.

At the moment, ipc-channel uses JSON for serialization. This is because serde does not yet have official support for bincode. When serde gains support for bincode, I'll switch to that. For now, however, the JSON encoding and decoding will constitute a significant performance regression in resource loading.

To avoid having to send boxed AsyncResponseTarget trait objects across process boundaries, this series of commits changes AsyncResponseTarget to wrap a sender only. It is then the client's responsibility to spawn a thread to proxy calls from that sender to the consumer of the resource data. This only had to be done in a few places. In the future, we may want to collapse those threads into one per process to reduce overhead. (It is impossible to continue to use AsyncResponseTarget as a boxed trait object across processes, regardless of how much work is done on ipc-channel. Vtables are fundamentally incompatible with IPC across mutually untrusting processes.)

In general, I was pretty pleased with how this turned out. The main changes are adding serialization functionality to various objects that serde does not know how to serialize natively—the most complicated being Hyper objects—and reworking AsyncResponseTarget. The overall structure of the code is unchanged, and other than AsyncResponseTarget no functionality was lost in moving to serialization and IPC.

r? @jdm

Review on Reviewable

@hoppipolla-critic-bot
Copy link

hoppipolla-critic-bot commented Jul 10, 2015

Critic review: https://critic.hoppipolla.co.uk/r/5505

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@Ms2ger
Copy link
Contributor

Ms2ger commented Jul 10, 2015

I'm not so happy about the SerializableFoo wrapper structs; can we avoid those somehow?

@pcwalton pcwalton closed this Jul 10, 2015
@pcwalton pcwalton reopened this Jul 10, 2015
@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 10, 2015

Only by making our upstream crates take hard dependencies on serde, which I didn't want to do since serde is pretty immature still.

@Ms2ger
Copy link
Contributor

Ms2ger commented Jul 10, 2015

Cargo features?

@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 10, 2015

@jdm @Ms2ger I have redone this PR to remove all serializable wrappers. This PR now depends on the following upstream PRs:

@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 11, 2015

Everything has gone upstream now except the serde change.

However, we can't take the hyper upgrade yet until the rustup lands, because of an ICE. That rustup is itself blocked on mysterious linker errors. We could also fork hyper and backport the change to get ourselves out of this mess.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 14, 2015

The latest upstream changes (presumably #6614) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Jul 14, 2015

-S-awaiting-review +S-needs-code-changes
There will also need to be changes in the other Cargo.lock files.


Reviewed 2 of 20 files at r1, 1 of 10 files at r2, 4 of 17 files at r3, 21 of 29 files at r5, 8 of 8 files at r6.
Review status: all files reviewed at latest revision, 17 unresolved discussions, some commit checks failed.


components/devtools_traits/Cargo.toml, line 22 [r6] (raw file):
Nope.


components/net/data_loader.rs, line 33 [r6] (raw file):
This change doesn't look necessary.


components/net/http_loader.rs, line 366 [r6] (raw file):
These changes aren't necessary, right?


components/net/http_loader.rs, line 379 [r6] (raw file):
Revert.


components/net/image_cache_task.rs, line 108 [r6] (raw file):
Let's make this an unwrap until we know how to handle an error.


components/net/image_cache_task.rs, line 257 [r6] (raw file):
Revert.


components/net/image_cache_task.rs, line 343 [r6] (raw file):
nit: move the AsyncResponseTarget creation into a separate binding.


components/net/image_cache_task.rs, line 346 [r6] (raw file):
Add a TODO to create a single thread to be shared by all IPC network listeners for a given script task.


components/net/resource_task.rs, line 282 [r6] (raw file):
Revert.


components/net_traits/lib.rs, line 34 [r6] (raw file):
Unused, right?


components/script/Cargo.toml, line 68 [r6] (raw file):
I don't recall seeing a PR for this.


components/script/dom/htmlscriptelement.rs, line 343 [r6] (raw file):
Add a TODO about sharing an IPC thread with the other network listeners for this script task.


components/script/dom/xmlhttprequest.rs, line 283 [r6] (raw file):
Add a TODO about sharing an IPC thread with the other network listeners for this script task.


components/script/dom/xmlhttprequest.rs, line 798 [r6] (raw file):
nit: four space indent.


components/script/network_listener.rs, line 20 [r6] (raw file):
Unwrap until we know how to handle an error properly.


components/script/script_task.rs, line 1523 [r6] (raw file):
Add a TODO to share this with the other network listeners for this script task.


components/util/Cargo.toml, line 25 [r6] (raw file):
Um.


Comments from the review on Reviewable.io

@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 14, 2015

components/util/Cargo.toml, line 25 [r6] (raw file):
Yeah, I had to do that because there's no way to use a Cargo override to pick up a new Cargo feature. It was the only way to get things building locally before the rust-url changes landed.


Comments from the review on Reviewable.io

@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 14, 2015

Review status: all files reviewed at latest revision, 17 unresolved discussions, some commit checks failed.


components/net/data_loader.rs, line 33 [r6] (raw file):
I think it was reverted in a later PR, so will be fixed by the squash.


components/net/image_cache_task.rs, line 108 [r6] (raw file):
Won't that cause shutdown panics? There's no other way to shut down the ResourceListener otherwise.


components/script/network_listener.rs, line 20 [r6] (raw file):
Worried about shutdown panics here, as above.


Comments from the review on Reviewable.io

@pcwalton pcwalton force-pushed the pcwalton:resource-task-ipc branch from e12b2c9 to 17c370b Jul 14, 2015
@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 14, 2015

Addressed the review comments. r? @jdm

@jdm
Copy link
Member

jdm commented Jul 14, 2015

-S-awaiting-review +S-needs-code-changes


Reviewed 1 of 20 files at r1, 31 of 31 files at r7.
Review status: all files reviewed at latest revision, 5 unresolved discussions, all commit checks successful.


components/net/data_loader.rs, line 33 [r6] (raw file):
I don't recall seeing that...


components/servo/Cargo.lock, line 1464 [r7] (raw file):
Let's not regress the version.


ports/cef/Cargo.lock, line 1116 [r7] (raw file):
Oh?


ports/cef/Cargo.lock, line 1411 [r7] (raw file):
Uh...


ports/gonk/Cargo.lock, line 1300 [r7] (raw file):
Eeep.


Comments from the review on Reviewable.io

@pcwalton pcwalton force-pushed the pcwalton:resource-task-ipc branch from 17c370b to 8ca0de1 Jul 14, 2015
@pcwalton pcwalton force-pushed the pcwalton:resource-task-ipc branch from 8ca0de1 to 8667004 Jul 14, 2015
@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 14, 2015

Review status: 31 of 35 files reviewed at latest revision, 5 unresolved discussions, all commit checks successful.


ports/cef/Cargo.lock, line 1116 [r7] (raw file):
What's wrong with this?


ports/cef/Cargo.lock, line 1411 [r7] (raw file):
I think the mismatched version numbers are an upstream serde problem. mach update-cargo -p serde && mach update-cargo -p serde-macros didn't fix it. Do you want me to hold the PR on getting a fix for this upstream?


Comments from the review on Reviewable.io

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2015

The latest upstream changes (presumably #6618) made this pull request unmergeable. Please resolve the merge conflicts.

@pcwalton pcwalton force-pushed the pcwalton:resource-task-ipc branch from 8667004 to 097624d Jul 15, 2015
@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2015

The latest upstream changes (presumably #6591) made this pull request unmergeable. Please resolve the merge conflicts.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

📌 Commit 7cdd779 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

Testing commit 7cdd779 with merge 93c4769...

bors-servo pushed a commit that referenced this pull request Jul 31, 2015
script: Make the resource task communication use IPC channels.

This change makes Servo use serialized messages over IPC channels for resource loading. The goal is to make it easier to make Servo multiprocess in the future. This patch does not make Servo multiprocess now; there are many other channels that need to be changed to IPC before that can happen. It does introduce a dependency on https://github.com/serde-rs/serde and https://github.com/pcwalton/ipc-channel for the first time.

At the moment, `ipc-channel` uses JSON for serialization. This is because serde does not yet have official support for bincode. When serde gains support for bincode, I'll switch to that. For now, however, the JSON encoding and decoding will constitute a significant performance regression in resource loading.

To avoid having to send boxed `AsyncResponseTarget` trait objects across process boundaries, this series of commits changes `AsyncResponseTarget` to wrap a sender only. It is then the client's responsibility to spawn a thread to proxy calls from that sender to the consumer of the resource data. This only had to be done in a few places. In the future, we may want to collapse those threads into one per process to reduce overhead. (It is impossible to continue to use `AsyncResponseTarget` as a boxed trait object across processes, regardless of how much work is done on `ipc-channel`. Vtables are fundamentally incompatible with IPC across mutually untrusting processes.)

In general, I was pretty pleased with how this turned out. The main changes are adding serialization functionality to various objects that `serde` does not know how to serialize natively—the most complicated being Hyper objects—and reworking `AsyncResponseTarget`. The overall structure of the code is unchanged, and other than `AsyncResponseTarget` no functionality was lost in moving to serialization and IPC.

r? @jdm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6586)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

💔 Test failed - linux2

@jdm
Copy link
Member

jdm commented Jul 31, 2015

/XMLHttpRequest/send-non-same-origin.sub.htm
--------------------------------------------
CRASH [Parent]
/dom/ranges/Range-mutations.html
--------------------------------
TIMEOUT [Parent]
@jdm
Copy link
Member

jdm commented Jul 31, 2015

 2:09.94 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) Full command: /home/servo/buildbot/slave/linux2/build/target/release/servo --cpu --hard-fail -u Servo/wptrunner -z http://localhost:8000/XMLHttpRequest/send-non-same-origin.sub.htm
(pid:7606) "Io(Error { repr: Custom(Custom { kind: Other, error: StringError("failed to lookup address information: Name or service not known") }) })"
 2:09.94 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: ()', src/libcore/result.rs:732"
 2:09.94 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "stack backtrace:"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   1:     0x7fddedaab6ce - sys::backtrace::write::h4461ce907fdef7c9Cys"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   2:     0x7fddedaaf0c2 - panicking::on_panic::hbb749401295aefc5Lnx"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   3:     0x7fddeda9b7ae - rt::unwind::begin_unwind_inner::hb561d488e4095b19o3w"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   4:     0x7fddeda9c205 - rt::unwind::begin_unwind_fmt::hcfdd98fa08198219u2w"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   5:     0x7fddedaaea96 - rust_begin_unwind"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   6:     0x7fddedae0484 - panicking::panic_fmt::h18e94a0fe8bc1992MhC"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   7:     0x7fddecee3255 - dom::xmlhttprequest::XMLHttpRequest::initiate_async_xhr::closure.130037"
 2:10.16 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   8:     0x7fdded7c1287 - router::RouterProxy::new::closure.14751"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "   9:     0x7fdded7c01c2 - boxed::F.FnBox<A>::call_box::h11566258001495260212"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  10:     0x7fdded7bfab9 - rt::unwind::try::try_fn::h587882849811351653"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  11:     0x7fddedaae9bf - __rust_try_inner"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  12:     0x7fddedaae9fa - __rust_try"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  13:     0x7fddedaa9267 - rt::unwind::try::inner_try::h2721e05d3675a507hZw"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  14:     0x7fdded7bfcce - boxed::F.FnBox<A>::call_box::h5587116118343096823"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  15:     0x7fddedaadb71 - sys::thread::Thread::new::thread_start::h3e0fc9f59f3e6025X8v"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  16:     0x7fddeb64d181 - start_thread"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  17:     0x7fdde9b2947c - __clone"
 2:10.17 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:7606) "  18:                0x0 - <unknown>"
@jdm
Copy link
Member

jdm commented Jul 31, 2015

@jdm
Copy link
Member

jdm commented Jul 31, 2015

5:08.70 TEST_START: Thread-TestrunnerManager-4 /dom/ranges/Range-mutations.html
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) Full command: /home/servo/buildbot/slave/linux2/build/target/release/servo --cpu --hard-fail -u Servo/wptrunner -z http://localhost:8000/dom/ranges/Range-mutations.html
(pid:21779) "thread 'FontCacheTask' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 24, message: "Too many open files" } }', src/libcore/result.rs:732"
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "stack backtrace:"
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   1:     0x7fa61f4816ce - <unknown>"
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   2:     0x7fa61f4850c2 - <unknown>"
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   3:     0x7fa61f4717ae - <unknown>"
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   4:     0x7fa61f472205 - <unknown>"
 5:12.47 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   5:     0x7fa61f484a96 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   6:     0x7fa61f4b6484 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   7:     0x7fa61e488ae6 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   8:     0x7fa61e488d57 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "   9:     0x7fa61e471351 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  10:     0x7fa61e47f93d - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  11:     0x7fa61e475a5c - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  12:     0x7fa61e481ea1 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  13:     0x7fa61e4576d9 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  14:     0x7fa61f4849bf - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  15:     0x7fa61f4849fa - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  16:     0x7fa61f47f267 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  17:     0x7fa61e4578ee - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  18:     0x7fa61f483b71 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  19:     0x7fa61d023181 - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  20:     0x7fa61b4ff47c - <unknown>"
 5:12.48 PROCESS_OUTPUT: Thread-TestrunnerManager-4 (pid:21779) "  21:                0x0 - <unknown>"
@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

The latest upstream changes (presumably #6795) made this pull request unmergeable. Please resolve the merge conflicts.

@pcwalton pcwalton force-pushed the pcwalton:resource-task-ipc branch from 7cdd779 to 1a26ebe Jul 31, 2015
@pcwalton pcwalton force-pushed the pcwalton:resource-task-ipc branch from 1a26ebe to 61e3a95 Jul 31, 2015
@pcwalton
Copy link
Contributor Author

pcwalton commented Jul 31, 2015

@bors-servo: r=jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

📌 Commit 61e3a95 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

Testing commit 61e3a95 with merge 2eb122f...

bors-servo pushed a commit that referenced this pull request Jul 31, 2015
script: Make the resource task communication use IPC channels.

This change makes Servo use serialized messages over IPC channels for resource loading. The goal is to make it easier to make Servo multiprocess in the future. This patch does not make Servo multiprocess now; there are many other channels that need to be changed to IPC before that can happen. It does introduce a dependency on https://github.com/serde-rs/serde and https://github.com/pcwalton/ipc-channel for the first time.

At the moment, `ipc-channel` uses JSON for serialization. This is because serde does not yet have official support for bincode. When serde gains support for bincode, I'll switch to that. For now, however, the JSON encoding and decoding will constitute a significant performance regression in resource loading.

To avoid having to send boxed `AsyncResponseTarget` trait objects across process boundaries, this series of commits changes `AsyncResponseTarget` to wrap a sender only. It is then the client's responsibility to spawn a thread to proxy calls from that sender to the consumer of the resource data. This only had to be done in a few places. In the future, we may want to collapse those threads into one per process to reduce overhead. (It is impossible to continue to use `AsyncResponseTarget` as a boxed trait object across processes, regardless of how much work is done on `ipc-channel`. Vtables are fundamentally incompatible with IPC across mutually untrusting processes.)

In general, I was pretty pleased with how this turned out. The main changes are adding serialization functionality to various objects that `serde` does not know how to serialize natively—the most complicated being Hyper objects—and reworking `AsyncResponseTarget`. The overall structure of the code is unchanged, and other than `AsyncResponseTarget` no functionality was lost in moving to serialization and IPC.

r? @jdm

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6586)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 31, 2015

☀️ Test successful - android, gonk, linux1, linux2, linux3, mac1, mac2, mac3

@bors-servo bors-servo merged commit 61e3a95 into servo:master Jul 31, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.