-
Notifications
You must be signed in to change notification settings - Fork 792
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: bug: memory leak when using bentoml>=1.2 #4775
Conversation
Do you think we need to reuse the temp directories across different requests, i.e. to use a temp dir pool. Is that overkill? |
It's not recommended, I think. I prefer to make a tmp directory when it's usable like it's a file style request. Rather than that, I think it would be waste to make a tmp directory for every request |
I think maybe we don't need a directory per request? We can group by the directory by thread/process id, and all the request file in the same directory? |
Yes, that is exactly what this PR does. The creation is lazy. |
Yep, I got it. But I might have another idea here
|
But we would also need to clean it periodically or its size will keep growing. The purpose of the temp dir is to isolate the store path for each request which is handled in coroutines, so using a process id/thread id wouldn't work. The same process and thread may be handling more than one request concurrently. For example, it makes the following work: @bentoml.api
def predict(self, input: int, ctx: bentoml.Context) -> Path:
output_path = Path(ctx.temp_dir, "output.txt") # this file shouldn't be overwritten by other request
with open(output_path, 'wb') as f:
f.write(some_bytes)
return output_path |
oh I got your means, you want to the developer following the common conventions like all files during request in the same directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
How about we just use a mem file instead? say pyfakefs or just use fssepc to create a memory file system. |
That would be better, but our goal is to provide a seamless experience so users can save files using the familiar |
mem file is also an impl of a file interface. And use it as the impl of |
I am afraid not, many inference functions expect a string as the input or output path. And we will lose the memfile magic. |
hmm can we use memfile and still offer pathlib-like API here? I guess that FS API is actually not very well known afaict |
but |
Fixes bentoml#4760 Signed-off-by: Frost Ming <me@frostming.com>
Signed-off-by: Frost Ming <me@frostming.com>
Signed-off-by: Frost Ming <me@frostming.com>
Signed-off-by: Frost Ming <me@frostming.com>
6194027
to
725ba54
Compare
Signed-off-by: Frost Ming <me@frostming.com>
Fixes #4760
Signed-off-by: Frost Ming me@frostming.com
What does this PR address?
Change the request temp dir to create on demand.
/cc @Zheaoli @gusghrlrl101