Created
November 29, 2017 13:06
-
-
Save isalgueiro/36a08947bc43f8fc63f20c3c2d6b1f1d to your computer and use it in GitHub Desktop.
HOW-TO get parallel HTTP connections in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(parallel) | |
library(httr) | |
library(RCurl) | |
detectCores() | |
f <- function(x) { | |
#h <- httr::handle('http://slowwly.robertomurray.co.uk/') | |
#httr::GET('http://slowwly.robertomurray.co.uk/delay/2000/url/http://www.google.co.uk', handle = h) | |
RCurl::httpGET('http://slowwly.robertomurray.co.uk/delay/2000/url/http://www.google.co.uk') | |
#Sys.sleep(2) | |
return(T) | |
} | |
vf <- Vectorize(f) | |
x <- 1:6 | |
system.time(pvec(x, vf, mc.cores = 1)) | |
system.time(pvec(x, vf, mc.cores = 2)) | |
system.time(pvec(x, vf, mc.cores = 4)) | |
system.time(pvec(x, vf, mc.cores = 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using httr I couldn't manage to make it launch parallel HTTP connections;
mc.cores = 6
execution is almost as slow asmc.cores = 1
. With RCurl parallel results are faster.httr 6 cores
RCurl 6 cores
More info: