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

remove useless millisleep #4790

Merged
merged 1 commit into from Sep 4, 2014
Merged

remove useless millisleep #4790

merged 1 commit into from Sep 4, 2014

Conversation

pstratem
Copy link
Contributor

reduces time to service requests improving performance

calls is unnecessary as select() blocks and on select() failure there is another MilliSleep()

@theuni
Copy link
Member

theuni commented Aug 30, 2014

This looks like a typical fail-safe for avoiding pegging the cpu in a tight loop. Are you sure there are no cases where the the thread ends up looping without a stall? There are plenty of cases where a select can return immediately without error.

@pstratem
Copy link
Contributor Author

@theuni This handles all cases.

timeout - essentially MilliSleep(50)
error - MilliSleep(50)
fd's ready - we dont want to sleep!

@sipa
Copy link
Member

sipa commented Aug 30, 2014

Untested ACK

@theuni
Copy link
Member

theuni commented Aug 30, 2014

@pstratem No problem. I didn't mean to imply that it really is needed, only that it may have a non-obvious use.

@pstratem
Copy link
Contributor Author

pstratem commented Sep 2, 2014

@theuni I didn't take offense, sanity checking even the most trivial looking changes makes perfect sense.

@gmaxwell
Copy link
Contributor

gmaxwell commented Sep 3, 2014

For those following at home. There are currently two sleeps in the network handling code— one in the thread with the select. One in the threadmessagehandler. The latter is necessary (or at least must be replaced with a semaphor) to prevent a busy loop. This one is not— it should be superfluous to the select, except— perhaps— if there are no connections.

(Posix select is defined to sleep when empty, but someone might want to double check on windows.)

@pstratem
Copy link
Contributor Author

pstratem commented Sep 3, 2014

should behave correctly with no connections, select() should sleep for the timeout period (select manpage specifically references calling select like this to get a high precision sleep function).

@pstratem
Copy link
Contributor Author

pstratem commented Sep 3, 2014

tested on debian 7.6, ./bitcoind -connect=10.1.1.1 does not result in a busy loop

@jgarzik
Copy link
Contributor

jgarzik commented Sep 3, 2014

Yah, that's fine on *nix. Windows is the key platform to test, for select() behavior. it is already quite odd on windows, only working for some types of handles (sockets). No-socket behavior is precisely the area windows would be annoying ;p

@pstratem
Copy link
Contributor Author

pstratem commented Sep 3, 2014

@jgarzik yes windows immediately returns WSAEINVAL if the three sets are empty

This triggers the MilliSleep in the error handler

There is only an issue if select returns a value other than -1 without blocking.

That doesn't appear to happen on any platform.

@gmaxwell
Copy link
Contributor

gmaxwell commented Sep 3, 2014

Okay, seems (according to the interwebs) that— indeed— windows returns an error instead of sleeping in the no socket case. But we already have a sleep in the error handling path.

I've tested this on Linux with and without connections. ACK on the change— But I'd like to hear that this was tested with and without any connections (e.g. -connect=0.0.0.0, and check if Bitcoin is pegging the cpu) on Windows and Mac.

reduces time to service requests improving performance
@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4790_9189f5fe4df1ac7ea6ca75ceada867beafda90a9/ for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@laanwj
Copy link
Member

laanwj commented Sep 3, 2014

Never knew that -connect=0.0.0.0 could be used to not connect to any nodes. Having a way to not connect was one of my reasons for being in favor of #4687.

@gavinandresen
Copy link
Contributor

ACK, tested on OSX with -connect=0.0.0.0

@gmaxwell
Copy link
Contributor

gmaxwell commented Sep 3, 2014

@pstratem Can you get this crazy merge commit out of here? (just rewrite against master and force push) this could be fixed on merge too but it might safe someone a few minutes to fix it yourself.

@pstratem
Copy link
Contributor Author

pstratem commented Sep 3, 2014

@gmaxwell i did... last night..?

@gmaxwell
Copy link
Contributor

gmaxwell commented Sep 4, 2014

@pstratem Weird, github must have been displaying stale data for me.

@pstratem
Copy link
Contributor Author

pstratem commented Sep 4, 2014

@gmaxwell I've found their caching to be consistently overly aggressive.

@laanwj laanwj merged commit 9189f5f into bitcoin:master Sep 4, 2014
laanwj added a commit that referenced this pull request Sep 4, 2014
9189f5f remove useless millisleep (phantomcircuit)
wtogami pushed a commit to litecoin-project/bitcoinomg that referenced this pull request Sep 9, 2014
reduces time to service requests improving performance

Rebased-from: 9189f5fe4df1ac7ea6ca75ceada867beafda90a9
bitcoin/bitcoin#4790
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants