I need to scan very large JSONL files efficiently and am considering a parallel grep-style approach over line-delimited text.

Would love to hear how you would design it.

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    2
    ·
    22 hours ago

    I think, you could open the same file multiple times and then just skip ahead by some number of bytes before you start reading.

    But yeah, no idea if this would actually be efficient. The bottleneck is likely still the hard drive and trying to fit multiple sections of the file into RAM might end up being worse than reading linearly…

    • Bazell@lemmy.zip
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      21 hours ago

      This approach will indeed hit bottleneck even in SSD. Thus, file can be read into RAM line by line in thread 0, then once specified amount of lines was gathered, schedule thread 1 to process them, while thread 0 still reads new lines. Once another chunk is ready, give to thread 2 and so on. This way you can start processing data in asynchronous regime in the fastest way possible. Slightly slower but more convenient approach is to firstly read all the file into RAM and only then assign parts of it to each thread at the same time.