【问题标题】:How to know response time of a website? [duplicate]如何知道网站的响应时间? [复制]
【发布时间】:2012-08-12 18:51:52
【问题描述】:

可能重复:
Measuring ping latency of a server - Python

There are a few servers such as

http://server1.stackoverflow.com
http://server2.stackoverflow.com
http://server3.stackoverflow.com
http://server4.stackoverflow.com

我想知道目前哪些链接的响应时间最短。我该怎么办?

我正在考虑:timeit 或 ping 服务器。

如果您能给我一个样品或任何想法,我将不胜感激,谢谢。 :)

【问题讨论】:

    标签: python sockets timeout ping timeit


    【解决方案1】:

    你为什么要自己做这件事?通常应用程序服务器在负载均衡器后面运行,希望将您的请求重定向到负载最少的机器......在这种情况下的负载平衡 - 由您自己完成 - 在地理分布的应用程序服务器设置中可能有意义,但在这里没有Stackoverflow 服务器。那么你的用例是什么?

    另见

    Measuring ping latency of a server - Python

    【讨论】:

    • 就是一个例子,想想你要选择代理服务器...
    【解决方案2】:

    我想用谷歌搜索半天,是这样的吗?

    url = ""
    
    f = urllib.urlopen(url)
    start = time.time()
    page = f.read()
    end = time.time()
    f.close()
    

    有更好的方法吗?

    【讨论】:

      【解决方案3】:

      你可以使用popen来执行ping命令:

      例如,让我们获取stackoverflow 中的三个nameservers 并ping 它们。 最快的将是平均时间最短的

      import os
      lis3=['64.34.119.33','64.34.119.34','69.59.196.217'] #nameservers of SO
      lis2=[]
      for x in lis3:
          strs=os.popen("ping "+x).read()
          #print strs
          time=strs[strs.rfind(' ')+1:strs.rfind('ms')]
          lis2.append(int(time))
      
      minn=lis3[lis2.index(min(lis2))]
      print 'lowest average time is from {0}'.format(minn)
      

      输出:

      lowest average time is from 69.59.196.217
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-18
        • 2016-11-15
        • 1970-01-01
        相关资源
        最近更新 更多