简体   繁体   中英

ubuntu 14.04 python requests slow

I am doing Python Requests to an https server. These https requests are unverified.

I have hit a roadblock in that when I run under Ubuntu 14.04 64 bit - my gets are about 1 second slower each than if I run under Sles 11 32 bit and if I run under Windows Pro 64 bit. I will have to confirm, but I think it ran fine under a version of RHEL and Python 2.7

Changing the requests version doesn't seem to change it Changing the python from 2.6 to 2.7 doesn't seem to change it.

Something else is the problem.

Suggestions?

This might not be a python-requests problem.

The snippet below shows what I thought I was doing. And it runs at the expected fast speed on the two Linux systems. The 'real' code is in a Python Unittest framework, with a wrapper around requests. When I instrument that wrapper and print r.elapsed in the wrapper, I still see the problem I reported. Again, when I run outside of that wrapper, its fast.

My concern is that I took my "working" code and put it on a new system and noticed a drastic slow down. Many Requests that were taking about 0.5 seconds were now taking 1.5 seconds. My total batch used to take 6 seconds and now was taking 60 seconds. The 'fix' seems to be in some support code that python-request calls.

It turns out that somehow in the newer Ubuntu Linux 14.04 the get request was working correctly, and the Windows System and the older Linux are both working incorrectly. It was my code that was in error. But it was "working" See example code below.

On the buggy systems... The non session based call acted like the session based call. And both ran the same speed - fast -- At session based speeds.

On the working system... The system indeed differentiates between session based get and non-session based get. the Session based gets run much faster.
http://docs.python-requests.org/en/latest/user/advanced/

Consider:

  #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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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