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
memory leak in cuecontext.CompileString? #1424
Comments
Maybe reuse the same cuecontext ? You don't need to create a new one everytime. |
I don't believe this is a memory leak as much as the shared index building up over time and not releasing memory. The evaluator currently has some global stuff which is why you cannot perform certain operations without locking and the memory footprint will increase indefinitely. At this point, you will have to do hacky things for long running CUE processes. (i.e. gracefully restart the server every so often and run enough copies to keep the API available) If you are using the same schema on every call, it will be beneficial to parse it once and reuse it in subsequent calls. note, this is expected to change over time. there are other issues tracking these features |
@verdverm thanks for your answer. I'm going to try to solve this problem by calling cue directly, although the performance will be worse |
I have tried this method, and the problem is still there but not as severe as before |
// sharedIndex is used for indexing builtins and any other labels common to
// all instances.
var sharedIndex = newIndex() instances built by runtime are used by the global variable |
maybe this fix could help (on your own risk): https://github.com/lipence/cue/commit/6ed69100ebd62509577826657536172ab46cf257
|
it works! |
I kind of think #1418 is better in that it raises the idea of letting users configure the index scope.
I don't think CUE can necessarily infer when I may be done with a value, so we probably need a way for users to control this due to the memory pressure the current behavior creates. |
@kentalee: yes, that is indeed the problem. There was some reason why this wasn't done yet exactly as you said. I think part of the issue was that builtins could not yet be treated the same way, even though this is not possible yet and then a proper fix for the packages, at least, dropped off the radar. @eonpatapon: in this case, to avoid growing memory, one actually _should _create a new Context on each iteration. The problem is indeed as @kentalee identified. |
i use the goapi in my server In the same way as above. However, I found that frequent calls to 'CompileString' led to uncontrolled memory.
Maybe I'm using it wrong. Who can tell me how to use the api correctly
The text was updated successfully, but these errors were encountered: