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

Move index values cache to bucket level to prevent race condition #306

Closed
wants to merge 1 commit into from

Conversation

yeya24
Copy link
Owner

@yeya24 yeya24 commented Jan 7, 2021

Signed-off-by: yeya24 [email protected]

The indexHeader is shared so we need to use locks. However, the upper level bucketIndexReader is one-per request so we don't need to add locks there. The idea is to move the values cache to the bucket level.

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Verification

@yeya24
Copy link
Owner Author

yeya24 commented Jan 7, 2021

The benchmark results are below and I did it twice. Comparing this pr with thanos-io#3705.

The performance is similar overall, only a little bit improvement.

name                                                                 old time/op    new time/op    delta
TelemeterRealData_Series/alerts2w/01EPXBGA0413QZMTF4XQ0M4Q3E            10.8s ± 0%     10.6s ± 0%  -2.12%
TelemeterRealData_Series/alerts15s/01EPXBGA0413QZMTF4XQ0M4Q3E           6.81s ± 0%     6.72s ± 0%  -1.30%
TelemeterRealData_Series/subssyncs2w/01EPXBGA0413QZMTF4XQ0M4Q3E         1.16s ± 0%     1.12s ± 0%  -3.55%
TelemeterRealData_Series/subs2w/01EPXBGA0413QZMTF4XQ0M4Q3E              6.43s ± 0%     5.79s ± 0%  -9.96%
TelemeterRealData_Series/subs2w1account/01EPXBGA0413QZMTF4XQ0M4Q3E      2.00s ± 0%     1.81s ± 0%  -9.20%
TelemeterRealData_Series/subs15m1account/01EPXBGA0413QZMTF4XQ0M4Q3E     2.02s ± 0%     1.87s ± 0%  -7.30%
TelemeterRealData_Series/subs15s/01EPXBGA0413QZMTF4XQ0M4Q3E             3.35s ± 0%     3.21s ± 0%  -4.36%

name                                                                 old alloc/op   new alloc/op   delta
TelemeterRealData_Series/alerts2w/01EPXBGA0413QZMTF4XQ0M4Q3E           4.18GB ± 0%    4.17GB ± 0%  -0.27%
TelemeterRealData_Series/alerts15s/01EPXBGA0413QZMTF4XQ0M4Q3E          1.84GB ± 0%    1.84GB ± 0%  +0.40%
TelemeterRealData_Series/subssyncs2w/01EPXBGA0413QZMTF4XQ0M4Q3E         444MB ± 0%     444MB ± 0%  +0.01%
TelemeterRealData_Series/subs2w/01EPXBGA0413QZMTF4XQ0M4Q3E             2.33GB ± 0%    2.33GB ± 0%  +0.00%
TelemeterRealData_Series/subs2w1account/01EPXBGA0413QZMTF4XQ0M4Q3E      662MB ± 0%     662MB ± 0%  +0.01%
TelemeterRealData_Series/subs15m1account/01EPXBGA0413QZMTF4XQ0M4Q3E     662MB ± 0%     662MB ± 0%  +0.00%
TelemeterRealData_Series/subs15s/01EPXBGA0413QZMTF4XQ0M4Q3E             858MB ± 0%     858MB ± 0%  +0.00%

name                                                                 old allocs/op  new allocs/op  delta
TelemeterRealData_Series/alerts2w/01EPXBGA0413QZMTF4XQ0M4Q3E            34.6M ± 0%     34.7M ± 0%  +0.07%
TelemeterRealData_Series/alerts15s/01EPXBGA0413QZMTF4XQ0M4Q3E           21.5M ± 0%     21.4M ± 0%  -0.12%
TelemeterRealData_Series/subssyncs2w/01EPXBGA0413QZMTF4XQ0M4Q3E         2.41M ± 0%     2.41M ± 0%  +0.01%
TelemeterRealData_Series/subs2w/01EPXBGA0413QZMTF4XQ0M4Q3E              13.8M ± 0%     13.8M ± 0%  +0.00%
TelemeterRealData_Series/subs2w1account/01EPXBGA0413QZMTF4XQ0M4Q3E      2.98M ± 0%     2.98M ± 0%  +0.00%
TelemeterRealData_Series/subs15m1account/01EPXBGA0413QZMTF4XQ0M4Q3E     2.98M ± 0%     2.98M ± 0%  +0.00%
TelemeterRealData_Series/subs15s/01EPXBGA0413QZMTF4XQ0M4Q3E             7.79M ± 0%     7.79M ± 0%  -0.00%
name                                                                 old time/op    new time/op    delta
TelemeterRealData_Series/alerts2w/01EPXBGA0413QZMTF4XQ0M4Q3E            10.8s ± 0%     10.3s ± 0%   -4.31%
TelemeterRealData_Series/alerts15s/01EPXBGA0413QZMTF4XQ0M4Q3E           6.81s ± 0%     7.35s ± 0%   +7.86%
TelemeterRealData_Series/subssyncs2w/01EPXBGA0413QZMTF4XQ0M4Q3E         1.16s ± 0%     1.06s ± 0%   -8.84%
TelemeterRealData_Series/subs2w/01EPXBGA0413QZMTF4XQ0M4Q3E              6.43s ± 0%     5.70s ± 0%  -11.37%
TelemeterRealData_Series/subs2w1account/01EPXBGA0413QZMTF4XQ0M4Q3E      2.00s ± 0%     1.75s ± 0%  -12.38%
TelemeterRealData_Series/subs15m1account/01EPXBGA0413QZMTF4XQ0M4Q3E     2.02s ± 0%     1.77s ± 0%  -12.08%
TelemeterRealData_Series/subs15s/01EPXBGA0413QZMTF4XQ0M4Q3E             3.35s ± 0%     3.31s ± 0%   -1.46%

name                                                                 old alloc/op   new alloc/op   delta
TelemeterRealData_Series/alerts2w/01EPXBGA0413QZMTF4XQ0M4Q3E           4.18GB ± 0%    4.15GB ± 0%   -0.58%
TelemeterRealData_Series/alerts15s/01EPXBGA0413QZMTF4XQ0M4Q3E          1.84GB ± 0%    1.83GB ± 0%   -0.51%
TelemeterRealData_Series/subssyncs2w/01EPXBGA0413QZMTF4XQ0M4Q3E         444MB ± 0%     444MB ± 0%   +0.01%
TelemeterRealData_Series/subs2w/01EPXBGA0413QZMTF4XQ0M4Q3E             2.33GB ± 0%    2.33GB ± 0%   +0.00%
TelemeterRealData_Series/subs2w1account/01EPXBGA0413QZMTF4XQ0M4Q3E      662MB ± 0%     662MB ± 0%   +0.00%
TelemeterRealData_Series/subs15m1account/01EPXBGA0413QZMTF4XQ0M4Q3E     662MB ± 0%     662MB ± 0%   +0.00%
TelemeterRealData_Series/subs15s/01EPXBGA0413QZMTF4XQ0M4Q3E             858MB ± 0%     780MB ± 0%   -9.11%

name                                                                 old allocs/op  new allocs/op  delta
TelemeterRealData_Series/alerts2w/01EPXBGA0413QZMTF4XQ0M4Q3E            34.6M ± 0%     34.7M ± 0%   +0.05%
TelemeterRealData_Series/alerts15s/01EPXBGA0413QZMTF4XQ0M4Q3E           21.5M ± 0%     21.5M ± 0%   -0.06%
TelemeterRealData_Series/subssyncs2w/01EPXBGA0413QZMTF4XQ0M4Q3E         2.41M ± 0%     2.41M ± 0%   +0.01%
TelemeterRealData_Series/subs2w/01EPXBGA0413QZMTF4XQ0M4Q3E              13.8M ± 0%     13.8M ± 0%   +0.00%
TelemeterRealData_Series/subs2w1account/01EPXBGA0413QZMTF4XQ0M4Q3E      2.98M ± 0%     2.98M ± 0%   +0.00%
TelemeterRealData_Series/subs15m1account/01EPXBGA0413QZMTF4XQ0M4Q3E     2.98M ± 0%     2.98M ± 0%   +0.00%
TelemeterRealData_Series/subs15s/01EPXBGA0413QZMTF4XQ0M4Q3E             7.79M ± 0%     7.79M ± 0%   -0.00%

Ideally, this can be improved more by using more fine-grained locks, but I haven't benchmarked it.

// Only update the cache if the block cache entry is not set.
if v != zeroIndexSymbol && r.block.valueSymbols[k] == zeroIndexSymbol {
r.block.valueSymbols[k] = v
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

This might be a problem. Not sure which way is better. Overwrite the entry every time?

@stale
Copy link

stale bot commented Mar 9, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Mar 9, 2021
@yeya24 yeya24 closed this Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant