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

Make background hang monitor optional #25647

Closed
jdm opened this issue Jan 30, 2020 · 11 comments
Closed

Make background hang monitor optional #25647

jdm opened this issue Jan 30, 2020 · 11 comments
Labels
Projects

Comments

@jdm
Copy link
Member

@jdm jdm commented Jan 30, 2020

In performance-sensitive situations like immersive mode on the hololens, having the background hang monitor thread running shows up in profiles. We should make it a configuration option at engine startup, and put the channels to communicate with the thread inside Option values so we don't have unnecessary channel traffic.

@jdm jdm added the I-perf-slow label Jan 30, 2020
@gterzian
Copy link
Member

@gterzian gterzian commented Jan 31, 2020

One way, perhaps the easiest, to do this, would:

  1. Set a flag using servo_config.
  2. In the BHM:

Here:

You could read the flag, and if we don't want to actually start a worker:

  1. Don't start one,
  2. return an implementation of BackgroundHangMonitorRegister that basically does nothing, where register_component would itself return an implementation of BackgroundHangMonitor that would do nothing.

put the channels to communicate with the thread inside Option values so we don't have unnecessary channel traffic

If the above solution is still too much, in the sense that components will still allocate and drop messages when they use the empty BackgroundHangMonitor, then we could indeed actually make changes to the client code and avoid any operation from happening.

@CYBAI
Copy link
Collaborator

@CYBAI CYBAI commented Jan 31, 2020

Maybe we can use the features of cargo and init the hang monitor like this 👀?

#[cfg(feature = "webdriver")]
fn webdriver(port: u16, constellation: Sender<ConstellationMsg>) {
webdriver_server::start_server(port, constellation);
}
#[cfg(not(feature = "webdriver"))]
fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) {}

@gterzian
Copy link
Member

@gterzian gterzian commented Jan 31, 2020

Yes that could be a good idea, how would that work exactly with the BHM being a sub-crate and with the workspace setup of the repo as a whole? I'm looking around online and if you already know how it would be done, please describe it here!

@CYBAI
Copy link
Collaborator

@CYBAI CYBAI commented Jan 31, 2020

@gterzian I'm not familiar with how BHM works but I imagine maybe we can do it like

For example, for the following piece of code, we will initiate the BHM if the feature is specified.

let (background_monitor_register, sampler_chan) = if cfg!(feature = "background_hang_monitor") {
    let (sampling_profiler_control, sampling_profiler_port) =
        ipc::channel().expect("ipc channel failure");

    (
        Some(HangMonitorRegister::init(
            background_hang_monitor_sender.clone(),
            sampling_profiler_port,
        )),
        vec![sampling_profiler_control],
    )
} else {
    (None, vec![])
};

// If we are in multiprocess mode,
// a dedicated per-process hang monitor will be initialized later inside the content process.
// See run_content_process in servo/lib.rs
let (background_monitor_register, sampler_chan) = if opts::multiprocess() {
(None, vec![])
} else {
let (sampling_profiler_control, sampling_profiler_port) =
ipc::channel().expect("ipc channel failure");
(
Some(HangMonitorRegister::init(
background_hang_monitor_sender.clone(),
sampling_profiler_port,
)),
vec![sampling_profiler_control],
)
};

Maybe @jdm will have better plan though, WDYT 👀?

@CYBAI
Copy link
Collaborator

@CYBAI CYBAI commented Jan 31, 2020

☝️ In this solution, I mean, if we don't specify --features="background_hang_monitor, then we don't start a BHM so that we might be able to avoid using it when we want?

@gterzian
Copy link
Member

@gterzian gterzian commented Feb 1, 2020

Looks like a good idea. I think what I proposed with different implementations of the current traits is actually too complicated.

@jdm
Copy link
Member Author

@jdm jdm commented Feb 19, 2020

As a developer, it would be ideal if this were a runtime rather than compile-time choice. My preference would be using Options around channels like we do with the devtools server.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Feb 20, 2020

@jdm could you point out the devtools server implementation that you referred above. It would be helpful if I take a look at it first.

@jdm
Copy link
Member Author

@jdm jdm commented Feb 20, 2020

This is where the devtools server is started, and the channel to communicate with it is stored in an Option. Similarly this is client code that will communicate with the devtools server if it exists.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Feb 21, 2020

If I wrap the value in background_hang_monitor_receiver inside Option, how do I handle it inside select macro?

recv(self.background_hang_monitor_receiver) -> msg => {
msg.expect("Unexpected BHM channel panic in constellation").map(Request::BackgroundHangMonitor)
}

@gterzian
Copy link
Member

@gterzian gterzian commented Feb 22, 2020

I think the example "Optionally add a receive operation to select! using never" could be useful for this, see https://docs.rs/crossbeam-channel/0.4.0/crossbeam_channel/macro.select.html

@kunalmohan kunalmohan mentioned this issue Feb 22, 2020
3 of 5 tasks complete
bors-servo added a commit that referenced this issue Feb 22, 2020
Make Background Hang Monitor Optional

This is done by wrapping all channels of communication and related objects inside Option which are configured using flag inside servo_config.

<!-- 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: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25647  (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. -->
bors-servo added a commit that referenced this issue Feb 22, 2020
Make Background Hang Monitor Optional

This is done by wrapping all channels of communication and related objects inside Option which are configured using flag inside servo_config.

<!-- 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: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25647  (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. -->
bors-servo added a commit that referenced this issue Feb 22, 2020
Make Background Hang Monitor Optional

This is done by wrapping all channels of communication and related objects inside Option which are configured using flag inside servo_config.

<!-- 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: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25647  (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. -->
bors-servo added a commit that referenced this issue Feb 23, 2020
Make Background Hang Monitor Optional

This is done by wrapping all channels of communication and related objects inside Option which are configured using flag inside servo_config.

<!-- 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: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25647  (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. -->
@atouchet atouchet added this to Done in HoloLens Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
HoloLens
  
Done
Linked pull requests

Successfully merging a pull request may close this issue.

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