2

I've been thinking about how to implement mirror picking in Python. When I call on service API I get response with IP address. Now I want to take that address and check if it's close to me or not. If not, retry. I thought about pinging, as I have only ~1ms ping to the IP addresses hosted in same data center, but much higher across the world. I looked up some examples of how to implement pinging in Python, but it seems fairly complicated and feels a bit hackish (like checking if target IP is less than 10ms). There may be better ways to tackle this issue, that I may not be aware of.

What are your ideas? I can't download any test file each time to test speed. GeoIP or ping? Or something else?

Gargauth
  • 2,495
  • 6
  • 27
  • 30

2 Answers2

4

The YUM fastestmirror plugin uses a crude method of timing how long it takes to connect to a port on the remote server. Whilst its crude, it measures lag rather than bandwidth, it is fairly effective:

time_before = time.time()
sock.connect((self.host, self.port))
result = time.time() - time_before
sock.close()
linuts
  • 6,608
  • 4
  • 35
  • 37
1

Call all the service API instances and use which ever responds quickest.

tMC
  • 18,105
  • 14
  • 62
  • 98