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

raft: reduce allocation #2391

Merged
merged 4 commits into from Oct 19, 2017

Conversation

Projects
None yet
3 participants
@BusyJay
Contributor

BusyJay commented Oct 18, 2017

No description provided.

@BusyJay BusyJay requested review from siddontang, overvenus and disksing Oct 18, 2017

let mci = mis[self.quorum() - 1];
let term = self.term;
self.raft_log.maybe_commit(mci, term)
let mci = if self.prs.len() <= 5 {

This comment has been minimized.

@siddontang

siddontang Oct 18, 2017

Contributor

why < 5 here?

This comment has been minimized.

@BusyJay

BusyJay Oct 18, 2017

Contributor

So the matched IDs can be put in a [0; 5] array. Generally we only have 3 or 5 replicas.

This comment has been minimized.

@overvenus

This comment has been minimized.

@BusyJay

BusyJay Oct 18, 2017

Contributor

Why use it? I think the final code should look almost the same.

This comment has been minimized.

@siddontang

siddontang Oct 18, 2017

Contributor

I think we should add a benchmark case here.

This comment has been minimized.

@BusyJay

BusyJay Oct 18, 2017

Contributor

The code will hardly change, an additional benchmark case seems redundant. My benchmark shows that use array is about 50% quicker.

When len is 3:
test bench_commit_array ... bench: 13 ns/iter (+/- 0)
test bench_commit_vec ... bench: 28 ns/iter (+/- 0)

When len is 5:
test bench_commit_array ... bench: 20 ns/iter (+/- 0)
test bench_commit_vec ... bench: 35 ns/iter (+/- 0)

mis[self.quorum() - 1]
} else {
let mut mis = Vec::with_capacity(self.prs.len());
for p in self.prs.values() {

This comment has been minimized.

@siddontang

siddontang Oct 19, 2017

Contributor

can we change vec to slice and unify the two similar codes?

..Default::default()
};
if !raft.msgs.is_empty() {
mem::swap(&mut raft.msgs, &mut rd.messages);

This comment has been minimized.

@siddontang

siddontang Oct 19, 2017

Contributor

any benchmark here?

This comment has been minimized.

@BusyJay

BusyJay Oct 19, 2017

Contributor

It's very obvious that mem::swap does not copy the heap values however drain.collect will allocate a new buffer then copy all the content from original.

For a 100 length u64 vector:
test bench_drain_collect ... bench: 105 ns/iter (+/- 2)
test bench_swap ... bench: 2 ns/iter (+/- 0)

BusyJay added some commits Oct 19, 2017

@BusyJay

This comment has been minimized.

Contributor

BusyJay commented Oct 19, 2017

/run-unit-test

@siddontang

LGTM

@BusyJay

This comment has been minimized.

Contributor

BusyJay commented Oct 19, 2017

/run-integration-test

@BusyJay BusyJay merged commit 895b76a into master Oct 19, 2017

5 checks passed

ci/circleci Your tests passed on CircleCI!
Details
jenkins-ci-tikv/build Jenkins job succeeded.
Details
jenkins-ci-tikv/integration-common-test Jenkins job succeeded.
Details
jenkins-ci-tikv/integration-ddl-test Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@BusyJay BusyJay deleted the busyjay/reduce-allocation branch Oct 19, 2017

BusyJay added a commit to BusyJay/tikv that referenced this pull request Oct 30, 2017

@BusyJay BusyJay referenced this pull request Oct 30, 2017

Merged

raft: reduce allocation #2434

siddontang added a commit that referenced this pull request Oct 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment