Skip to content

Parameterize memory size and some key improvements #153

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

Merged
merged 6 commits into from
Aug 10, 2022

Conversation

hanahmily
Copy link
Contributor

These changes introduce several parameters to control memory usage. I assigned some defaults to them, and now the initial memory is around 2GB 🎉

There are a series of improvements:

  • Remove run.Chan, which could cause the data race. We don't have to close a channel more than notifying the receivers. @lujiajing1126 Please don't try to use it.
  • Introduce a self-spinning lock to optimize the life-cycle of the block.
  • Fix a tiny bug about parsing the lsm index's key. You never encounter errors in testing the measure package.

Signed-off-by: Gao Hongtao hanahmily@gmail.com

Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
@hanahmily hanahmily added the enhancement New feature or request label Aug 9, 2022
@hanahmily hanahmily added this to the 0.2.0 milestone Aug 9, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2022

Codecov Report

Merging #153 (3a65acd) into main (4391412) will decrease coverage by 0.10%.
The diff coverage is 67.04%.

@@            Coverage Diff             @@
##             main     #153      +/-   ##
==========================================
- Coverage   54.11%   54.00%   -0.11%     
==========================================
  Files          89       89              
  Lines        7904     7997      +93     
==========================================
+ Hits         4277     4319      +42     
- Misses       3233     3275      +42     
- Partials      394      403       +9     
Impacted Files Coverage Δ
banyand/tsdb/metric.go 35.29% <0.00%> (ø)
pkg/timestamp/clock.go 0.00% <ø> (ø)
banyand/tsdb/series.go 45.34% <12.50%> (-3.41%) ⬇️
banyand/tsdb/segment.go 64.91% <31.70%> (-3.15%) ⬇️
banyand/tsdb/seriesdb.go 75.93% <62.96%> (-0.51%) ⬇️
banyand/tsdb/block.go 65.05% <69.47%> (-5.58%) ⬇️
banyand/tsdb/bucket/strategy.go 73.13% <69.69%> (-11.16%) ⬇️
pkg/index/lsm/lsm.go 62.96% <80.00%> (+6.44%) ⬆️
banyand/measure/metadata.go 65.97% <100.00%> (+0.23%) ⬆️
banyand/measure/service.go 73.33% <100.00%> (+0.73%) ⬆️
... and 9 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Contributor

@lujiajing1126 lujiajing1126 left a comment

Choose a reason for hiding this comment

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

We should make default values constants or variables and add comments for them rather than directly use them everywhere.

Instead of 2<<20 or 8<<20, I prefer 1<<21 or 1<<24 which seems to be clearer.

Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
@lujiajing1126
Copy link
Contributor

  • Remove run.Chan, which could cause the data race. We don't have to close a channel more than notifying the receivers. @lujiajing1126 Please don't try to use it.

Not quite follow this argument. I remember I'm not using this toolkit.

@hanahmily
Copy link
Contributor Author

We should make default values constants or variables and add comments for them rather than directly use them everywhere.

Make sense, I will tweak them.

Instead of 2<<20 or 8<<20, I prefer 1<<21 or 1<<24 which seems to be clearer.

8<<20 indicates the literal(8) and the unit(1<<20=1024*1024=1MB), which is more precise and straightforward than 1<<24.

Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
@hanahmily
Copy link
Contributor Author

Fixes apache/skywalking#9383

}(value)
}

func (s *Writer) Close() error {
return s.ch.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we removed Close() here, is it possible we still have many goroutines waiting to write to the channel?

Copy link
Contributor Author

@hanahmily hanahmily Aug 10, 2022

Choose a reason for hiding this comment

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

We can use close to notify the receivers, not the senders. The senders will be waiting to write. That is the purpose of this process. They won't block the GC from collecting them.

Copy link
Contributor

@lujiajing1126 lujiajing1126 Aug 10, 2022

Choose a reason for hiding this comment

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

We can use close to notify the receivers, not the senders. The senders will be waiting to write. That is the purpose of this process.

Yes, we can use some stop channel to notify the receivers, but what about the senders?

They won't block the GC from collecting them.

From this issue, golang/go#19702, Go may not be clever enough now to garbage collect blocking goroutines.

Copy link
Member

Choose a reason for hiding this comment

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

Automatically closing always has this kind of bugs in GC phases.
Be careful. We don't want a leak 😄

verification round

Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
Signed-off-by: Gao Hongtao <hanahmily@gmail.com>
Copy link
Contributor

@lujiajing1126 lujiajing1126 left a comment

Choose a reason for hiding this comment

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

LGTM. We can create an issue to track goroutine leak issue later.

@lujiajing1126 lujiajing1126 merged commit 05d858a into main Aug 10, 2022
@lujiajing1126 lujiajing1126 deleted the optimize-memory branch August 10, 2022 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants