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

fix: Peek OOM and performance issue #335

Merged
merged 3 commits into from
Jun 7, 2024
Merged

Conversation

xiaost
Copy link
Contributor

@xiaost xiaost commented Jun 6, 2024

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

修复 Peek 调用导致的性能与内存问题

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
Originally, when we have data in more than one linkBufferNode,
Each Peek call will create a new buffer for returning data, and put it in cache list.
when the data grows larger, it would cause OOM if we can't release the cache in time.
This PR will reuse a cachePeek for Peek for memory and performance friendly, especially peeking a large buffer.
The Next method can also use the implementation like this one when it becomes stable.

zh(optional):
在原来的实现里面,我们如果数据存放在多于一个的 linkBufferNode
那么每次的 Peek 调用都会新建一个buffer来返回数据,并且会放在cache列表里。
当数据增长,这会导致OOM问题,如果我们不能及时回收cache里的数据。
这个PR对于Peek调用会复用一个cachePeek,对内存和性能更为友好,特别是peek数据量大的场景。
当这个实现稳定后,Next 方法也可以使用这方式来优化内存占用。

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@xiaost xiaost requested review from a team as code owners June 6, 2024 10:03
@xiaost xiaost changed the title fix: Peek oom and performance issue fix: Peek OOM and performance issue Jun 6, 2024
nocopy_linkbuffer.go Outdated Show resolved Hide resolved
@joway
Copy link
Member

joway commented Jun 7, 2024

the optimization I think only works on Peek? Next will not access a buffer twice so cannot be cached

@joway joway merged commit c4ec256 into cloudwego:develop Jun 7, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants