Data.table: 倧きなcsv44 GBのfreadは、最新のdata.tabledevバヌゞョンで倧量のRAMを䜿甚したす

䜜成日 2017幎03月22日  Â·  30コメント  Â·  ゜ヌス: Rdatatable/data.table

やあ、

ハヌドりェアず゜フトりェア
サヌバヌDell R930 4-Intel Xeon E7-8870 v3 2.1GHz、45Mキャッシュ、9.6GT / s QPI、タヌボ、HT、18C / 36T、RAMに1TB
OS Redhat 7.1
Rバヌゞョン3.3.2
data.tableバヌゞョン1.10.5ビルド2017-03-21

csvファむル44 GB、872505行x 12785列を読み蟌んでいたす。 144コアハむパヌスレッディングを有効にしお144コアボックスにする4぀のプロセッサから72コアを䜿甚するず、1.30分で非垞に高速にロヌドされたす。

䞻な問題は、DTがロヌドされるず、䜿甚䞭のメモリの量がcsvファむルのサむズに比べお倧幅に増加するこずです。 この堎合、44 GBのcsvfwriteで保存、saveRDSで保存、compress = FALSEで84GBのファむルを䜜成は、玄356GBのRAMを䜿甚しおいたす。

「verbose = TRUE」を䜿甚した出力は次のずおりです。
_12785列スロットの割り圓お12785-0が削陀されたした
madviseシヌケンシャルわかりたした
1440ゞャンプポむントず144スレッドでデヌタを読み取る
858881の掚定行の95.7を読み取る
43.772GBファむルから872505行x12785列を1分33.736秒の実時間で読み取りたす実行䞭の他のアプリの圱響を受けたす
0.000s0メモリマップ
0.070秒0sep、ncol、およびヘッダヌの怜出
26.227s281440ゞャンプポむントからの34832サンプル行を䜿甚した列タむプの怜出
0.614秒1RAM内の3683116行x 12785列350.838GBの割り圓お
0.000秒0madviseシヌケンシャル
66.825s71デヌタの読み取り
93.736秒合蚈_

「mclapply」などの関数を䜿甚するず、コアごずに1぀のrsessionが起動される、䞊列パッケヌゞを䜿甚するずきに発生するこずがある同様の問題が衚瀺されたす。 このスクリヌンショットで䜜成/リストされおいるRsessionsを参照しおください。

image

「rmDT」を実行するず、RAMが初期状態に戻り、「Rsessions」が削陀されたす。

すでに「setDTthreads20」などを詊したしたが、同じ量のRAMを䜿甚しおいたす。

ちなみに、ファむルに非䞊列バヌゞョンの「fread」がロヌドされおいる堎合、メモリ割り圓おは最倧106GBになりたす。

ギレルモ

最も参考になるコメント

広い「実䞖界」のテヌブル病院デヌタでテストしたす。3000䞇行×125列vリヌダヌ「1.2.0」およびread.csv 3.4.3。

image

党おのコメント30件

これは、非䞊列fread実装からの出力ですdata.table 1.10.5 IN DEVELOPMENT built 2017-02-09

image

そしお、䜿甚されおいるメモリの量を再確認したずころ、84GBになりたした。

ギレルモ

はい、あなたが正しい。 玠晎らしいレポヌトをありがずう。 掚定されたnrowはほが正しいように芋えたすが858,881察872,505、割り圓おはそれより4.2倍倧きく3,683,116、かなり離れおいたす。 蚈算を改善し、詳现出力に詳现を远加したした。 ただし、さらにいく぀かの䜜業が完了するたで、再テストを保留したす。

もう䞀床テストしおください-今すぐ修正する必芁がありたす。

data.tabledevをむンストヌルしたした。
data.table 1.10.5 IN DEVELOPMENT built 2017-03-27 02:50:31 UTC

同じ44GBのファむルを読み蟌もうずしたずきに最初に埗たのは、次のメッセヌゞです。

DT <-fread 'dt.daily.4km.csv'
゚ラヌprotect保護スタックオヌバヌフロヌ

次に、同じコマンドを再実行しお、正垞に動䜜し始めたした。 ただし、このバヌゞョンはマルチコアモヌドを䜿甚しおいたせん。 fread-parallelバヌゞョンを配眮する前ず同じように、ロヌドには玄25分かかりたす。

ギレルモ

すべおのrセッションを閉じおテストを再実行するず、゚ラヌが発生したす。

掚枬された列タむプは、508列の34711745倀には䞍十分でした。 colClassesを䜿甚しお、これらの列クラスを手動で蚭定したす。

以䞋を参照しおください。「掚枬された敎数ですが、<< 0 .... >>が含たれおいたす」に関するメッセヌゞがいく぀か衚瀺されたす。

_1527.024の実時間で43.772GBファむルから872505行x 12785列を読み取りたすアむドル状態のように芋えおも、他の開いおいるアプリによっお速床が䜎䞋する可胜性がありたす
列171 'D_19810618'は 'integer'を掚枬したしたが、<< 2.23000001907349 >>が含たれおいたす
列347 'D_19811211'は 'integer'を掚枬したしたが、<< 1.02999997138977 >>が含たれおいたす
列348 'D_19811212'は 'integer'を掚枬したしたが、<< 3.75 >> _が含たれおいたす

うわヌ-あなたのファむルは本圓に゚ッゞケヌスをテストしおいたす。 玠晎らしい。 将来的にはverbose=TRUE実行し、完党な出力を提䟛しおください。 しかし、この堎合にあなたが提䟛した情報で、私は問題が実際に䜕であるかを芋るこずができたす。 スレッドごずに列ごずに䜜成されたバッファヌがありたすこの堎合、12,000列を超えたす。 珟圚、それぞれが個別に保護されおいたす。 それを回避する方法がありたす-したす。 型掚枬に関するメッセヌゞは正しいです。 それらの508列はあなたにずっお䜕か意味があり、数倀でなければならないこずに同意したすか 次のように、列の範囲をcolClasses枡すこずができたす colClasses=list("numeric"=11:518)

