pin_upload memory use grows with file size

Offen Anfängerfreundlich
#367 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
data

Rechercherichtung

Lies zuerst Version.from_files und Version.hash_file, die der Issue als wahrscheinliche Ursache für den starken Speicheranstieg nennt. Prüfe, wie block_size verwendet wird und warum der Standardwert -1 ist, und führe dann die relevanten Hash- und Upload-Tests aus. Das Ziel ist erreicht, wenn das Hochladen einer großen Datei ungefähr konstant viel Speicher benötigt und dabei der erwartete Pin-Versionshash erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Python
Sterne
59
Forks
11
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus rstudio/pins-python

Alle Issues in rstudio/pins-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.