apache / apache/arrow

[R] arrow::open_dataset %>% select(myvars) %>% collect causes memory leak

Aperta
#33,366 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Priority: Critical Type: bug
Lingua principale
C++
Stelle
17.1k
Fork
4.3k
Merge medio
3g 23h
PR unite (30g)
101

Descrizione

I first posted on StackOverlow, [here.](https://stackoverflow.com/questions/74221492/r-arrow-open-dataset-selectmyvars-collect-causing-memory-leak)

I am having trouble using arrow in R. First, I saved some `data.tables` that were about 50-60Gb (`{}d{`} in the code chunk) in memory to a parquet file using:
 
`d %>% write_dataset(f, format='parquet') # f is the directory name`

Then I try to read open the file, select the relevant variables and
 
`tic()d2 <- open_dataset(f) %>% select(all_of(myvars)) %>% collect #myvars is a vector of variable namestoc()`

I did this conversion for 3 sets of data.tables (unfortunately, data is confidential so I can't include in the example). In one set, I was able to `open>select>collect` the desired table in about 60s, obtaining a 10Gb file (after variable selection).

For the other two sets, the command caused a memory leak. tic()-toc() returned after 80s. But the object name (d2) never appeared in Rstudio's "Enviroment panel", and memory used keeps creeping up until it occupied most of the available RAM of the server, and then R crashed. Note the orginal dataset, without subsetting cols, was smaller than 60Gb and the server had 512GB.

Any ideas on what could be going on here?

UPDATE: today I noticed a few more things.

1) If the collected object is small enough (3 cols, 66million rows), R will unfreeze. The console becomes responsive, the object shows up in the Environment panel. But memory use keeps going up (by small amounts because the underlying that is small). While this is helpening, issuing a gc() command reduces the memory use, but it then starts growing again.

2) Even after "rm(d2)" and  "gc()", the R session that issued the arrow commands still use around 60-70Gb of RAM... The only way to end that is to close the R session. 

3) I am using arrow 10.0.0

 

 

 

**Reporter**: [Lucas Mation](https://issues.apache.org/jira/browse/ARROW-18176) / @lucasmation
#### Related issues:
- [[R] Substantial RAM use increase in 9.0.0 release on write_dataset()](https://github.com/apache/arrow/issues/32795) (relates to)

**Note**: *This issue was originally created as [ARROW-18176](https://issues.apache.org/jira/browse/ARROW-18176). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo il workflow R 10.0.0 segnalato con open_dataset(f) %>% select(all_of(myvars)) %>% collect, usando dataset abbastanza grandi da mostrare la crescita della memoria. L’issue non indica file o test del repository; il lavoro sarà considerato completato quando sarà identificata la causa della memoria trattenuta e sarà dimostrato che la memoria viene rilasciata dopo la raccolta e la pulizia.

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

Valutazione

Stack tecnologico
r
Ambito
data
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.