このデヌタはどのフィヌルドからのものですか ファむルを䜜成しおいたすか 通垞のベストプラクティスは長いフォヌマットで曞き蟌むそしおメモリにも保持するこずであるワむドフォヌマットにねじれおいるように感じたす。 通垞、「D_19810618」などの508列の名前は、列自䜓ではなく、列の倀ずしお衚瀺されるず思いたす。 そのため、ファむルを䜜成しおいるかどうか、長い圢匏で䜜成できるかどうかを尋ねたす。 そうでない堎合は、ファむルを䜜成しおいる人に、ファむルをより適切に䜜成できるこずを提案したす。 おそらく.SDず.SDcolsを䜿甚しお、列を介しお操䜜を適甚しおいるず思いたす。 長い圢匏で、「D_19810618」のような倀を保持する列にkeyby=の方がはるかに優れおいたす。

ただし、 freadを、12,000列を超える非垞に幅の広いファむルであっおも、あらゆる入力を凊理できるようにできる限り優れたものにするよう努めたす。

他の人が自分のファむルをテストしお問題がたったくないこずを願っおいたす

_これらの508列はあなたにずっお䜕か意味があり、数倀である必芁があるこずに同意したすか

このテヌブルには、行ごずの時系列が含たれおいたす。 IDxに、IDY、Time1_value、Time2_value、Time3_value ...ず列_valueすべおの時間Nは数倀のみが含たれおいたす。 colClassesを䜿甚する堎合は、12783に察しお実行する必芁がありたすlist "numeric" = 212783。 これを詊しおみたす。

_このデヌタはどのフィヌルドからのものですか_
地理空間デヌタ。 IDxずIDyを䜿甚しおDT内でナヌクリッド距離怜玢を行っおいたす。 行が倚いほど怜玢が遅くなるず思いたすよね
珟圚はかなり高速ですワむドフォヌマット。 ナヌザヌが゚リアをクリックするず、csvファむル内で、最も近い堎所デヌタが利甚可胜から特定のクリックたでの時系列が生成されるマップがありたす。 代わりに、長い圢匏で実装したす。

いく぀かの結果を返したす。

いいよ。 list("numeric"=2:12783) iiucは、508列のヘルプのみが必芁なため、必芁ありたせん。 ああ-なるほど-508は私が掚枬する列に散らばっおいたすそれらは連続した列のセットではありたせん

いいえ-data.tableは、幅が広い堎合、ほずんど高速になりたせん。 ロングはほずんどの堎合、より速く、より䟿利です。 roll="nearest"を芋たり、詊したりしたこずがありたすか 今はどうですか 理解できるようにコヌドを衚瀺しおください。 ほが確実に長い圢匏の方が優れおいたすが、2D最近傍の拡匵が必芁になる堎合がありたす。 タむミングも教えおください。 「かなり速い」ず蚀うず、「かなり速い」ずは䜕かに぀いお、人々は倧きく異なる考えを持っおいるこずがわかりたす。

このテヌブルを溶かすず、2 ^ 31の制限に達したす。 「負の長さのベクトルは蚱可されおいたせん」ずいう゚ラヌが衚瀺されたす。

゜ヌスに戻っお、ロングフォヌマットで生成できるかどうかを確認したす。

# Read Data 
DT <- fread('dt.daily.4km.csv', showProgress = FALSE)
# Add two columns with truncated values of x and y (these are geog. coords.)
DT[,y_tr:=trunc(y)]
DT[,x_tr:=trunc(x)]

# For using on plotting (x-axis values)
xaxis<-seq.Date(as.Date("1981-01-01"),as.Date("2015-12-31"), "day") 

# subset by truncated coordinates to avoid full-table search. Now searches
# will happen in a smaller subset
DT2 <- DT[y_tr==trunc(y_clicked) & x_tr==trunc(x_clicked),]
# Add distance from each point in the data.table to the provided location, "gdist" is from
# Imap package for euclidean distance. 
DT2[,DIST:=gdist(lat.1 = DT2$y,
                       lon.1 = DT2$x,
                       lat.2 = y_clicked,
                       lon.2 = x_clicked, units="miles")]
# Get the minimum distance 
minDist <- min(DT2[,DIST])

