Use async iterators to ensure leveldb iterators are always closed #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After running
y-websocket-serverwith a moderate load (e.g. 12 concurrent clients) for some hours, the memory it used grew to around 4GB. On investigation, this was due to (a)yDocsnot being disposed of after use (see the y-websocket-server PR#7 (b) levelDB iterators not being properly destroyed iny-leveldb. This PR deals with the latter. In combination, the changes result in a reduction in memory use (rss=) from about 3950MB to 1100MB under identical conditions, with the memory used by levelDB reducing from about 1500MB to 4MB.This dramatic reduction in
leveldbmemory is achieved by using native iterators for the bulk functions such asgetLevelBulkEntries, and providing some explicit memory thresholds for its cache to guard against excessive memory use (the values should be adequate for most loads).There are no consequent changes to the
y-leveldbinterface - this version is a drop in replacement for the old.The inline documentation has also been rationalised.