开发者

How to choose closest/fastest mirror in Python?

开发者 https://www.devze.com 2023-03-09 08:22 出处:网络
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. I

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?


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()


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

0

精彩评论

暂无评论...
验证码 换一张
取 消