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

Improve addrman Select() performance when buckets are nearly empty #6530

Merged
merged 1 commit into from Aug 26, 2015

Conversation

@sipa
Copy link
Member

sipa commented Aug 6, 2015

Earlier, when there are only a few entries in the addrman tables, Select() could spin for long periods of time (~200ms), resulting in high CPU usage (up to 40% here). This reduces it to around 0.3ms (0.5% CPU).

@sipa sipa force-pushed the sipa:fastselect branch 2 times, most recently Aug 6, 2015
@dgenr8
Copy link
Contributor

dgenr8 commented Aug 7, 2015

utACK

@TheBlueMatt
Copy link
Contributor

TheBlueMatt commented Aug 8, 2015

utACK

@gmaxwell
Copy link
Contributor

gmaxwell commented Aug 22, 2015

ACK

@laanwj
laanwj reviewed Aug 24, 2015
View changes
src/addrman.cpp Outdated
@@ -341,8 +341,11 @@ CAddrInfo CAddrMan::Select_()
while (1) {
int nKBucket = GetRandInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
if (vvTried[nKBucket][nKBucketPos] == -1)
continue;
while (1) {

This comment has been minimized.

Copy link
@laanwj

laanwj Aug 24, 2015

Member

Equivalent but maybe slightly more readable:

while(vvTried[nKBucket][nKBucketPos] == -1) {
    nKBucket = (nKBucket + insecure_rand()) % ADDRMAN_TRIED_BUCKET_COUNT;
    nKBucketPos = (nKBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
}

This comment has been minimized.

Copy link
@sipa

sipa Aug 26, 2015

Author Member

Nit addressed.

@sipa sipa force-pushed the sipa:fastselect branch to c33c11e Aug 26, 2015
@dcousens
Copy link
Contributor

dcousens commented Aug 26, 2015

utACK

@laanwj laanwj merged commit c33c11e into bitcoin:master Aug 26, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
laanwj added a commit that referenced this pull request Aug 26, 2015
c33c11e Improve addrman Select() performance when buckets are nearly empty (Pieter Wuille)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

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