pin_upload memory use grows with file size

Aperta Adatta ai principianti
#367 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Inizia leggendo Version.from_files e Version.hash_file, che l’issue identifica come probabile causa del picco di memoria. Controlla come viene usato block_size e perché il suo valore predefinito è -1, poi esegui i test pertinenti di hash e caricamento. Il lavoro è completato quando il caricamento di un file grande usa una quantità di memoria pressoché costante, preservando l’hash di versione del pin previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Scenario

I use Polars to process data frames that are larger than available memory. Polars streams the work and writes the result straight to a parquet file on disk, so the data is never fully in memory. The file is published with pin_upload to an S3 board.

We expected the upload to stream the file as well. Instead, memory use during pin_upload grows with the file size. Our largest file is larger than available memory and the process is killed during the upload.

From a quick look, the spike seems to come from computing the pin version hash. Version.from_files calls Version.hash_file without a block_size, and the default of -1 reads the whole file in one call. hash_file already loops over chunks, so passing a fixed block_size, or changing the default, might be enough. I may be missing context on why the default is -1.

Reproducible example

import os
import resource
import tempfile

import pins

with tempfile.TemporaryDirectory() as d:
    path = os.path.join(d, "big.bin")
    with open(path, "wb") as f:
        for _ in range(1024):  # 1 GiB, written in 1 MiB chunks
            f.write(os.urandom(1024**2))

    before = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
    board = pins.board_temp()
    board.pin_upload(paths=[path], name="big")
    after = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
    print(f"peak RSS before: {before}, after: {after}")  # grows by about 1 GiB

On macOS (ru_maxrss is in bytes), peak RSS grows from about 35 MiB to about 1,059 MiB. When hash_file is patched to use an 8 MiB block_size, the peak only reaches about 50 MiB.

Expected behavior

Uploading a file should use roughly constant memory regardless of file size.

Environment

  • pins 0.9.2
  • Python 3.12
  • S3 board through s3fs
Lingua principale
Python
Stelle
59
Fork
11
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rstudio/pins-python

Tutte le issue di rstudio/pins-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.