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

Sleep while polling sockets on Windows #5594

Merged
merged 5 commits into from
Jun 17, 2022
Merged

Sleep while polling sockets on Windows #5594

merged 5 commits into from
Jun 17, 2022

Conversation

nirinchev
Copy link
Member

@nirinchev nirinchev commented Jun 15, 2022

What, How & Why?

This appears to address the issue reported in #5591.

I have no idea if that's a real fix or making things worse, but when testing locally, it made CPU usage go from 100% on both cores to ~10-20%.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed.

@@ -1155,6 +1155,8 @@ bool Service::IoReactor::wait_and_advance(clock::time_point timeout, clock::time
ret++;
}

std::this_thread::sleep_for(std::chrono::milliseconds(10));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i think maybe this should be on line 1151 like

if (m_pollfd_slots.size() > 1) {
    ...
} else if (m_wakeup_pipe.is_signaled()) {
    ...
} else {
    sleep()
}

Maybe what's going on here is that you don't have any active sync sessions and so you're stuck busy waiting for a sync session to open or the Service to get something posted to it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to preserve the old behavior (no else for if (m_wakeup_pipe.is_signaled())) because I don't know enough about networking on Windows and in Core to judge whether it was intentional that we always check for the wakeup pipe, regardless of whether we polled the sockets. Happy to make the suggested change if you believe the original code was wrong though.

src/realm/util/network.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@blagoev blagoev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as red until we had a chance to discuss it offline

@nirinchev nirinchev marked this pull request as ready for review June 16, 2022 09:25
@nirinchev
Copy link
Member Author

The failing tests seem to be due to timeouts starting stitch and on macos/ubuntu, so they should not be caused by the changes in this PR.

@blagoev
Copy link
Contributor

blagoev commented Jun 16, 2022

We had the discussion. Fee free to merge it.

@blagoev
Copy link
Contributor

blagoev commented Jun 16, 2022

I propose an alternative fix here #5599

Copy link
Contributor

@blagoev blagoev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we use the alternative fix unless something critical is found with it

Copy link
Contributor

@blagoev blagoev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After profiling both fixes and sharing the results I will leave it to Core team to decide which fix to go in.

@nirinchev
Copy link
Member Author

I'm going to merge this as is to make our Dart tests reliably green. We can always improve the situation with #5599 whenever that passes review.

@nirinchev nirinchev merged commit def0126 into master Jun 17, 2022
@nirinchev nirinchev deleted the ni/sleep branch June 17, 2022 16:24
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants