通过网络复制文件比使用`system.mv ...)慢得多。

问题描述 投票:9回答:1
通过我们的公司网络访问文件时,R变得非常缓慢,这一直困扰着我。因此,我退回去做了一些测试,我震惊地发现R file.copy()命令比使用system(mv ...)的等效文件复制慢[[

MUCH

。这是一个已知问题,还是我在这里做错了?这是我的测试:我有3个文件:

large_random.txt-〜100MB

    medium_random.txt-〜10MB
  • small_random.txt-〜1 MB
  • 我是这样在Mac上创建这些的:
  • dd if=/dev/urandom of=small_random.txt bs=1048576 count=1 dd if=/dev/urandom of=medium_random.txt bs=1048576 count=10 dd if=/dev/urandom of=large_random.txt bs=1048576 count=100

    但是以下所有R测试都是使用在虚拟机上运行的Windows完成的。 J盘位于本地,N盘位于700英里之外。

    library(tictoc)
    
    test_copy <- function(source, des){
      tic('r file.copy')
      file.remove(des)
      file.copy(source, des )
      toc()
    
      tic('system call')
      system(paste('rm', des, sep=' '))
      system(paste('cp', source, des, sep=' '))
      toc()
    }
    
    source <- 'J:\\tidy_examples\\dummyfiles\\small_random.txt'
    des <- 'N:\\JAL\\2018\\_temp\\small_random.txt'
    test_copy(source, des)
    
    source <- 'J:\\tidy_examples\\dummyfiles\\medium_random.txt'
    des <- 'N:\\JAL\\2018\\_temp\\medium_random.txt'
    test_copy(source, des)
    
    source <- 'J:\\tidy_examples\\dummyfiles\\large_random.txt'
    des <- 'N:\\JAL\\2018\\_temp\\large_random.txt'
    test_copy(source, des)
    

    将得到以下结果:

    > source <- 'J:\\tidy_examples\\dummyfiles\\small_random.txt'
    > des <- 'N:\\JAL\\2018\\_temp\\small_random.txt'
    > test_copy(source, des)
    r file.copy: 6.49 sec elapsed
    system call: 2.12 sec elapsed
    > 
    > source <- 'J:\\tidy_examples\\dummyfiles\\medium_random.txt'
    > des <- 'N:\\JAL\\2018\\_temp\\medium_random.txt'
    > test_copy(source, des)
    r file.copy: 56.86 sec elapsed
    system call: 4.65 sec elapsed
    > 
    > source <- 'J:\\tidy_examples\\dummyfiles\\large_random.txt'
    > des <- 'N:\\JAL\\2018\\_temp\\large_random.txt'
    > test_copy(source, des)
    r file.copy: 562.94 sec elapsed
    system call: 31.01 sec elapsed
    > 
    

    所以发生了什么,使系统调用变得如此快?大文件时,速度要慢18倍!

    通过我们的公司网络访问文件时,R变得非常缓慢,我一直遇到一些问题。所以我退了下来,做了一些测试,我很惊讶地发现R file.copy()...
  • r drive
    1个回答
    0
    投票
    © www.soinside.com 2019 - 2024. All rights reserved.