Skip to content
Snippets Groups Projects

cube.r

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Dirk Sarpe

    Read bunch of csvs and roll the data dice.

    Edited
    cube.r 361 B
    library(data.table)
    library(parallel)
    
    files <- commandArgs(trailingOnly = TRUE)
    nlines <- 731759
    
    reader <- function(file) {
      fread(file, header = TRUE, colClasses = rep("double", 16))
    }
    
    
    cl <- makeForkCluster()
    files.content <- parSapplyLB(cl, files, reader)
    vfiles.content <- unlist(files.content, recursive = FALSE)
    dim(vfiles.content) <- c(nlines, 16, 6)
    • Habs ein wenig angepasst. Die Konvertierung lasse ich auf idiv2 gerade mit Marias Daten laufen. Braucht natürlich 185 GiB Arbeitsspeicher, ist auf dem Server aber kein Problem. Was tatsächlich am längsten dauert, ist das saveRDS, das läuft mit 100% CPU und schreibt mit 18-20 MB/s ins GPFS, jeweils 9/10 OPS, also in 2 MB chunks. Schneller scheint saveRDS irgendwie nicht zu sein.

      library(data.table)
      library(parallel)
      
      files <- commandArgs(trailingOnly = TRUE)
      
      nlines <- 731759
      nyears <- 17
      
      reader <- function(file) {
        cat(paste("fread", file, "...\n"))
        fread(file, header = TRUE, colClasses = rep("double", nyears), showProgress = FALSE)
      }
      
      cl <- makeForkCluster(outfile = "")
      
      csvs <- parSapplyLB(cl, files, reader)
      
      cat("csvs size: ")
      print(object.size(csvs), units = 'auto', standard = 'IEC')
      
      cube <- unlist(csvs, recursive = FALSE)
      
      dim(cube) <- c(nlines, nyears, length(files))
      
      cat("cube size: ")
      print(object.size(cube), units = 'auto', standard = 'IEC')
      
      cat(paste("saving cube ...\n"))
      
      saveRDS(cube, file = '/work/admchkr/cube.rds')
    • Leider sehr groß:

      $ ls -lh /work/admchkr/cube.rds
      -rw-r--r-- 1 admchkr root 89G Mar  6 16:06 /work/admchkr/cube.rds

      Einlesen dauert auch ne Weile:

      > system.time(a <- readRDS("/work/admchkr/cube.rds"))
         user  system elapsed
      825.933  71.411 898.730
      
      > dim(a)
      [1] 731759     17   1000
    • 89 GB in 15 Minuten entspräche ~100 MB/s. Nicht glamorös aber nunja.

      Was war die Summe Dateigrößen der csvs?

    • $ du -ch /work-local/maria/*.csv | tail -1
      222G    total

      Hab jetzt den cube nochmal ohne compression gespeichert, macht von der Größe nicht viel:

      $ ll /work/admchkr/cube*.rds
      -rw-r--r-- 1 admchkr root 93G Mar  6 18:30 /work/admchkr/cube-nozip.rds
      -rw-r--r-- 1 admchkr root 89G Mar  6 16:06 /work/admchkr/cube.rds
    • Das unkomprimierte is auch'n bisl schneller beim Lesen:

      > system.time(a <- readRDS("/work/admchkr/cube-nozip.rds"))
         user  system elapsed
      147.578  65.847 217.654
    • gpfs monitoring hatte dazu gesagt ~ 450 MB/s bei genau der Hälfte OPS, d.h. 2 MB read buffer size. Das ist ein sehr gutes Zeichen. Ich hatte das vorhin auch beim saveRDS beobachtet, dass er da genau die Blockgröße vom FS verwendet hat.

    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment