Closed expelledboy closed 7 months ago
Alternatively, if you could create a test release with https://github.com/CertainLach/jrsonnet/pull/122 I could continue with my other method of calling jrsonnet
as a binary
We have identified the leak comes from ContextInitializer::new
the actual line that leaks in the above code is this:
let ctx = ContextInitializer::new(state.clone(), PathResolver::new_cwd_fallback());
I think there must be some sort of circular reference or something like that in this ContextInitializer
code.
I think there must be some sort of circular reference or something like that in this ContextInitializer code.
Yes, there is, jrsonnet uses garbage collection for such links.
You can force garbage collection of current thread reference cycles using jrsonnet_gcmodule::collect_thread_cycles()
call.
Regarding State is not Sync
- jrsonnet internal structures aren't thread-safe (This isn't unique to jrsonnet, all jrsonnet implementations aren't thread-safe, even go-jsonnet: https://github.com/google/go-jsonnet/issues/733), you can use I.e thread_local for this, but I would recommend you to start jrsonnet in separate process, especially if you plan to limit code in RAM/CPU usage.
Thanks! The process is run in a Thread by tokio, so I just needed to run jrsonnet_gcmodule::collect_thread_cycles();
and now we are not getting any memory leaks.
We really appreciate your rapid response! We pushing to production any day now, and this was a major issue. 😅
I am trying to use jrsonnet as lib in an HTTP wrapper to improve performance in a high TPS system.
However we have just deployed the service and its experiencing a memory leak.
This is the util module I created, and a test which demonstrates how I use the API.
This gets called in the following
tokio
API handler:This is my first crack at writing a system in Rust. Perhaps I am doing something wrong. Either, there a memory leak in the code above, or in
jrsonnet
itself.If I could clone
context
and supply it to the decode function I could perhaps circumvent the memory leak. However I am getting the follow error when trying to do so:Is there any obvious issue with my code?
Or is there anyway I can clone the context?