Embedded Scryer memory leak mitigations, experiments, and results #2566
Replies: 2 comments 1 reply
-
This is fine for the embedded use case (where the host language controls the world) if you can always just use a new machine for every query, but if it's Prolog controlling the world there is no easy way to clean the atom table (and therefore partial strings) yet apart from restarting the whole process. This also adds a bunch of latency of creating a whole machine for each query. |
Beta Was this translation helpful? Give feedback.
-
Scryer is indeed perfectly well suited for many different usage modes and applications. The issue is: Scryer cannot be exhaustively tested due its memory leaks! For example, the following leaks memory, but should not leak memory:
A key performance attraction of Prolog is that memory can be quickly reclaimed on backtracking, even without GC! The above case should reclaim the allocated memory, and no GC is needed for that. Memory reclamation on backtracking is a necessary condition to run exhaustive tests. EDIT: Please check out the newly available rebis-dev development branch which addresses these issues, see also the announcement: #2569! |
Beta Was this translation helpful? Give feedback.
-
Using the following Python script, I wanted to see what the consequences of Scryer memory growth were before, during, and after cleanup of the WAM. I was really happy with the results.
Script
Results from testing embedded Scryer instantiating multiple WAMs and then allowing them to be GC'd, I am very happy with the results:
Console Output:
Results
Final memory scores mean, "memory usage just before GC'ing the WAM", and GC means memory AFTER GC'ing the WAM. (please refer to the source code if this explanation is confusing)
The great news from my perspective is that even within the same parent process, spawning and GC'ing WAMs is a very effective technique at managing memory. I will continue you to do more tests, I am curious how much that final GC number would continue to rise, but there are many many reasons that could account for the small different in memory size.
To me this indicates any insinuation that Scryer should not be used because of "memory leaks" is an extremely silly argument -- the results are pretty conclusive that even in the worst case the memory growth is not extremely significant and cycling the WAM clears it out easily. The difficulty of implementing this pattern should be no harder for an average developer than making a REST API call.
Obviously GC will be wonderful when it happens, but it's already looking pretty wonderful, even in the worst case scenario!
Beta Was this translation helpful? Give feedback.
All reactions