R: Copying files over a MUCH network is slower with `file.copy` than` system (mv ...) `

I am having some problems with the fact that R becomes very slow when accessing files through our corporate network. So I refused and did some testing, and I was shocked to find that the R file.copy() MUCH command is slower than the equivalent copy of the file using system(mv ...). Is this a known issue or am I doing something wrong here?

Here is my test:

I have 3 files:

  • large_random.txt - ~ 100 MB
  • medium_random.txt - ~ 10 MB
  • small_random.txt - ~ 1 MB

I created them on my Mac as follows:

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

But the following R-tests were performed using Windows running on a virtual machine. Drive J is local and drive N is 700 miles away.

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)

This leads to the following:

> 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 !

+4

Source: https://habr.com/ru/post/1696257/


All Articles