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

[patch] add C.free & delete ivc before core.BulkInsert C' function executing for reducing memory usage #701

Merged
merged 8 commits into from
Sep 17, 2020

Conversation

kpango
Copy link
Collaborator

@kpango kpango commented Sep 15, 2020

Signed-off-by: kpango i.can.feel.gravity@gmail.com

Description:

this PR includes 3 fixes

  1. move ivc.Delete operation befor core/ngt.BulkInsert operation
  2. add C.free for fixing memory leaks
  3. small dependencies updates.

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.15.2
  • 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.

@pull-assistant
Copy link

pull-assistant bot commented Sep 15, 2020

Score: 0.52

Best reviewed: commit by commit


Optimal code review plan (2 warnings, 4 commits squashed)

[patch] add C.free &... ... fix

Squashed 4 commits:

go.mod 67% changes removed in fix

go.sum 83% changes removed in fix

fix

go.mod 50% changes removed in fix

     fix

     fix

     fix

Powered by Pull Assistant. Last update 9e1eed8 ... 0a0c104. Read the comment docs.

@vdaas-ci
Copy link
Collaborator

[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

cvec := (*C.float)(&vec[0])
defer C.free(unsafe.Pointer(cvec))
csize := *(*C.size_t)(unsafe.Pointer(&size))
defer C.free(unsafe.Pointer(&csize))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

csize := *(*C.size_t)(unsafe.Pointer(&size))
defer C.free(unsafe.Pointer(&csize))
cepsilon := *(*C.float)(unsafe.Pointer(&epsilon))
defer C.free(unsafe.Pointer(&cepsilon))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

cepsilon := *(*C.float)(unsafe.Pointer(&epsilon))
defer C.free(unsafe.Pointer(&cepsilon))
cradius := *(*C.float)(unsafe.Pointer(&radius))
defer C.free(unsafe.Pointer(&cradius))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

@codecov
Copy link

codecov bot commented Sep 15, 2020

Codecov Report

Merging #701 into master will decrease coverage by 0.23%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #701      +/-   ##
==========================================
- Coverage   15.64%   15.40%   -0.24%     
==========================================
  Files         418      418              
  Lines       22240    22191      -49     
==========================================
- Hits         3479     3419      -60     
- Misses      18523    18528       +5     
- Partials      238      244       +6     
Impacted Files Coverage Δ
pkg/agent/core/ngt/service/ngt.go 0.00% <0.00%> (ø)
internal/db/nosql/cassandra/option.go 9.81% <0.00%> (-20.27%) ⬇️
internal/worker/queue.go 95.65% <0.00%> (-4.35%) ⬇️
internal/errors/option.go 0.00% <0.00%> (ø)
internal/worker/worker.go 84.54% <0.00%> (ø)
internal/db/nosql/cassandra/cassandra.go 0.00% <0.00%> (ø)

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 1bd41ef...0a0c104. Read the comment docs.

Copy link
Contributor

@rinx rinx left a comment

Choose a reason for hiding this comment

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

Overall looks good

internal/core/ngt/ngt.go Outdated Show resolved Hide resolved
internal/core/ngt/ngt.go Outdated Show resolved Hide resolved
@kpango
Copy link
Collaborator Author

kpango commented Sep 16, 2020

If I end up in a test environment e2e breathing, I will remove the comment out block.

@rinx
Copy link
Contributor

rinx commented Sep 16, 2020

okay

@@ -454,8 +483,10 @@ func (n *ngt) SaveIndex() error {

// Remove removes from NGT index.
func (n *ngt) Remove(id uint) error {
oid := C.ObjectID(id)
defer C.free(unsafe.Pointer(&oid))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

@@ -470,7 +501,9 @@ func (n *ngt) Remove(id uint) error {
func (n *ngt) BulkRemove(ids ...uint) error {
n.mu.Lock()
for _, id := range ids {
if C.ngt_remove_index(n.index, C.ObjectID(id), n.ebuf) == ErrorCode {
oid := C.ObjectID(id)
defer C.free(unsafe.Pointer(&oid))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

results,
n.ebuf)
defer C.free(unsafe.Pointer(&ret))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

@@ -302,12 +316,16 @@ func (n *ngt) Search(vec []float32, size int, epsilon, radius float32) ([]Search
n.mu.RUnlock()

rsize := int(C.ngt_get_result_size(results, n.ebuf))
defer C.free(unsafe.Pointer(&rsize))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

id := C.ngt_insert_index_as_float(n.index, (*C.float)(&vec[0]), C.uint32_t(n.dimension), n.ebuf)
defer C.free(unsafe.Pointer(&id))
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 🐶
dupSubExpr: suspicious identical LHS and RHS for == operator (gocritic)

@@ -214,12 +214,14 @@ func (n *ngt) create() (err error) {
return err
}
}
path := C.CString(n.idxPath)
defer C.free(unsafe.Pointer(path))
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 🐶
only one cuddle assignment allowed before defer statement (wsl)

rinx
rinx previously approved these changes Sep 17, 2020
Copy link
Contributor

@rinx rinx left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango
Copy link
Collaborator Author

kpango commented Sep 17, 2020

/rebase
/format

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kpango for branch: bugfix/internal-agent/reduce-memory-usage

@vdaas-ci
Copy link
Collaborator

[FORMAT] Updating license headers and formatting go codes triggered by kpango.

@github-actions github-actions bot added size/L and removed size/M labels Sep 17, 2020
@kpango
Copy link
Collaborator Author

kpango commented Sep 17, 2020

/rebase

@vdaas-ci
Copy link
Collaborator

[REBASE] Rebase triggered by kpango for branch: bugfix/internal-agent/reduce-memory-usage

kpango added 5 commits September 17, 2020 05:16
…ecuting for reducing memory usage

Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
kpango added 2 commits September 17, 2020 05:16
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
@vdaas-ci vdaas-ci force-pushed the bugfix/internal-agent/reduce-memory-usage branch from 76353fa to 3a39dbd Compare September 17, 2020 05:16
fix
Signed-off-by: kpango <i.can.feel.gravity@gmail.com>
@kpango kpango merged commit e8a1c63 into master Sep 17, 2020
@kpango kpango deleted the bugfix/internal-agent/reduce-memory-usage branch September 17, 2020 05:21
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.

None yet

3 participants