aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-04-19 15:48:56 -0400
committerGitHub <noreply@github.com>2019-04-19 15:48:56 -0400
commitc449cbb8eacd2e42b450a2a06af4d94bda2bc103 (patch)
tree8ee3e0da7521c484165550dd2f0553a4ca52f420
parent53b752bab7dd59d1de9adcc57b4b5a6a60e8b1c6 (diff)
parentc52cfda957a3aa85c8ee4abe6ce29dcb726e909e (diff)
downloadservo-c449cbb8eacd2e42b450a2a06af4d94bda2bc103.tar.gz
servo-c449cbb8eacd2e42b450a2a06af4d94bda2bc103.zip
Auto merge of #22769 - gterzian:use_thread_pool_in_resource_thread, r=nox
Use a threadpool for fetch <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #22768 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22769) <!-- Reviewable:end -->
-rw-r--r--Cargo.lock1
-rw-r--r--components/net/Cargo.toml1
-rw-r--r--components/net/resource_thread.rs73
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json17
-rw-r--r--tests/wpt/mozilla/meta/mozilla/fetch_cannot_overwhelm_system.window.js.ini3
-rw-r--r--tests/wpt/mozilla/tests/mozilla/fetch_cannot_overwhelm_system.window.js15
6 files changed, 74 insertions, 36 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2a09547b7e3..87e5fc6248f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2805,6 +2805,7 @@ dependencies = [
"openssl 0.10.11 (registry+https://github.com/rust-lang/crates.io-index)",
"pixels 0.0.1",
"profile_traits 0.0.1",
+ "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_allocator 0.0.1",
diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml
index af3b049cda3..d21dbd56f0e 100644
--- a/components/net/Cargo.toml
+++ b/components/net/Cargo.toml
@@ -44,6 +44,7 @@ net_traits = {path = "../net_traits"}
openssl = "0.10"
pixels = {path = "../pixels"}
profile_traits = {path = "../profile_traits"}
+rayon = "1"
serde = "1.0"
serde_json = "1.0"
servo_allocator = {path = "../allocator"}
diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs
index 32a3fb28058..cdbaa747edd 100644
--- a/components/net/resource_thread.rs
+++ b/components/net/resource_thread.rs
@@ -406,6 +406,7 @@ pub struct CoreResourceManager {
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
swmanager_chan: Option<IpcSender<CustomResponseMediator>>,
filemanager: FileManager,
+ fetch_pool: rayon::ThreadPool,
}
impl CoreResourceManager {
@@ -415,11 +416,16 @@ impl CoreResourceManager {
_profiler_chan: ProfilerChan,
embedder_proxy: EmbedderProxy,
) -> CoreResourceManager {
+ let pool = rayon::ThreadPoolBuilder::new()
+ .num_threads(16)
+ .build()
+ .unwrap();
CoreResourceManager {
user_agent: user_agent,
devtools_chan: devtools_channel,
swmanager_chan: None,
filemanager: FileManager::new(embedder_proxy),
+ fetch_pool: pool,
}
}
@@ -454,42 +460,37 @@ impl CoreResourceManager {
_ => ResourceTimingType::Resource,
};
- thread::Builder::new()
- .name(format!("fetch thread for {}", request_builder.url))
- .spawn(move || {
- let mut request = request_builder.build();
- // XXXManishearth: Check origin against pipeline id (also ensure that the mode is allowed)
- // todo load context / mimesniff in fetch
- // todo referrer policy?
- // todo service worker stuff
- let context = FetchContext {
- state: http_state,
- user_agent: ua,
- devtools_chan: dc,
- filemanager: filemanager,
- cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(
- cancel_chan,
- ))),
- timing: Arc::new(Mutex::new(ResourceFetchTiming::new(request.timing_type()))),
- };
-
- match res_init_ {
- Some(res_init) => {
- let response = Response::from_init(res_init, timing_type);
- http_redirect_fetch(
- &mut request,
- &mut CorsCache::new(),
- response,
- true,
- &mut sender,
- &mut None,
- &context,
- );
- },
- None => fetch(&mut request, &mut sender, &context),
- };
- })
- .expect("Thread spawning failed");
+ self.fetch_pool.spawn(move || {
+ let mut request = request_builder.build();
+ // XXXManishearth: Check origin against pipeline id (also ensure that the mode is allowed)
+ // todo load context / mimesniff in fetch
+ // todo referrer policy?
+ // todo service worker stuff
+ let context = FetchContext {
+ state: http_state,
+ user_agent: ua,
+ devtools_chan: dc,
+ filemanager: filemanager,
+ cancellation_listener: Arc::new(Mutex::new(CancellationListener::new(cancel_chan))),
+ timing: Arc::new(Mutex::new(ResourceFetchTiming::new(request.timing_type()))),
+ };
+
+ match res_init_ {
+ Some(res_init) => {
+ let response = Response::from_init(res_init, timing_type);
+ http_redirect_fetch(
+ &mut request,
+ &mut CorsCache::new(),
+ response,
+ true,
+ &mut sender,
+ &mut None,
+ &context,
+ );
+ },
+ None => fetch(&mut request, &mut sender, &context),
+ };
+ });
}
fn websocket_connect(
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index 44be53a4de0..a29a6bb5c5a 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -13052,6 +13052,19 @@
{}
]
],
+ "mozilla/fetch_cannot_overwhelm_system.window.js": [
+ [
+ "mozilla/fetch_cannot_overwhelm_system.window.html",
+ {
+ "script_metadata": [
+ [
+ "title",
+ "Ensure multiple fetch do not crash the browser."
+ ]
+ ]
+ }
+ ]
+ ],
"mozilla/first-reflow-sheet-assert.html": [
[
"mozilla/first-reflow-sheet-assert.html",
@@ -20057,6 +20070,10 @@
"0ba1ce0d5577de68e5e8ff3acbce52043e7dee43",
"testharness"
],
+ "mozilla/fetch_cannot_overwhelm_system.window.js": [
+ "989231e9caedd099f5212bd2f9d377c83f929a22",
+ "testharness"
+ ],
"mozilla/first-reflow-sheet-assert.html": [
"268af6d333f04adc35974ca3f2e9ebb29783fd2e",
"testharness"
diff --git a/tests/wpt/mozilla/meta/mozilla/fetch_cannot_overwhelm_system.window.js.ini b/tests/wpt/mozilla/meta/mozilla/fetch_cannot_overwhelm_system.window.js.ini
new file mode 100644
index 00000000000..37bb7100b8c
--- /dev/null
+++ b/tests/wpt/mozilla/meta/mozilla/fetch_cannot_overwhelm_system.window.js.ini
@@ -0,0 +1,3 @@
+[fetch_cannot_overwhelm_system.window.html]
+ expected:
+ if os == "linux": CRASH
diff --git a/tests/wpt/mozilla/tests/mozilla/fetch_cannot_overwhelm_system.window.js b/tests/wpt/mozilla/tests/mozilla/fetch_cannot_overwhelm_system.window.js
new file mode 100644
index 00000000000..989231e9cae
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/fetch_cannot_overwhelm_system.window.js
@@ -0,0 +1,15 @@
+// META: title=Ensure multiple fetch do not crash the browser.
+
+async_test(function(t) {
+ onload = t.step_func(function() {
+ var step;
+ var xhr
+ var url = '/';
+ t.step_timeout(t.step_func_done(), 10);
+ for (step = 0; step < 5000; step++) {
+ xhr = new XMLHttpRequest();
+ xhr.open('GET', url, true);
+ xhr.send();
+ }
+ });
+});