【问题标题】:fread() run time is taking longer than reported speedfread() 运行时间比报告的速度长
【发布时间】:2018-04-29 06:16:01
【问题描述】:

我正在尝试将一个大文件读入 EC2 实例上的 R。但是,在读取某些数据后,我遇到的运行时间远远长于 fread 报告的时间。

例如,当我只读取我的 csv 文件的第一行数据时,我得到了 fread 的 verbose=TRUE 输出。如您所见,报告的运行时间比实际运行时间短得多。你知道为什么会这样吗?有什么方法可以加快这个过程,使其更符合读取数据后读取报告的运行时?

> start_time <- Sys.time()
> fread(file_name_1, nrows=1, verbose=TRUE)
Input contains no \n. Taking this to be a filename to open
File opened, filesize is 68.770914 GB.
Memory mapping ... ok
Detected eol as \n only (no \r afterwards), the UNIX and Mac standard.
Positioned on line 1 after skip or autostart
This line is the autostart and not blank so searching up for the last non-blank ... line 1
Detecting sep ... ','
Detected 55 columns. Longest stretch was from line 1 to line 30
Starting data input on line 1 (either column names or first row of data). First 10 characters: bank_num,b
All the fields on line 1 are character fields. Treating as the column names.
nrow set to nrows passed in (1)
Type codes (point  0): 1114434134111034444411333333333333333333333333333311111
Type codes: 1114434134111034444411333333333333333333333333333311111 (after applying colClasses and integer64)
Type codes: 1114434134111034444411333333333333333333333333333311111 (after applying drop or select (if supplied)
Allocating 55 column slots (55 - 0 dropped)
Read 1 rows and 55 (of 55) columns from 68.771 GB file in 00:00:27
Read 1 rows. Exactly what was estimated and allocated up front
  26.480s (100%) Memory map (rerun may be quicker)
   0.000s (  0%) sep and header detection
   0.000s (  0%) Count rows (wc -l)
   0.000s (  0%) Column type detection (100 rows at 10 points)
   0.000s (  0%) Allocation of 1x55 result (xMB) in RAM
   0.000s (  0%) Reading data
   0.000s (  0%) Allocation for type bumps (if any), including gc time if triggered
   0.000s (  0%) Coercing data already read in type bumps (if any)
   0.000s (  0%) Changing na.strings to NA
  26.480s        Total
> end_time <- Sys.time()
> end_time - start_time
Time difference of 9.695263 mins

【问题讨论】:

    标签: r amazon-ec2 data.table fread


    【解决方案1】:

    请始终说明版本号;例如sessionInfo() 的输出。但我可以告诉你,你可能使用的是 CRAN 版本。

    在 Stack Overflow 上提问之前,请务必检查 NEWS

    第 3 项(在许多其他 fread 改进中):

    内存映射懒惰;例如对于 9GB 文件,仅使用 nrow=10 读取前 10 行是 12 秒到 0.01 秒。接近 RAM 限制的大文件也可以更可靠地工作。进度条将更快、更一致地开始。

    可以使用 this install command 轻松试用 dev 的最新版本。您编写了 EC2,所以大概是 Linux,但任何 Windows 用户都可以使用Windows.zip from dev,而无需任何工具。

    既然你有一个 68GB 的​​ csv,你肯定会从 data.table v1.10.5+ 中受益匪浅。请在此处更新您的处理方式。

    【讨论】:

      猜你喜欢
      • 2014-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多