I have a Python file:
from concurrent.futures import ProcessPoolExecutor
import tarfile, rapidgzip
def processNdjson(ndjsonName):
with rapidgzip.open(inTarDir) as myZip:
myZip.import_index(rapidgzipDir)
with tarfile.open(fileobj=myZip, mode="r:*") as f:
member = f.getmember(ndjsonName)
dataFile = f.extractfile(member)
for oneLine in dataFile:
# process oneLine here
if __name__ == "__main__":
rapidgzipDir = ...
inTarDir = ...
nCore = 5
ndjsonNames = ["name1.ndjson", "name2.ndjson"]
with ProcessPoolExecutor(nCore) as pool:
results = pool.map(worker, ndjsonNames)
Above,
inTarDir is the directory to a .tar.gz file that contains multiple .ndjson files.
rapidgzipDir is the pre-index file to be used by rapidgzip. This allows fast random access and is a drop-in replacement for the built-in Python gzip.GzipFile.
- Each process will
with rapidgzip.open(inTarDir) as myZip:
myZip.import_index(rapidgzipDir)
with tarfile.open(fileobj=myZip, mode="r:*") as f:
My concern: each command myZip.import_index(rapidgzipDir) will take up a certain amount of RAM (for example, 500MB for a 20GB .tar.gz file). This will grow linearly with nCore.
It would be great of we can load rapidgzipDir once into some index_map object in the memory. Then every with rapidgzip.open(inTarDir) as myZip in each worker can use this index_map object.
Thank you for your consideration.
I have a Python file:
Above,
inTarDiris the directory to a .tar.gz file that contains multiple .ndjson files.rapidgzipDiris the pre-index file to be used byrapidgzip. This allows fast random access and is a drop-in replacement for the built-in Pythongzip.GzipFile.My concern: each command
myZip.import_index(rapidgzipDir)will take up a certain amount of RAM (for example, 500MB for a 20GB .tar.gz file). This will grow linearly withnCore.It would be great of we can load
rapidgzipDironce into someindex_mapobject in the memory. Then everywith rapidgzip.open(inTarDir) as myZipin each worker can use thisindex_mapobject.Thank you for your consideration.