From 563cf021c96446aa15a41c1f532067d13d880b41 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 8 Dec 2013 15:13:23 -0500 Subject: db-import: detect best package mirror --- db-pick-mirror | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 db-pick-mirror (limited to 'db-pick-mirror') diff --git a/db-pick-mirror b/db-pick-mirror new file mode 100755 index 0000000..7cbc032 --- /dev/null +++ b/db-pick-mirror @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require 'json' +require 'rest_client' + +protocol = ARGV[0] +jsonurl = ARGV[1] + +data = JSON::parse(RestClient.get(jsonurl)) + +if data["version"] != 3 + print "Data format version != 3" + exit 1 +end + +urls = data["urls"] +rsync_urls = urls.select{|a| a["protocol"]==protocol} + +# By score ( (delay+speed)/completion ) +#best = rsync_urls.sort{|a,b| (a["score"] || Float::INFINITY) <=> (b["score"] || Float::INFINITY) }.first +# By delay/completion ; hopefully this gives us a tier 1 mirror +best = rsync_urls.sort{|a,b| a["delay"]/a["completion_pct"] <=> b["delay"]/b["completion_pct"] }.first + +puts best["url"] -- cgit v1.2.3-2-g168b From 88472049c1e8ccd64f355eed2ce624954539944d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 17 Jun 2014 21:19:10 -0400 Subject: db-pick-mirror: remove obsolete comment --- db-pick-mirror | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'db-pick-mirror') diff --git a/db-pick-mirror b/db-pick-mirror index 7cbc032..9474ed7 100755 --- a/db-pick-mirror +++ b/db-pick-mirror @@ -18,7 +18,7 @@ rsync_urls = urls.select{|a| a["protocol"]==protocol} # By score ( (delay+speed)/completion ) #best = rsync_urls.sort{|a,b| (a["score"] || Float::INFINITY) <=> (b["score"] || Float::INFINITY) }.first -# By delay/completion ; hopefully this gives us a tier 1 mirror +# By delay/completion best = rsync_urls.sort{|a,b| a["delay"]/a["completion_pct"] <=> b["delay"]/b["completion_pct"] }.first puts best["url"] -- cgit v1.2.3-2-g168b From 91b26994d40f7ea23f5bc7ef8e4e40e1af115e7a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 16 Apr 2016 14:30:39 -0400 Subject: db-pick-mirror: use Net::HTTP instead of RestClient --- db-pick-mirror | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'db-pick-mirror') diff --git a/db-pick-mirror b/db-pick-mirror index 9474ed7..6adcdaf 100755 --- a/db-pick-mirror +++ b/db-pick-mirror @@ -1,12 +1,12 @@ #!/usr/bin/env ruby require 'json' -require 'rest_client' +require 'net/http' protocol = ARGV[0] jsonurl = ARGV[1] -data = JSON::parse(RestClient.get(jsonurl)) +data = JSON::parse(Net::HTTP.get(URI(jsonurl))) if data["version"] != 3 print "Data format version != 3" -- cgit v1.2.3-2-g168b From 752bd700e9da464006bfbd9877cc858dfad545ba Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 16 Apr 2016 14:31:34 -0400 Subject: db-pick-mirror: filter out URLs with incomplete information --- db-pick-mirror | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'db-pick-mirror') diff --git a/db-pick-mirror b/db-pick-mirror index 6adcdaf..4d01b95 100755 --- a/db-pick-mirror +++ b/db-pick-mirror @@ -13,7 +13,8 @@ if data["version"] != 3 exit 1 end -urls = data["urls"] +# Filter out URLs with incomplete information +urls = data["urls"].select{|a| a.none?{|k,v|v.nil?}} rsync_urls = urls.select{|a| a["protocol"]==protocol} # By score ( (delay+speed)/completion ) -- cgit v1.2.3-2-g168b