mirror of
https://github.com/servo/servo.git
synced 2025-07-08 16:03:40 +01:00
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 -->
This commit is contained in:
commit
c449cbb8ea
6 changed files with 73 additions and 35 deletions
|
@ -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"}
|
||||
|
|
|
@ -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()))),
|
||||
};
|
||||
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),
|
||||
};
|
||||
})
|
||||
.expect("Thread spawning failed");
|
||||
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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue