如何在Python中选择最近/最快的镜像?
我一直在思考如何用Python实现镜像选取。当我调用服务 API 时,我收到带有 IP 地址的响应。现在我想获取该地址并检查它是否离我很近。如果没有,请重试。我考虑过 ping,因为我对同一数据中心托管的 IP 地址只有大约 1 毫秒的 ping 时间,但在全球范围内要高得多。我查了一些如何在 Python 中实现 ping 的示例,但它看起来相当复杂,感觉有点 hackish(比如检查目标 IP 是否小于 10 毫秒)。可能有更好的方法来解决这个问题,但我可能不知道。
你有什么想法?我无法每次都下载任何测试文件来测试速度。 GeoIP 还是 ping?还是别的什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
YUM fastmirror 插件 使用一种粗略的方法来计时连接到某个镜像所需的时间。远程服务器上的端口。虽然它很粗糙,但它测量的是延迟而不是带宽,但它相当有效:
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:
调用所有服务 API 实例并使用响应最快的一个。
Call all the service API instances and use which ever responds quickest.