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

Use runtime.GC for reducing indexing memory & replace saveMu with atomic busy loop for race control #682

Merged
merged 13 commits into from
Sep 11, 2020

Conversation

kpango
Copy link
Collaborator

@kpango kpango commented Sep 8, 2020

Signed-off-by: kpango [email protected]

Description:

this PR includes 2 feature

  1. Use runtime.GC for reducing indexing memory
  2. Replace save index mutex lock with atomic loop for race control

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.15.1
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.12.1

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Sep 8, 2020

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - add changelog comment
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master

@pull-assistant
Copy link

pull-assistant bot commented Sep 8, 2020

Score: 0.98

Best reviewed: commit by commit


Optimal code review plan

     use runtime.GC for reducing indexing memory

     downgrade go version for debug

     fix

     reduce create index & save index timing using busy loop and atomic cou...

     fix

     fix

     fix

     fix

     fix

     fix

     fix

     Update charts/vald/values.yaml

     Merge branch 'master' into performance/agent/use-userdefined-gc-call

Powered by Pull Assistant. Last update f62d60d ... fca1052. Read the comment docs.

@kpango kpango changed the title use runtime.GC for reducing indexing memory [WIP] {Please Do not merge}. use runtime.GC for reducing indexing memory Sep 8, 2020
@codecov
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #682 into master will decrease coverage by 0.53%.
The diff coverage is 3.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #682      +/-   ##
==========================================
- Coverage   15.55%   15.02%   -0.54%     
==========================================
  Files         412      417       +5     
  Lines       21626    22127     +501     
==========================================
- Hits         3364     3324      -40     
- Misses      18022    18554     +532     
- Partials      240      249       +9     
Impacted Files Coverage Δ
internal/config/ngt.go 100.00% <ø> (ø)
internal/errors/http.go 0.00% <0.00%> (ø)
...ternal/observability/metrics/agent/core/ngt/ngt.go 0.00% <0.00%> (ø)
pkg/agent/core/ngt/service/ngt.go 0.00% <0.00%> (ø)
pkg/agent/core/ngt/usecase/agentd.go 0.00% <0.00%> (ø)
pkg/agent/core/ngt/service/option.go 13.26% <25.00%> (+0.49%) ⬆️
internal/net/http/middleware/timeout.go 100.00% <100.00%> (ø)
internal/compress/zstd.go 30.64% <0.00%> (-69.36%) ⬇️
internal/worker/queue.go 98.55% <0.00%> (-1.45%) ⬇️
...ernal/observability/metrics/manager/index/index.go 0.00% <0.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7bc99a...fca1052. Read the comment docs.

@rinx
Copy link
Contributor

rinx commented Sep 9, 2020

How about to add options for enabling/disabling runtime.GC calls before/after CreateIndex and SaveIndex?

@rinx
Copy link
Contributor

rinx commented Sep 9, 2020

/rebase

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Sep 9, 2020

[REBASE] Rebase triggered by rinx for branch: performance/agent/use-userdefined-gc-call

@vdaas-ci vdaas-ci force-pushed the performance/agent/use-userdefined-gc-call branch from 2b950ac to 7ea859e Compare September 9, 2020 08:44
@github-actions github-actions bot added size/M and removed size/S labels Sep 10, 2020
@kpango kpango changed the title [WIP] {Please Do not merge}. use runtime.GC for reducing indexing memory Use runtime.GC for reducing indexing memory & replace saveMu with atomic busy loop for race control Sep 10, 2020
@rinx
Copy link
Contributor

rinx commented Sep 10, 2020

How do you think about this comment? @kpango
#682 (comment)

@github-actions github-actions bot added team/set SET team size/XL and removed size/M labels Sep 10, 2020
@kpango
Copy link
Collaborator Author

kpango commented Sep 10, 2020

sounds nice, I'll do that for now, by the way could you please test this branch?

@kpango
Copy link
Collaborator Author

kpango commented Sep 10, 2020

@rinx do we need divide enbale/disable configuration into before and after?
I just think about define the single configuration like a enableProactiveGC.

saveMu sync.Mutex // creating or saving index
indexing atomic.Value
saving atomic.Value
lastNoice uint64 // last number of create index execution this value prevent unnecessary saveindex.
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! 👍

@rinx
Copy link
Contributor

rinx commented Sep 10, 2020

I just think about define the single configuration like a enableProactiveGC.

I've just imagined it like that. 👍

@vdaas-ci
Copy link
Collaborator

[WARNING:INTCFG] Changes in interal/config may require you to change Helm charts. Please check.

fix
Signed-off-by: kpango <[email protected]>
@kpango kpango force-pushed the performance/agent/use-userdefined-gc-call branch from 4a5ff85 to c22261d Compare September 10, 2020 03:24
kpango added 2 commits September 10, 2020 12:25
fix
Signed-off-by: kpango <[email protected]>
fix
Signed-off-by: kpango <[email protected]>
@kpango
Copy link
Collaborator Author

kpango commented Sep 10, 2020

@rinx could you please review it? you don't need to review test code it's generated by make gotest/patch

fix
Signed-off-by: kpango <[email protected]>
fix
Signed-off-by: kpango <[email protected]>
fix
Signed-off-by: kpango <[email protected]>
*/
}

for _, test := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: range var test copies lock: github.com/vdaas/vald/internal/observability/metrics/db/kvs/redis.test contains github.com/vdaas/vald/internal/observability/metrics/db/kvs/redis.fields contains sync.Mutex (govet)

pipelineLatency: test.fields.pipelineLatency,
cmdNameKey: test.fields.cmdNameKey,
numCmdKey: test.fields.numCmdKey,
mu: test.fields.mu,
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: literal copies lock value from test.fields.mu: sync.Mutex (govet)

*/
}

for _, test := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: range var test copies lock: github.com/vdaas/vald/internal/observability/metrics/db/kvs/redis.test contains github.com/vdaas/vald/internal/observability/metrics/db/kvs/redis.fields contains sync.Mutex (govet)

pipelineLatency: test.fields.pipelineLatency,
cmdNameKey: test.fields.cmdNameKey,
numCmdKey: test.fields.numCmdKey,
mu: test.fields.mu,
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: literal copies lock value from test.fields.mu: sync.Mutex (govet)

*/
}

for _, test := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: range var test copies lock: github.com/vdaas/vald/internal/observability/metrics/db/kvs/redis.test contains github.com/vdaas/vald/internal/observability/metrics/db/kvs/redis.fields contains sync.Mutex (govet)

}

func Test_mysqlMetrics_View(t *testing.T) {
type fields struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
struct of size 56 bytes could be of size 48 bytes (maligned)

*/
}

for _, test := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: range var test copies lock: github.com/vdaas/vald/internal/observability/metrics/db/rdb/mysql.test contains github.com/vdaas/vald/internal/observability/metrics/db/rdb/mysql.fields contains sync.Mutex (govet)

*/
}

for _, test := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: range var test copies lock: github.com/vdaas/vald/internal/observability/metrics/db/rdb/mysql.test contains github.com/vdaas/vald/internal/observability/metrics/db/rdb/mysql.fields contains sync.Mutex (govet)

*/
}

for _, test := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
copylocks: range var test copies lock: github.com/vdaas/vald/internal/observability/metrics/db/rdb/mysql.test contains github.com/vdaas/vald/internal/observability/metrics/db/rdb/mysql.fields contains sync.Mutex (govet)

@@ -3604,31 +3843,208 @@ func Test_ngt_insertCache(t *testing.T) {
}
}

func Test_ngt_IsSaving(t *testing.T) {
type fields struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
struct of size 248 bytes could be of size 224 bytes (maligned)

charts/vald/values.yaml Outdated Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Show resolved Hide resolved
@rinx
Copy link
Contributor

rinx commented Sep 10, 2020

Others LGTM.
The CI run for Helm lint is failed because of Helm's bug. so please ignore it.

@rinx
Copy link
Contributor

rinx commented Sep 10, 2020

and please write the description of this PR.

Co-authored-by: Rintaro Okamura <[email protected]>
@kpango kpango merged commit ca48e44 into master Sep 11, 2020
@kpango kpango deleted the performance/agent/use-userdefined-gc-call branch September 11, 2020 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants