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: Reduce memory usage when publishing prediction log to kafka #525

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

tiopramayudi
Copy link
Contributor

@tiopramayudi tiopramayudi commented Jan 29, 2024

Description

We've seen gradual increase of memory usage when model observability is enabled for a model.

First hypothesis why this happened is due to using asyncio, because we pass prediction input and output to the async function. We try to prove it by reducing sampling rate to 0, since the async function that being called need to publish to kafka, so we need to isolate this only for asyncio overhead. After set sampling rate to 0 the memory usage is stable there is no gradual increase

Since first hypothesis is not correct, we have new hypothesis that this is due to publishing the data to kafka, and we did memory profiler to the model

PS: We use memray as profiler https://github.com/bloomberg/memray

Screen Shot 2024-01-29 at 09 47 21 Screen Shot 2024-01-29 at 09 49 11 Screen Shot 2024-01-29 at 09 48 52

We see that the memory usage is keep increasing and producing the message to kafka contribute to this.

Modifications

To solve this problem, kafka producer must call poll after publish the message, this is necessary so ack buffer from producer will be drained and the memory usage won't gradually increase, ref: 1 , 2

After the changes
Screen Shot 2024-01-29 at 09 49 02

Screen Shot 2024-01-29 at 09 49 19

Tests

Checklist

  • Added PR label
  • Added unit test, integration, and/or e2e tests
  • Tested locally
  • Updated documentation
  • Update Swagger spec if the PR introduce API changes
  • Regenerated Golang and Python client if the PR introduces API changes

Release Notes


@tiopramayudi tiopramayudi self-assigned this Jan 29, 2024
@ghost
Copy link

ghost commented Jan 29, 2024

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@khorshuheng khorshuheng added the bug Something isn't working label Jan 29, 2024
Copy link
Collaborator

@khorshuheng khorshuheng left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@ariefrahmansyah
Copy link
Contributor

On a separate note, what tool are you using for memory profiling? @tiopramayudi

@tiopramayudi
Copy link
Contributor Author

On a separate note, what tool are you using for memory profiling? @tiopramayudi

I use memray as profiler https://github.com/bloomberg/memray

@tiopramayudi tiopramayudi merged commit e97330c into main Jan 29, 2024
32 of 33 checks passed
@tiopramayudi tiopramayudi deleted the memory-leak branch January 29, 2024 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants