Tools to Test and Compare Internet Bandwidth Speeds
The ‘Ookla’ ‘Speedtest’ site https://beta.speedtest.net/about provides interactive and programmatic services to test and compare bandwidth speeds from a source node on the Internet to thousands of test servers. Tools are provided to obtain test server lists, identify target servers for testing and performing speed/bandwidth tests.
The following functions are implemented:
nice_speed
: Convert a test speed, in Mbits/s, to its string representation along with appropriate units for the magnitude of the test speedspd_best_servers
: Find “best” servers (latency-wise) from master server listspd_closest_servers
: Find “closest” servers (geography-wise) from master server listspd_compute_bandwidth
: Compute bandwidth from bytes transferred and time takenspd_config
: Retrieve client configuration information for the speedtestspd_download_test
: Perform a download speed/bandwidth testspd_servers
: Retrieve a list of SpeedTest serversspd_test
: Test your internet speed/bandwidthspd_upload_test
: Perform an upload speed/bandwidth testWhile you can run spd_test()
from an R console, it was desgined to be an easily wrapped into a bash
(et al) alias or put into a small batch script. Or, you can just type out the following if you’re fleet-of-finger/have dexterous digits:
Rscript --quiet -e 'speedtest::spd_test()'
which will look something like:
Folks interested in contributing can take a look at the TODOs and pick as many as you like! Ones with question marks are truly a “I dunno if we shld” kinda thing. Ones with exclamation marks are essentials.
autoplot
support!install.packages("speedtest", repos = "https://cinc.rud.is")
# or
remotes::install_git("https://git.rud.is/hrbrmstr/speedtest.git")
# or
remotes::install_git("https://git.sr.ht/~hrbrmstr/speedtest")
# or
remotes::install_gitlab("hrbrmstr/speedtest")
# or
remotes::install_bitbucket("hrbrmstr/speedtest")
# or
remotes::install_github("hrbrmstr/speedtest")
NOTE: To use the ‘remotes’ install options you will need to have the {remotes} package installed.
library(speedtest)
library(stringi)
library(hrbrthemes)
library(ggbeeswarm)
library(tidyverse)
# current verison
packageVersion("speedtest")
## [1] '0.2.0'
config <- spd_config()
servers <- spd_servers(config=config)
closest_servers <- spd_closest_servers(servers, config=config)
only_the_best_severs <- spd_best_servers(closest_servers, config)
glimpse(spd_download_test(closest_servers[1,], config=config))
## Observations: 1
## Variables: 15
## $ url <chr> "http://speedtest.nyc.rr.com/speedtest/upload.php"
## $ lat <dbl> 40.7127
## $ lng <dbl> -74.0059
## $ name <chr> "New York, NY"
## $ country <chr> "United States"
## $ cc <chr> "US"
## $ sponsor <chr> "Spectrum"
## $ id <chr> "16976"
## $ host <chr> "speedtest.nyc.rr.com:8080"
## $ url2 <chr> NA
## $ min <dbl> 127.2843
## $ mean <dbl> 999.9776
## $ median <dbl> 776.5936
## $ max <dbl> 2245.832
## $ sd <dbl> 825.7982
glimpse(spd_download_test(only_the_best_severs[1,], config=config))
## Observations: 1
## Variables: 17
## $ total_time <dbl> 0.003372
## $ retrieval_time <dbl> 1.9e-05
## $ url <chr> "http://nyc.speedtest.sbcglobal.net/speedtest/upload.php"
## $ lat <dbl> 40.7127
## $ lng <dbl> -74.0059
## $ name <chr> "New York, NY"
## $ country <chr> "United States"
## $ cc <chr> "US"
## $ sponsor <chr> "AT&T"
## $ id <chr> "5029"
## $ host <chr> "nyc.speedtest.sbcglobal.net:8080"
## $ url2 <chr> NA
## $ min <dbl> 461.7571
## $ mean <dbl> 1377.858
## $ median <dbl> 1476.05
## $ max <dbl> 1828.417
## $ sd <dbl> 419.8095
glimpse(spd_upload_test(only_the_best_severs[1,], config=config))
## Observations: 1
## Variables: 17
## $ total_time <dbl> 0.003372
## $ retrieval_time <dbl> 1.9e-05
## $ url <chr> "http://nyc.speedtest.sbcglobal.net/speedtest/upload.php"
## $ lat <dbl> 40.7127
## $ lng <dbl> -74.0059
## $ name <chr> "New York, NY"
## $ country <chr> "United States"
## $ cc <chr> "US"
## $ sponsor <chr> "AT&T"
## $ id <chr> "5029"
## $ host <chr> "nyc.speedtest.sbcglobal.net:8080"
## $ url2 <chr> NA
## $ min <dbl> 92.66968
## $ mean <dbl> 340.4642
## $ median <dbl> 318.1886
## $ max <dbl> 586.9351
## $ sd <dbl> 170.5776
glimpse(spd_upload_test(closest_servers[1,], config=config))
## Observations: 1
## Variables: 15
## $ url <chr> "http://speedtest.nyc.rr.com/speedtest/upload.php"
## $ lat <dbl> 40.7127
## $ lng <dbl> -74.0059
## $ name <chr> "New York, NY"
## $ country <chr> "United States"
## $ cc <chr> "US"
## $ sponsor <chr> "Spectrum"
## $ id <chr> "16976"
## $ host <chr> "speedtest.nyc.rr.com:8080"
## $ url2 <chr> NA
## $ min <dbl> 75.0513
## $ mean <dbl> 145.8827
## $ median <dbl> 134.05
## $ max <dbl> 234.6362
## $ sd <dbl> 57.07895
Choose closest, “best” and randomly (there can be, and are, some dups as a result for best/closest), run the test and chart the results. This will show just how disparate the results are from these core/crude tests. Most of the test servers compensate when they present the results. Newer, “socket”-based tests are more accurate but there are no free/hidden exposed APIs yet for most of them.
set.seed(8675309)
bind_rows(
closest_servers[1:3,] %>%
mutate(type="closest"),
only_the_best_severs[1:3,] %>%
mutate(type="best"),
filter(servers, !(id %in% c(closest_servers[1:3,]$id, only_the_best_severs[1:3,]$id))) %>%
sample_n(3) %>%
mutate(type="random")
) %>%
group_by(type) %>%
ungroup() -> to_compare
select(to_compare, sponsor, name, country, host, type)
## # A tibble: 9 x 5
## sponsor name country host type
## <chr> <chr> <chr> <chr> <chr>
## 1 Spectrum New York, NY United States speedtest.nyc.rr.com:8080 closest
## 2 AT&T New York, NY United States nyc.speedtest.sbcglobal.net:8080 closest
## 3 Speedtest.net New York, NY United States nyc.host.speedtest.net:8080 closest
## 4 AT&T New York, NY United States nyc.speedtest.sbcglobal.net:8080 best
## 5 Pilot New York, NY United States speedtest.pilotfiber.com:8080 best
## 6 Spectrum New York, NY United States speedtest.nyc.rr.com:8080 best
## 7 Bell Mobility Winnipeg, MB Canada wnpcfspd01.srvr.bell.ca:8080 random
## 8 KamaTera INC Rosh HaAyin Israel speedtest.il.kamatera.com:8080 random
## 9 LifeNet Nossa Senhora do Socorro Brazil sptest.lifenet.net.br:8080 random
map_df(1:nrow(to_compare), ~{
spd_download_test(to_compare[.x,], config=config, summarise=FALSE, timeout=30)
}) -> dl_results_full
mutate(dl_results_full, type=stri_trans_totitle(type)) %>%
ggplot(aes(type, bw, fill=type)) +
geom_quasirandom(aes(size=size, color=type), width=0.15, shape=21, stroke=0.25) +
scale_y_continuous(expand=c(0,5)) +
scale_size(range=c(2,6)) +
scale_color_manual(values=c(Random="#b2b2b2", Best="#2b2b2b", Closest="#2b2b2b")) +
scale_fill_ipsum() +
labs(x=NULL, y=NULL, title="Download bandwidth test by selected server type",
subtitle="Circle size scaled by size of file used in that speed test") +
theme_ipsum_rc(grid="Y") +
theme(legend.position="none")
Choose closest and “best” and filter duplicates out since we’re really trying to measure here vs show the disparity:
bind_rows(
closest_servers[1:3,] %>% mutate(type="closest"),
only_the_best_severs[1:3,] %>% mutate(type="best")
) %>%
distinct(.keep_all=TRUE) -> to_compare
select(to_compare, sponsor, name, country, host, type)
## # A tibble: 6 x 5
## sponsor name country host type
## <chr> <chr> <chr> <chr> <chr>
## 1 Spectrum New York, NY United States speedtest.nyc.rr.com:8080 closest
## 2 AT&T New York, NY United States nyc.speedtest.sbcglobal.net:8080 closest
## 3 Speedtest.net New York, NY United States nyc.host.speedtest.net:8080 closest
## 4 AT&T New York, NY United States nyc.speedtest.sbcglobal.net:8080 best
## 5 Pilot New York, NY United States speedtest.pilotfiber.com:8080 best
## 6 Spectrum New York, NY United States speedtest.nyc.rr.com:8080 best
map_df(1:nrow(to_compare), ~{
spd_upload_test(to_compare[.x,], config=config, summarise=FALSE, timeout=30)
}) -> ul_results_full
ggplot(ul_results_full, aes(x="Upload Test", y=bw)) +
geom_quasirandom(aes(size=size, fill="col"), width=0.1, shape=21, stroke=0.25, color="#2b2b2b") +
scale_y_continuous(expand=c(0,0.5)) +
scale_size(range=c(2,6)) +
scale_fill_ipsum() +
labs(x=NULL, y=NULL, title="Upload bandwidth test by selected server type",
subtitle="Circle size scaled by size of file used in that speed test") +
theme_ipsum_rc(grid="Y") +
theme(legend.position="none")