-
Curious what do you think would be the best way to implement something like a temporary table for sorting. Imagine we have data in LMDB and want to sort it by some field but we only use the result once and then throw it away (the result is needed for 2-5 seconds at most). We can load the data in memory and sort it in node heap but this will lead to a big memory spike. Instead, I've been thinking about just using some The idea is to write there while iterating LMDB cursor with the original data, then do another iteration on values and then remove the Not sure if it makes sense. But if it does - the next question is how to avoid persisting this value to disk - what would be preferable - |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If you are using this purely to build a table to sort and then immediately removing, you might consider using a child transaction to build the table and then aborting it once you are done instead of committing it. However, if you need this table to last longer (even 2-5 seconds is a long time to keep a transaction open) for additional interaction, running with |
Beta Was this translation helpful? Give feedback.
-
I did a quick and dirty benchmark and looks like it is a viable approach. Setup: 1,000,000 objects stored in lmdb Option 1: load all objects in memory and sort in JS, then iterate final array:
Option 2: iterate and put to
This is amazing 😲 The caveat is that in the 2nd approach we only have partial data and may need to load full objects again. But in our use case, we need maybe 100 "full" objects after sorting (with |
Beta Was this translation helpful? Give feedback.
If you are using this purely to build a table to sort and then immediately removing, you might consider using a child transaction to build the table and then aborting it once you are done instead of committing it.
However, if you need this table to last longer (even 2-5 seconds is a long time to keep a transaction open) for additional interaction, running with
noSync
does seem like a good idea. Setting a largecommitDelay
wouldn't accomplish much, that just delays the transaction you want to start (it delays the start of the transaction too). RunningnoSync
in combination withuseWritemap
seems like it would most ideal if you want to keep the table alive for a little while (I was seeing s…