繁体   English   中英

ubuntu 14.04 python请求缓慢

[英]ubuntu 14.04 python requests slow

我正在对https服务器进行Python请求。 这些https请求未经验证。

当我在Ubuntu 14.04 64位下运行时,我遇到了障碍 - 我的速度比我在Sles 11 32位下运行并且如果我在Windows Pro 64位下运行时慢了大约1秒。 我将不得不确认,但我认为它在RHEL和Python 2.7的版本下运行良好

更改请求版本似乎没有改变它将python从2.6更改为2.7似乎没有改变它。

还有其他问题。

建议?

这可能不是python请求问题。

下面的片段显示了我以为我在做什么。 它在两个Linux系统上以预期的快速运行。 “真正的”代码在Python Unittest框架中,包含请求的包装器。 当我检测包装器并在包装器中打印r.elapsed时,我仍然看到我报告的问题。 再一次,当我在那个包装器之外运行时,它很快。

我担心的是,我把我的“工作”代码放在一个新的系统上,注意到一个急剧的减速。 大约0.5秒的许多请求现在需要1.5秒。 我的总批次过去需要6秒,现在需要60秒。 'fix'似乎是python-request调用的一些支持代码。

事实证明,在较新的Ubuntu Linux 14.04中,get请求工作正常,Windows系统和较旧的Linux都运行不正常。 这是我的代码错误。 但它“正在工作”请参阅下面的示例代码。

在有缺陷的系统上......非基于会话的呼叫就像基于会话的呼叫一样。 两者都以相同的速度运行 - 快速 - 基于会话的速度。

在工作系统上......系统确实区分了基于会话的get和基于非会话的get。 基于会话的运行速度更快。
http://docs.python-requests.org/en/latest/user/advanced/

考虑:

  #here we spin up a session.
  s = requests.Session()
  s.auth = restCreds

  #on a buggy system these two calls will be the same speed.
  #on a fixed system they will probably differ.

  #this will do a non session based request call.
  r = requests.get(url, auth=restCreds, verify=False)
  #this will do a session based request call.
  r = s.get(url, auth=restCreds, verify=False)

  #thanks! posting w/ an example helped me find the problem
  #hope it helps the next person.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM