Skip to content

Improve allocation for SoftState in Ready.#13

Merged
tbg merged 1 commit into
etcd-io:mainfrom
XiongKezhi:soft-state-allocation
Jan 4, 2023
Merged

Improve allocation for SoftState in Ready.#13
tbg merged 1 commit into
etcd-io:mainfrom
XiongKezhi:soft-state-allocation

Conversation

@XiongKezhi

Copy link
Copy Markdown
Contributor

Fixes: etcd-io/raft#10.

Improve allocation for SoftState in Ready so that only when changes, it will escape to the heap.

BenchmarkRawNode result (generated by benchdiff):

name                     old time/op        new time/op        delta
RawNode/two-voters-12          1.54µs ±18%        1.44µs ± 7%   -6.85%  (p=0.041 n=10+8)
RawNode/single-voter-12         892ns ± 4%         871ns ±20%     ~     (p=0.182 n=9+10)

name                     old firstIndex/op  new firstIndex/op  delta
RawNode/single-voter-12          2.00 ± 0%          2.00 ± 0%     ~     (all equal)
RawNode/two-voters-12            6.00 ± 0%          6.00 ± 0%     ~     (all equal)

name                     old lastIndex/op   new lastIndex/op   delta
RawNode/single-voter-12          2.00 ± 0%          2.00 ± 0%     ~     (all equal)
RawNode/two-voters-12            2.00 ± 0%          2.00 ± 0%     ~     (all equal)

name                     old ready/op       new ready/op       delta
RawNode/single-voter-12          2.00 ± 0%          2.00 ± 0%     ~     (all equal)
RawNode/two-voters-12            2.00 ± 0%          2.00 ± 0%     ~     (all equal)

name                     old term/op        new term/op        delta
RawNode/single-voter-12          0.00 ± 7%          0.00 ± 0%     ~     (p=0.108 n=9+10)
RawNode/two-voters-12            1.00 ± 0%          1.00 ± 0%     ~     (all equal)

name                     old alloc/op       new alloc/op       delta
RawNode/single-voter-12          422B ± 2%          376B ± 4%  -10.92%  (p=0.000 n=8+10)
RawNode/two-voters-12            658B ± 3%          629B ± 3%   -4.44%  (p=0.000 n=10+10)

name                     old allocs/op      new allocs/op      delta
RawNode/single-voter-12          5.00 ± 0%          3.00 ± 0%  -40.00%  (p=0.000 n=10+10)
RawNode/two-voters-12            7.00 ± 0%          5.00 ± 0%  -28.57%  (p=0.000 n=10+10)

@XiongKezhi XiongKezhi force-pushed the soft-state-allocation branch from b3762e3 to b1546fe Compare December 21, 2022 19:57
@tbg tbg self-requested a review December 22, 2022 09:10
Signed-off-by: Kezhi Xiong <august.xkz@gmail.com>
@tbg tbg force-pushed the soft-state-allocation branch from b1546fe to 228ee70 Compare December 22, 2022 09:24
@tbg

tbg commented Dec 22, 2022

Copy link
Copy Markdown
Contributor

Thank you! I rebased your PR, there were merge conflicts due to #8.

Re-ran the benchmarks produced different numbers now, but the reduction we're targeting is still there.

$ benchdiff --old HEAD~1 -r BenchmarkRawNode -c 5 .
test binaries already exist for '65a0bf3'; skipping build
test binaries already exist for '228ee70'; skipping build

  pkg=1/1 iter=5/5 go.etcd.io/raft/v3 /

name                     old time/op        new time/op        delta
RawNode/single-voter-10         918ns ± 1%         900ns ± 1%   -1.93%  (p=0.032 n=5+5)
RawNode/two-voters-10          1.37µs ± 1%        1.35µs ± 1%   -1.71%  (p=0.008 n=5+5)

name                     old firstIndex/op  new firstIndex/op  delta
RawNode/single-voter-10          1.00 ± 0%          1.00 ± 0%     ~     (all equal)
RawNode/two-voters-10            3.00 ± 0%          3.00 ± 0%     ~     (all equal)

name                     old lastIndex/op   new lastIndex/op   delta
RawNode/single-voter-10          2.00 ± 0%          2.00 ± 0%     ~     (all equal)
RawNode/two-voters-10            2.00 ± 0%          2.00 ± 0%     ~     (all equal)

name                     old ready/op       new ready/op       delta
RawNode/single-voter-10          2.00 ± 0%          2.00 ± 0%     ~     (all equal)
RawNode/two-voters-10            2.00 ± 0%          2.00 ± 0%     ~     (all equal)

name                     old term/op        new term/op        delta
RawNode/single-voter-10          0.00 ± 0%          0.00 ± 0%  -12.50%  (p=0.008 n=5+5)
RawNode/two-voters-10            1.00 ± 0%          1.00 ± 0%     ~     (all equal)

name                     old alloc/op       new alloc/op       delta
RawNode/two-voters-10            883B ± 1%          850B ± 1%   -3.72%  (p=0.008 n=5+5)
RawNode/single-voter-10          533B ± 0%          549B ± 2%   +2.89%  (p=0.008 n=5+5)

name                     old allocs/op      new allocs/op      delta
RawNode/single-voter-10          6.00 ± 0%          4.00 ± 0%  -33.33%  (p=0.008 n=5+5)
RawNode/two-voters-10            8.00 ± 0%          6.00 ± 0%  -25.00%  (p=0.008 n=5+5)

Looks like #8 (or something else) gave us an extra allocation.

Not this PR's problem, though.

@tbg tbg merged commit c040647 into etcd-io:main Jan 4, 2023
@tbg

tbg commented Jan 4, 2023

Copy link
Copy Markdown
Contributor

Thank you!

Qian-Cheng-nju pushed a commit to specula-org/raft that referenced this pull request Mar 26, 2026
The heartbeat loop invokes leaderSendAEs without holding cm.mu, so in the
mean-time this node may have become a follower, and shouldn't be sending
heartbeats.

For etcd-io#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(*raft).softState() allocates

2 participants