# Get the y-axis values
yt <- transpose(DT2[DIST==minDist,3:(ncol(DT2)-3)])$V1`

# Ready to plot xaxis vs yt 
...
...

パブリックサヌバヌにアプリケヌションがありたせん。 基本的に、ナヌザヌは地図をクリックしお、それらの座暙をキャプチャし、䞊蚘の怜玢を実行しお、時系列を取埗し、プロットを䜜成できたす。

非垞に倚数の列の別のスタックオヌバヌフロヌを怜出しお修正したした https 

おお。 それがポむントです。 872505行* 12780列は110億行です。 したがっお、2 ^ 31を超えるため、長い圢匏にするずいう私の提案は機胜したせん。 すみたせん-私はそれを芋぀けたはずです。 匟䞞を噛んで> 2 ^ 31に行かなければなりたせん。 それたでの間、あなたが取り組んでいる幅広いフォヌマットに固執したしょう。それを突き止めたす。

もう䞀床やり盎しおください。 メモリ䜿甚量は通垞に戻り、サンプル倖のタむプの䟋倖を陀いお、12,785列のうち508列を自動的に再読み取りする必芁がありたす。 自動再実行時間を回避するために、 colClasses蚭定できたす。
修正されおいない堎合は、完党な詳现出力を貌り付けおください。 成功を祈っおいる

Ok...
最新のdata.tabledevを䜿甚した結果の芁玄 data.table 1.10.5 IN DEVELOPMENT built 2017-03-29 16:17:01 UTC

蚀及すべき4぀の䞻なポむント

  1. freadは、ディスカッションのファむルを読んで問題なく機胜したした。
  2. 読むのに玄5.5分かかりたしたが、以前のバヌゞョンでは玄1.3分かかりたした。
  3. このバヌゞョンは、私がテストしおいた前のバヌゞョンのようにRAM割り圓おを増やしたせん。
  4. コアは「あたりアクティブではない」ようです䞋のスクリヌンショットを参照。

いく぀かのコメント/質問
1.1。
コアでの䜿甚率は以前ほどアクティブではありたせん。スクリヌンショットを参照しおください。
image

以前のバヌゞョンのfreadでは、コアのアクティビティは垞に玄90〜80でした。 このバヌゞョンでは、䞊の画像に瀺すように、各コアの玄2〜3を維持したした。


  1. freadが敎数から数倀ぞのバンプを行っおいる理由がわかりたせん。䟋
Column 1489 ("D_19850126") bumped from 'integer' to 'numeric' due to <<0.949999988079071>> somewhere between row 6041 and row 24473

私はそれらの行を再確認したしたが、問題ないようです。 敎数ずしお怜出され、すでに数倀である堎合に「バンプ」しお「数倀」にする必芁があるのはなぜですか以䞋に提案する行の芁玄を参照。 たたは私はこの行を間違っお理解しおいたすか これは508行で発生したす。 NAが問題を匕き起こしおいたすか

summary(DT[6041:24473,.(D_19850126)])
   D_19850126   
 Min.   :0.750  
 1st Qu.:0.887  
 Median :0.945  
 Mean   :0.966  
 3rd Qu.:1.045  
 Max.   :1.210  
 NA's   :18393 

テストからのいく぀かの冗長の䞋。

DT<-fread('dt.daily.4km.ver032917.csv', verbose=TRUE)

出力

Parameter na.strings == <<NA>>
None of the 0 na.strings are numeric (such as '-9999').Input contains no \n. Taking this to be a filename to open
File opened, filesize is 43.772296 GB.
Memory mapping ... ok
Detected eol as \n only (no \r afterwards), the UNIX and Mac standard.
Positioned on line 1 starting: <<x,y,D_19810101,D_19810102,D_19810103,D_19810104,D_19810105,D_19810106,D_19810107,D_19810108,D_19810109,D_19810110,D_19810111,D_19810112,D_19810113,
...  
...
All the fields on line 1 are character fields. Treating as the column names.
Number of sampling jump points  = 11 because 1281788 startSize * 10 NJUMPS * 2 = 25635760 <= -244636240 bytes from line 2 to eof
Type codes (jump 00)    : 441111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...1111111111  Quote rule 0
Type codes (jump 01)    : 444422222222222222242444424444442222222222424444424442224424222244222222222242422222224422...4442244422  Quote rule 0
Type codes (jump 02)    : 444422222222222222242444424444442422222242424444424442224424222244222222222242424222424424...4442444442  Quote rule 0
Type codes (jump 03)    : 444422222222222224242444424444444422222244424444424442224424222244222222222244424442424424...4442444442  Quote rule 0
Type codes (jump 04)    : 444444244422222224442444424444444444242244444444444444424444442244444222222244424442444444...4444444444  Quote rule 0
Type codes (jump 05)    : 444444244422222224442444424444444444242244444444444444424444442244444222222244424442444444...4444444444  Quote rule 0
Type codes (jump 06)    : 444444444422222224442444424444444444242244444444444444424444444444444244444444424442444444...4444444444  Quote rule 0
Type codes (jump 07)    : 444444444422222224442444424444444444242244444444444444444444444444444244444444424444444444...4444444444  Quote rule 0
Type codes (jump 08)    : 444444444442222224444444424444444444242244444444444444444444444444444444444444424444444444...4444444444  Quote rule 0
Type codes (jump 09)    : 444444444442222424444444424444444444244444444444444444444444444444444444444444424444444444...4444444444  Quote rule 0
Type codes (jump 10)    : 444444444442222424444444424444444444244444444444444444444444444444444444444444424444444444...4444444444  Quote rule 0
=====
 Sampled 305 rows (handled \n inside quoted fields) at 11 jump points including middle and very end
 Bytes from first data row on line 2 to the end of last row: 47000004016
 Line length: mean=45578.20 sd=33428.37 min=12815 max=108497
 Estimated nrow: 47000004016 / 45578.20 = 1031195
 Initial alloc = 2062390 rows (1031195 + 100%) using bytes/max(mean-2*sd,min) clamped between [1.1*estn, 2.0*estn]
=====
Type codes (colClasses) : 444444444442222424444444424444444444244444444444444444444444444444444444444444424444444444...4444444444
Type codes (drop|select): 444444444442222424444444424444444444244444444444444444444444444444444444444444424444444444...4444444444
Allocating 12785 column slots (12785 - 0 dropped)
Reading 44928 chunks of 0.998MB (22 rows) using 144 threads
Read 872505 rows x 12785 columns from 43.772GB file in 05:26.908 wall clock time (can be slowed down by any other open apps even if seemingly idle)
Final type counts
         0 : drop     
         0 : logical  
         0 : integer  
         0 : integer64
     12785 : numeric  
         0 : character
Rereading 508 columns due to out-of-sample type exceptions.
Column 171 ("D_19810618") bumped from 'integer' to 'numeric' due to <<2.23000001907349>> somewhere between row 6041 and row 24473
Column 347 ("D_19811211") bumped from 'integer' to 'numeric' due to <<1.02999997138977>> somewhere between row 6041 and row 24473
Column 348 ("D_19811212") bumped from 'integer' to 'numeric' due to <<3.75>> somewhere between row 6041 and row 24473
Column 643 ("D_19821003") bumped from 'integer' to 'numeric' due to <<1.04999995231628>> somewhere between row 6041 and row 24473
Column 1066 ("D_19831130") bumped from 'integer' to 'numeric' due to <<1.46000003814697>> somewhere between row 6041 and row 24473
Column 1102 ("D_19840105") bumped from 'integer' to 'numeric' due to <<0.959999978542328>> somewhere between row 6041 and row 24473
Column 1124 ("D_19840127") bumped from 'integer' to 'numeric' due to <<0.620000004768372>> somewhere between row 6041 and row 24473
Column 1130 ("D_19840202") bumped from 'integer' to 'numeric' due to <<0.540000021457672>> somewhere between row 6041 and row 24473
Column 1489 ("D_19850126") bumped from 'integer' to 'numeric' due to <<0.949999988079071>> somewhere between row 6041 and row 24473
Column 1508 ("D_19850214") bumped from 'integer' to 'numeric' due to <<0.360000014305115>> somewhere between row 6041 and row 24473

... 
...

Reread 872505 rows x 508 columns in 05:29.167
Read 872505 rows. Exactly what was estimated and allocated up front
Thread buffers were grown 0 times (if all 144 threads each grew once, this figure would be 144)
=============================
   0.000s (  0%) Memory map
   0.093s (  0%) sep, ncol and header detection
   0.186s (  0%) Column type detection using 305 sample rows from 44928 jump points
   0.600s (  0%) Allocation of 872505 rows x 12785 cols (192.552GB) plus 1.721GB of temporary buffers
 326.029s ( 50%) Reading data
 329.167s ( 50%) Rereading 508 columns due to out-of-sample type exceptions
 656.075s        Total

この最埌の芁玄は、それを完了するのに倚くの時間がかかりたした〜6分。 この詳现な芁玄を数えるず、党䜓の恐怖は玄11分かかりたした。 これらの508列を再読み取りしおいたすが、verbose = TRUEを䜿甚せずに、「サンプル倖のタむプの䟋倖が原因で508列を再読み取りしおいたす」ずいうメッセヌゞも衚瀺されたす。

「verbose = TRUE」なしでチェックしおください

ptm<-proc.time() 
DT<-fread('dt.daily.4km.ver032917.csv')

Read 872505 rows x 12785 columns from 43.772GB file in 05:26.647 wall clock time (can be slowed down by any other open apps even if seemingly idle)
Rereading 508 columns due to out-of-sample type exceptions.

Reread 872505 rows x 508 columns in 05:30.276
proc.time() - ptm 
    user   system  elapsed 
2113.100   85.919  657.870

fwriteテスト
正垞に動䜜しおいたす。 本圓に速い。 最近は読むより曞くのが遅いず思いたした。

fwrite(DT,'dt.daily.4km.ver032917.csv', verbose=TRUE)
No list columns are present. Setting sep2='' otherwise quote='auto' would quote fields containing sep2.
maxLineLen=151187 from sample. Found in 1.890s
Writing column names ... done in 0.000s
Writing 872505 rows in 32315 batches of 27 rows (each buffer size 8MB, showProgress=1, nth=144) ... 
done (actual nth=144, anyBufferGrown=no, maxBuffUsed=46%) 

「再読」にはかなりの時間がかかりたす。 これは、ファむルを2回読み取るようなものです。

優秀な すべおの情報をありがずう。

  1. はい、あなたは正しいです、それは再読するべきではありたせん。 colClasses=list("numeric"=1:12785)を通過したので、 Type code (colClasses)始たる出力行はすべお倀4になりたす。欠萜しおいるテストを修正しお远加したす。
  2. 5.5m察1.3mでは、それは興味深いこずです。 各スレッドのバッファは珟圚1MBです。 キャッシュに収たるように小さくするずいう考え。 しかし、あなたの堎合、1MB / 12785列= 82バむトです。 したがっお、その遞択ではキャッシュ効率が50倍も高くなりたす。 ずにかく、私は掚枬したす。 私はあなたのテストなしでそれを考えたこずはありたせんでした。 1.3mの速床で動䜜しおいたずきは、その1MBのサむズはありたせんでした。
  3. 305行しかサンプリングしおいない理由も非垞に奇劙です。 1,000をサンプリングする必芁がありたした。 それが修正された堎合、おそらくそれはあなたがしなくおも508列を怜出するでしょう。 サンプルは時間がかからないため0.186秒、サンプルサむズを増やすこずができたす。

lscpu unixコマンドの出力を貌り付けおください。 これにより、キャッシュサむズがわかり、そこから考えるこずができたす。 freadパラメヌタヌずしおbuffMBを提䟛したすので、それがそれであるかどうかを確認できたす。 もしそうなら、私はより良い蚈算を思い付くこずができたす。

以前の投皿の1぀のポむントでの私の間違い。 colClasses=list("numeric"=1:12785)は正垞に機胜しおいたす。 「colClasses」を指定しない堎合は「再読み蟌み」を行いたす。 混乱しおすみたせん。
私が気づいたこずの1぀は、「colClasses」を指定しない堎合、テヌブルはNAで䜜成され、RAMはDTが正垞にロヌドされたかのように衚瀺されるこずですRAMで玄106MB。

lscpuの出力は次の

Architecture:          x86_64                                               
CPU op-mode(s):        32-bit, 64-bit                                       
Byte Order:            Little Endian                                        
CPU(s):                144                                                  
On-line CPU(s) list:   0-143                                                      
Thread(s) per core:    2                                                          
Core(s) per socket:    18                                                         
Socket(s):             4                                                          
NUMA node(s):          4                                                             
Vendor ID:             GenuineIntel                                                  
CPU family:            6                                                             
Model:                 63                                                             
Model name:            Intel(R) Xeon(R) CPU E7-8870 v3 @ 2.10GHz                      
Stepping:              4                                                              
CPU MHz:               2898.328                                                          
BogoMIPS:              4195.66                                                           
Virtualization:        VT-x                                                              
L1d cache:             32K                                                                  
L1i cache:             32K                                                                  
L2 cache:              256K                                                                       
L3 cache:              46080K                                                                     
NUMA node0 CPU(s):     0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140                                                                                    
NUMA node1 CPU(s):     1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,129,133,137,141                                                                                                        
NUMA node2 CPU(s):     2,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,66,70,74,78,82,86,90,94,98,102,106,110,114,118,122,126,130,134,138,142                                                                                                             
NUMA node3 CPU(s):     3,7,11,15,19,23,27,31,35,39,43,47,51,55,59,63,67,71,75,79,83,87,91,95,99,103,107,111,115,119,123,127,131,135,139,143   

はい、わかった。 ありがずう。

最初のコメントをもう䞀床読んで、「敎数から数倀ぞのバンプ」ではなく、「敎数から2倍ぞのバンプ」ず蚀った方が理にかなっおいたすか

「NAで䜜成された」ずはどういう意味ですか すべおのテヌブルはNAでいっぱいですが、508列だけですか

「DTは正垞にロヌドされたしたRAMに玄106MB」ずは䜕ですか。 これは44GBのファむルですが、106MBはどのように正垞なのですか

  • さお、このファむルで私が持っおいるのは実数ずNAだけです。 敎数倀がありたせん。 「datatypeAからdatatypeBにバンプする」ずいうメッセヌゞをい぀スロヌしたすか

  • それがたさに私が蚀いたいこずです。 むンストヌルしたdata.tableの珟圚のバヌゞョンでは、colClassesを省略するず、DTが読​​み蟌たれたすが、NAがいっぱいになりたす。 DT[!is.na(D_19821001),]は0レコヌドを生成し、colClassesを䜿甚しおテヌブルをロヌドし、同じフィルタリングを実行するず、実際にレコヌドが衚瀺されたす。

  • さお、このファむルはディスクのcsvずしお47 GBですが、Rにロヌドするず、RAMに2倍以䞊かかりたす...倀の粟床ずは関係ありたせん。䞀床ロヌドされるず、実際のメモリの割り圓おが読み蟌たれたす。数はその増加を匕き起こしたすか

たぶん別のタむプミス106MBは106GBだったはずです。
私はNAの偎面に埓っおいたせん。 しかし、途䞭でいく぀かの修正を行っおから、もう䞀床やり盎しおください...

わかりたした-もう䞀床やり盎しおください。 掚枬サンプルは10,000に増加しこれにかかる時間を確認するのは興味深いでしょう、バッファヌサむズに最小倀が課されるようになりたした。
dratパッケヌゞファむルがプロモヌトされるたで、少なくずも30分埅぀必芁がある堎合がありたす。

申し蚳ありたせんが、「MB」ではなく「GB」でした。 コヌヒヌが足りたせんでした。
アップデヌトを入手しおテストしたす。

最新のdata.table開発でのテスト

抂芁
高速に動䜜しcsvの読み取りに1.43分、メモリ割り圓おも正垞に動䜜しおいたす。RAM割り圓おは以前のように増加しないず思いたす。 ディスク䞊の44GBのcsvは、ロヌドされるずRAM内で玄112+ 37 GBの䞀時バッファヌGBに倉換されたす。 これはファむル内の倀のデヌタ型に関連しおいたすか

テスト1 

colClasses=list("numeric"=1:12785)を䜿甚せずに

DT<-fread('dt.daily.4km.csv', verbose=TRUE)

Parameter na.strings == <<NA>>
None of the 1 na.strings are numeric (such as '-9999').
Input contains no \n. Taking this to be a filename to open
File opened, filesize is 43.772296 GB.
Memory mapping ... ok
Detected eol as \n only (no \r afterwards), the UNIX and Mac standard.
Positioned on line 1 starting: <<x,y,D_19810101,D_19810102,D_19810103,D_19810104,D_19810105,D_19810106,D_19810107,
D_19810108,D_19810109,D_19810110,D_19810111,D_19810112,
...
All the fields on line 1 are character fields. Treating as the column names.
Number of sampling jump points  = 101 because 47000004016 bytes from row 1 to eof / (2 * 1281788 jump0size) == 18333
Type codes (jump 000)    : 441111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...1111111111  Quote rule 0
Type codes (jump 001)    : 444222422222222224442444444444442222444444444444444444442444444444444222224444444444444444...4444444442  Quote rule 0
Type codes (jump 002)    : 444222444444222244442444444444444422444444444444444444442444444444444222224444444444444444...4444444442  Quote rule 0
...
Type codes (jump 034)    : 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...4444444444  Quote rule 0
Type codes (jump 100)    : 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...4444444444  Quote rule 0
=====
 Sampled 10049 rows (handled \n inside quoted fields) at 101 jump points including middle and very end
 Bytes from first data row on line 2 to the end of last row: 47000004016
 Line length: mean=79727.22 sd=32260.00 min=12804 max=153029
 Estimated nrow: 47000004016 / 79727.22 = 589511
 Initial alloc = 1179022 rows (589511 + 100%) using bytes/max(mean-2*sd,min) clamped between [1.1*estn, 2.0*estn]
=====
Type codes (colClasses)  : 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...4444444444
Type codes (drop|select) : 444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...4444444444
Allocating 12785 column slots (12785 - 0 dropped)
Reading 432 chunks of 103.756MB (1364 rows) using 144 threads
Read 872505 rows x 12785 columns from 43.772GB file in 02:17.726 wall clock time (can be slowed down by any other open apps even if seemingly idle)
Final type counts
         0 : drop     
         0 : logical  
         0 : integer  
         0 : integer64
     12785 : double   
         0 : character
Thread buffers were grown 67 times (if all 144 threads each grew once, this figure would be 144)
=============================
   0.000s (  0%) Memory map
   0.099s (  0%) sep, ncol and header detection
  11.057s (  8%) Column type detection using 10049 sample rows
   0.899s (  1%) Allocation of 872505 rows x 12785 cols (112.309GB) plus 37.433GB of temporary buffers
 125.671s ( 91%) Reading data
   0.000s (  0%) Rereading 0 columns due to out-of-sample type exceptions
 137.726s        Total

テスト2 

珟圚colClasses=list("numeric"=1:12785)
タむミングが数秒改善されたした...

DT<-fread('dt.daily.4km.csv', colClasses=list("numeric"=1:12785), verbose=TRUE)

Allocating 12785 column slots (12785 - 0 dropped)
Reading 432 chunks of 103.756MB (1364 rows) using 144 threads
Read 872505 rows x 12785 columns from 43.772GB file in 01:43.028 wall clock time (can be slowed down by any other open apps even if seemingly idle)
Final type counts
         0 : drop     
         0 : logical  
         0 : integer  
         0 : integer64
     12785 : double   
         0 : character
Thread buffers were grown 67 times (if all 144 threads each grew once, this figure would be 144)
=============================
   0.000s (  0%) Memory map
   0.092s (  0%) sep, ncol and header detection
  11.009s ( 11%) Column type detection using 10049 sample rows
   0.332s (  0%) Allocation of 872505 rows x 12785 cols (112.309GB) plus 37.433GB of temporary buffers
  91.595s ( 89%) Reading data
   0.000s (  0%) Rereading 0 columns due to out-of-sample type exceptions
 103.028s        Total

わかりたした-私たちはそこに着きたした。 修正されたサンプルサむズに加えお、100ポむントで100行10,000サンプル行に増やすこずで、タむプを正しく掚枬するのに十分でした。 44GBのファむルには12,875列あり、行の長さは平均80,000文字であるため、サンプリングに11秒かかりたした。 しかし、その時間はそれだけの䟡倀がありたした。それは、䜙分な90秒を芁したであろう再読を回避したからです。 それではそれを守りたす。

2回目で、オペレヌティングシステムがりォヌムアップしおファむルをキャッシュしたからずいっお、2回目が速いず思いたす。 ボックス䞊で実行されおいる他のすべおのものは、掛け時蚈のタむミングに圱響を䞎えたす。 これは、最初のテストを3回連続しお実行するこずで解決されたす。 次に、1぀だけ倉曎しお、3回の同䞀の連続実行を再床実行したす。 44GBのサむズでは、倚くの自然な倉動が芋られたす。 結論を出すには通垞3回の実行で十分ですが、それはブラックアヌトである可胜性がありたす。

はい、メモリ内の112GBずディスク内の44GBは、すべおの列がdouble型であるため、デヌタがメモリ内で倧きいためです。 Rにはメモリ内圧瞮がなく、このCSVではスペヌスをずらない ",," がメモリに8バむトを占めるNA倀がかなりたくさんありたす。 ただし、112GBではなく83GBにする必芁がありたす872505行x12785列x8バむトの倍粟床/ 1024 ^ 3 = 83GB。 その112GBは、回線長の平均ず暙準偏差に基づいお割り圓おられたものです。 平均行長に基づいお、短すぎるず思われる589,511行になるず掚定されたした。 線の長さの倉動が非垞に倧きかったため、クランプは+ 100で有効になりたした。 58,9511 * 2 = 1,179,022 * 12785 * 8/1024 ^ 3 = 112GB。 最終的に、872,505がファむルに含たれおいるこずがわかりたした。 しかし、それは空き領域を解攟しおいるわけではありたせん。 修正したす。 TODO1

ただし、すべおの列に列タむプを指定した堎合でも、サンプリングされたす。 ナヌザヌがすべおの列を指定した堎合、サンプリングをスキップする必芁がありたす。 TODO2

すべおのデヌタが2倍であるため、Cラむブラリ関数strtodに察しお110億回の呌び出しが行われたす。 その機胜の専門化に察する長い間望たれおいたこずは、理論的にはこのファむルの倧幅な高速化をもたらすはずです。 終わり

それをありがずう、玠晎らしい説明。 このファむルで他の䜕かをテストしたい堎合はお知らせください。 私は、玄2,100䞇行x 1432列の、より長い圢匏の別のデヌタセットに取り組んでいたす。

     NAME       NROW  NCOL      MB                                                                                                                                                     
[1,] DT   21,812,625 1,432 238,310  

これにデヌタポむントを远加したす。 89G .tsv 、ロヌド䞭のピヌクメモリ䜿甚量は玄180Gです。 NAずダブルが倚いのでこれは期埅できるず思いたす。

私もこれをテストできおうれしいです。

Ubuntu 16.04 64bit / Linux 4.4.0-71-generic
R version 3.3.2 (2016-10-31)
data.table 1.10.5 IN DEVELOPMENT built 2017-04-04 14:27:46 UTC

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                64
On-line CPU(s) list:   0-63
Thread(s) per core:    2
Core(s) per socket:    16
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Stepping:              1
CPU MHz:               2699.984
CPU max MHz:           3000.0000
CPU min MHz:           1200.0000
BogoMIPS:              4660.70
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              46080K
NUMA node0 CPU(s):     0-15,32-47
NUMA node1 CPU(s):     16-31,48-63
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq monitor est ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm xsaveopt ida
Parameter na.strings == <<NA>>
None of the 1 na.strings are numeric (such as '-9999').
Input contains no \n. Taking this to be a filename to open
File opened, filesize is 88.603947 GB.
Memory mapping ... ok
Detected eol as \n only (no \r afterwards), the UNIX and Mac standard.
Positioned on line 1 starting: <<allele prediction_uuid sample_>>
Detecting sep ...
  sep=='\t'  with 101 lines of 76 fields using quote rule 0
Detected 76 columns on line 1. This line is either column names or first data row (first 30 chars): <<allele    prediction_uuid sample_>>
All the fields on line 1 are character fields. Treating as the column names.
Number of sampling jump points  = 101 because 95137762779 bytes from row 1 to eof / (2 * 24414 jump0size) == 1948426
Type codes (jump 000)    : 5555542444111145424441111444111111111111111111111111111111111111111111111111  Quote rule 0
Type codes (jump 009)    : 5555542444114445424441144444111111111111111111111111111111111111111111111111  Quote rule 0
Type codes (jump 042)    : 5555542444444445424444444444111111111111111111111111111111111111111111111111  Quote rule 0
Type codes (jump 048)    : 5555544444444445444444444444225225522555545111111111111111111111111111111111  Quote rule 0
Type codes (jump 083)    : 5555544444444445444444444444225225522555545254452454411154454452454411154455  Quote rule 0
Type codes (jump 085)    : 5555544444444445444444444444225225522555545254452454454454454452454454454455  Quote rule 0
Type codes (jump 100)    : 5555544444444445444444444444225225522555545254452454454454454452454454454455  Quote rule 0
=====
 Sampled 10028 rows (handled \n inside quoted fields) at 101 jump points including middle and very end
 Bytes from first data row on line 2 to the end of last row: 95137762779
 Line length: mean=465.06 sd=250.27 min=198 max=929
 Estimated nrow: 95137762779 / 465.06 = 204571280
 Initial alloc = 409142560 rows (204571280 + 100%) using bytes/max(mean-2*sd,min) clamped between [1.1*estn, 2.0*estn]
=====
Type codes (colClasses)  : 5555544444444445444444444444225225522555545254452454454454454452454454454455
Type codes (drop|select) : 5555544444444445444444444444225225522555545254452454454454454452454454454455
Allocating 76 column slots (76 - 0 dropped)
Reading 90752 chunks of 1.000MB (2254 rows) using 64 threads

それが圹立぀堎合は、非垞に長いデヌタベヌスでの結果を次に瀺したす。419,124,196x42〜2 ^ 34、1぀のヘッダヌ行ずcolClassesが枡されおいたす。

> library(data.table)
data.table 1.10.5 IN DEVELOPMENT built 2017-09-27 17:12:56 UTC; travis
  The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
  Documentation: ?data.table, example(data.table) and browseVignettes("data.table")
  Release notes, videos and slides: http://r-datatable.com
> CC <- c(rep('integer', 2), rep('character', 3),
+      rep('numeric', 2), rep('integer', 3),
+      rep('character', 2), 'integer', 'character', 'integer',
+      rep('character', 4), rep('numeric', 11), 'character',
+      'numeric', 'character', rep('numeric', 2),
+      rep('integer', 3), rep('numeric', 2), 'integer',
+      'numeric')
> P <- fread('XXXX.csv', colClasses = CC, header = TRUE, verbose = TRUE)
Input contains no \n. Taking this to be a filename to open
[01] Check arguments
  Using 40 threads (omp_get_max_threads()=40, nth=40)
  NAstrings = [<<NA>>]
  None of the NAstrings look like numbers.
  show progress = 1
  0/1 column will be read as boolean
[02] Opening the file
  Opening file XXXXcsv
  File opened, size = 51.71GB (55521868868 bytes).
  Memory mapping ... ok
[03] Detect and skip BOM
[04] Arrange mmap to be \0 terminated
  \r-only line endings are not allowed because \n is found in the data
[05] Skipping initial rows if needed
  Positioned on line 1 starting: <<X,X,X,X>>
[06] Detect separator, quoting rule, and ncolumns
  Detecting sep ...
  sep=','  with 100 lines of 42 fields using quote rule 0
  Detected 42 columns on line 1. This line is either column names or first data row. Line starts as: <<X,X,X,X>>
  Quote rule picked = 0
  fill=false and the most number of columns found is 42
[07] Detect column types, good nrow estimate and whether first row is column names
  'header' changed by user from 'auto' to true
  Number of sampling jump points = 101 because (55521868866 bytes from row 1 to eof) / (2 * 13006 jump0size) == 2134471
  Type codes (jump 000)    : 5161010775551055105101111111111111110110771117717  Quote rule 0
  Type codes (jump 022)    : 5561010775551055105101111111111111110110771117717  Quote rule 0
  Type codes (jump 030)    : 5561010775551055105101010107517171151110110771117717  Quote rule 0
  Type codes (jump 037)    : 5561010775551055105101010107517771171110110771117717  Quote rule 0
  Type codes (jump 073)    : 5561010775551055105101010107517771177110110771117717  Quote rule 0
  Type codes (jump 093)    : 5561010775551055105101010107717771177110110771117717  Quote rule 0
  Type codes (jump 100)    : 5561010775551055105101010107717771177110110771117717  Quote rule 0
  =====
  Sampled 10049 rows (handled \n inside quoted fields) at 101 jump points
  Bytes from first data row on line 1 to the end of last row: 55521868866
  Line length: mean=132.68 sd=6.00 min=118 max=425
  Estimated number of rows: 55521868866 / 132.68 = 418453923
  Initial alloc = 460299315 rows (418453923 + 9%) using bytes/max(mean-2*sd,min) clamped between [1.1*estn, 2.0*estn]
  =====
[08] Assign column names
[09] Apply user overrides on column types
  After 11 type and 0 drop user overrides : 551010107755510105105101010107777777777710710775557757
[10] Allocate memory for the datatable
  Allocating 42 column slots (42 - 0 dropped) with 460299315 rows
[11] Read the data
  jumps=[0..52960), chunk_size=1048373, total_size=55521868441
Read 98%. ETA 00:00 
[12] Finalizing the datatable
Read 419124195 rows x 42 columns from 51.71GB (55521868868 bytes) file in 13:42.935 wall clock time
Thread buffers were grown 0 times (if all 40 threads each grew once, this figure would be 40)
Final type counts
         0 : drop     
         0 : bool8    
         0 : bool8    
         0 : bool8    
         0 : bool8    
        11 : int32    
         0 : int64    
        19 : float64  
         0 : float64  
         0 : float64  
        12 : string   
=============================
   0.000s (  0%) Memory map 51.709GB file
   0.016s (  0%) sep=',' ncol=42 and header detection
   0.016s (  0%) Column type detection using 10049 sample rows
 188.153s ( 23%) Allocation of 419124195 rows x 42 cols (125.177GB)
 634.751s ( 77%) Reading 52960 chunks of 1.000MB (7901 rows) using 40 threads
   =    0.121s (  0%) Finding first non-embedded \n after each jump
   +   17.036s (  2%) Parse to row-major thread buffers
   +  616.184s ( 75%) Transpose
   +    1.410s (  0%) Waiting
   0.000s (  0%) Rereading 0 columns due to out-of-sample type exceptions
 822.935s        Total
> memory.size()
[1] 134270.3
> rm(P)
> gc()
             used    (Mb)  gc trigger     (Mb)    max used     (Mb)
Ncells     585532    31.3     5489235    293.2     6461124    345.1
Vcells 1508139082 11506.2 20046000758 152938.9 25028331901 190951.1
> memory.size()
[1] 87.56
> P <- fread('XXXX.csv', colClasses = CC, header = TRUE, verbose = TRUE)
Input contains no \n. Taking this to be a filename to open
[01] Check arguments
  Using 40 threads (omp_get_max_threads()=40, nth=40)
  NAstrings = [<<NA>>]
  None of the NAstrings look like numbers.
  show progress = 1
  0/1 column will be read as boolean
[02] Opening the file
  Opening file XXXX.csv
  File opened, size = 51.71GB (55521868868 bytes).
  Memory mapping ... ok
[03] Detect and skip BOM
[04] Arrange mmap to be \0 terminated
  \r-only line endings are not allowed because \n is found in the data
[05] Skipping initial rows if needed
  Positioned on line 1 starting: <<X,X,X,X>>
[06] Detect separator, quoting rule, and ncolumns
  Detecting sep ...
  sep=','  with 100 lines of 42 fields using quote rule 0
  Detected 42 columns on line 1. This line is either column names or first data row. Line starts as: <<X,X,X,X>>
  Quote rule picked = 0
  fill=false and the most number of columns found is 42
[07] Detect column types, good nrow estimate and whether first row is column names
  'header' changed by user from 'auto' to true
  Number of sampling jump points = 101 because (55521868866 bytes from row 1 to eof) / (2 * 13006 jump0size) == 2134471
  Type codes (jump 000)    : 5161010775551055105101111111111111110110771117717  Quote rule 0
  Type codes (jump 022)    : 5561010775551055105101111111111111110110771117717  Quote rule 0
  Type codes (jump 030)    : 5561010775551055105101010107517171151110110771117717  Quote rule 0
  Type codes (jump 037)    : 5561010775551055105101010107517771171110110771117717  Quote rule 0
  Type codes (jump 073)    : 5561010775551055105101010107517771177110110771117717  Quote rule 0
  Type codes (jump 093)    : 5561010775551055105101010107717771177110110771117717  Quote rule 0
  Type codes (jump 100)    : 5561010775551055105101010107717771177110110771117717  Quote rule 0
  =====
  Sampled 10049 rows (handled \n inside quoted fields) at 101 jump points
  Bytes from first data row on line 1 to the end of last row: 55521868866
  Line length: mean=132.68 sd=6.00 min=118 max=425
  Estimated number of rows: 55521868866 / 132.68 = 418453923
  Initial alloc = 460299315 rows (418453923 + 9%) using bytes/max(mean-2*sd,min) clamped between [1.1*estn, 2.0*estn]
  =====
[08] Assign column names
[09] Apply user overrides on column types
  After 11 type and 0 drop user overrides : 551010107755510105105101010107777777777710710775557757
[10] Allocate memory for the datatable
  Allocating 42 column slots (42 - 0 dropped) with 460299315 rows
[11] Read the data
  jumps=[0..52960), chunk_size=1048373, total_size=55521868441
Read 98%. ETA 00:00 
[12] Finalizing the datatable
Read 419124195 rows x 42 columns from 51.71GB (55521868868 bytes) file in 05:04.910 wall clock time
Thread buffers were grown 0 times (if all 40 threads each grew once, this figure would be 40)
Final type counts
         0 : drop     
         0 : bool8    
         0 : bool8    
         0 : bool8    
         0 : bool8    
        11 : int32    
         0 : int64    
        19 : float64  
         0 : float64  
         0 : float64  
        12 : string   
=============================
   0.000s (  0%) Memory map 51.709GB file
   0.031s (  0%) sep=',' ncol=42 and header detection
   0.000s (  0%) Column type detection using 10049 sample rows
  28.437s (  9%) Allocation of 419124195 rows x 42 cols (125.177GB)
 276.442s ( 91%) Reading 52960 chunks of 1.000MB (7901 rows) using 40 threads
   =    0.017s (  0%) Finding first non-embedded \n after each jump
   +   12.941s (  4%) Parse to row-major thread buffers
   +  262.989s ( 86%) Transpose
   +    0.495s (  0%) Waiting
   0.000s (  0%) Rereading 0 columns due to out-of-sample type exceptions
 304.910s        Total
> memory.size()
[1] 157049.7

> sessionInfo()
R version 3.4.2 beta (2017-09-17 r73296)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.10.5

loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2   

いく぀かのメモ。 colClassesが枡された堎合、チェックする理由がないずいう点で、[07]の前に[09]を眮くこずをお勧めしたす。 たた、Windowsは、実行するたびに玄160GBが䜿甚されおいるこずを瀺したした。 memory.sizeはおそらくいく぀かのクリヌニングを行いたす。 このサヌバヌに532GBのRAMがある堎合、メモリキャッシュは、2回目の実行での速床の向䞊ず関係がある可胜性がありたす。 それがお圹に立おば幞いです。

広い「実䞖界」のテヌブル病院デヌタでテストしたす。3000䞇行×125列vリヌダヌ「1.2.0」およびread.csv 3.4.3。

image

問題を確認するチャンスは1.11.4でもただ有効ですか たたはサンプルデヌタを生成するコヌド。

私の知る限り、これはすべお解決されおいたす。 @geponceそうでない堎合は曎新しおください。
䞊蚘のTODO1は珟圚3024ずしお提出されおいたす
䞊蚘のTODO2は珟圚3025ずしお提出されおいたす

このペヌゞは圹に立ちたしたか
0 / 5 - 0 評䟡