You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
100% processor usage during GET have to wait 60s for response #1910
When GET request have to wait 60s for remote service response, processor usage increases to 100% - version 1 of "requests" worked in this case better.
GET is configured with "cert" data and "timeout=120" over SSL connection.
More details: GET is fired by sub-process (multiprocessing) - GET is calling API exposed by GSM operator - by this API I am receiving SMS and MMS. Other tasks fired by sub-proceses are using CPU below 1% (server with 2 Xeons).
I can expose on my server, over valid SSL, PHP script with 60s delay if this is what You mean?
Unfortunately I can not give You access to API exposed by GSM operator :(
Here You are - direct call of requests.get from my library
(which is launched by multiprocessing.Process(target=launch_function,
args=('arg1', 'arg2')) ):
I am in my phone, so I'll be brief. I suspect this is pyopenssl interacting with tje timeout. Especially the makefile function in urllib3.contrib.pyopenssl busylooping when no data is being recieved
This is a guess (I think I stumbled upon this previously). I'll check it later. Maybe gevent is also an issue. Gevent and pyopenssl don't really work together.
Yes, I have: py27-asn1-0.1.4_1,1, py27-ndg_httpsclient-0.3.2, py-openssl 0.13 but following the FreeBSD ports tree:
py27-asn1 is required by py27-ndg_httpsclient
py27-ndg_httpsclient is required by py-urllib3 (mentioned by @t-8ch) and requires to run: py-openssl and py-asn1
Of course, I can de-install any of them, but I like to keep full functionality of requests (SSL, cert. etc.). What I should to do - "to be or not to be, this is the question..." ;)
# netcat from the nmap project, should work with all ssl capable netcats# We complete the SSL handshake but don't send a HTTP response line!
$ ncat --ssl -l 0.0.0.0 4000
Hi there, sorry to jump into this discussion, but I'm switching some legacy url resolver mechanism from urllib2 to requests 2.2.1 . Although requests works much better, the server's CPU started to scale in an erratic manner, whereas in the past it was kind of constant under 10% usage. We resolve, http and https urls, using a custom header and verify=True. Do you know if this is an issue and what might be causing it?
It's possible that this is your bug, if you're accessing HTTPS urls and have pyopenssl installed. If both of those things are true, try applying the above patch to your installed requests package and check if it resolves your problem.
Nope, I don't use pyopenssl and this also happens, when I don't set the verify option. I wonder whether there's any overhead associated with get methods, as opposed to initialising a Session object and have different threads calling send. If none of this matters substantially, are you aware of any other high CPU issues related to requests?
There's definitely overhead when using get: we create a Session object behind the scenes for each call.
You should consider having a single Session object, but note that it's not really thread-safe. If using a single Session, you should either serialize access to it or have it run in its own thread and send messages in and out on queues.
Otherwise, we're not aware of any high CPU issues and it'd be interesting to get diags if you still hit it.
I have a similar issue. Basically there are cpu peaks after switching from urllib2 to request to make get and post petitions. Basically Im seeeing a lot of FUTEX WAIT after stracing my process.
I'm a bit confused with respect of the default behaviour of the connection pool.
Is there a global Session by default shared among all the requests made?.
Do requests to a single host share the same connection in teh pool?
Is that shared connection in the pool blocking?
Could the pool cache size and pool size affecting?
No. As I said above, we create a Session object behind the scenes if you aren't using one yourself.
Not always. Connection pools belong to Sessions, so if you aren't using Sessions you aren't using connection pools. We then have a pool of connections to each host. Whether requests to that host re-use a connection or not depends on whether or not the connection is still open.
Basically in the cpu peaks Im getting lots of futex(..., FUTEX_WAIT, 1, NULL)
I thought that could be related to a some lock on some variables inside requests
Activity
Lukasa commentedon Feb 11, 2014
Do you have a publicly-accessible URL that I can test against?
e-manuel commentedon Feb 11, 2014
More details: GET is fired by sub-process (multiprocessing) - GET is calling API exposed by GSM operator - by this API I am receiving SMS and MMS. Other tasks fired by sub-proceses are using CPU below 1% (server with 2 Xeons).
I can expose on my server, over valid SSL, PHP script with 60s delay if this is what You mean?
Unfortunately I can not give You access to API exposed by GSM operator :(
Lukasa commentedon Feb 11, 2014
Hmm. In that case, can you show me your code? Feel free to remove identifying information (like URLs, header values etc.)
e-manuel commentedon Feb 11, 2014
Here You are - direct call of requests.get from my library
(which is launched by multiprocessing.Process(target=launch_function,
args=('arg1', 'arg2')) ):
p_par = {
'login': 'xxx',
'password': 'xxx',
'serviceId': '0000',
'timeout': 60000, # wait 60s for response
'deleteContent': 'true',
'manualconfirm': 'true'
}
p_uri_part = 'getsms.aspx'
def __request_api2(self, p_par, p_uri_part=None):
try:
# GSM
if self.__channel == '0':
v_url = '{0}/{1}'.format(self.__API_0_URL, p_uri_part)
v_crt = '{0}smsapi.crt'.format(self.__PATH_RES_SEC)
v_key = '{0}smsapi.key'.format(self.__PATH_RES_SEC)
try:
v_rsp = requests.get(
v_url, params=p_par
,cert=(v_crt, v_key)
,timeout=120
,verify='{0}ca_root_certificates.pem'.format(self.__PATH_RES_SEC)
)
v_res = v_rsp.text
except Exception as e:
self.__add_error('Error when invoking API: {0}'.format(str(e)))
v_res = 0
finally:
return v_res
ca_root_certificates.pem - is grabbed from Mozilla - CA bundle
Best regards,
Artur
Lukasa commentedon Feb 11, 2014
GitHub's email formatting made that pretty difficult to read, so I copy-pasted it into a code block here:
Lukasa commentedon Feb 11, 2014
Hmm, there's nothing obviously wrong with that. When I get a moment I'll try to reproduce something similar on my machine.
t-8ch commentedon Feb 11, 2014
I am in my phone, so I'll be brief. I suspect this is pyopenssl interacting with tje timeout. Especially the makefile function in urllib3.contrib.pyopenssl busylooping when no data is being recieved
Lukasa commentedon Feb 11, 2014
Wait, does it do that? That's pretty awful.
t-8ch commentedon Feb 11, 2014
This is a guess (I think I stumbled upon this previously). I'll check it later. Maybe gevent is also an issue. Gevent and pyopenssl don't really work together.
t-8ch commentedon Feb 11, 2014
Hm, I can't reproduce this at the moment.
@e-manuel Could you give more information about your environment:
e-manuel commentedon Feb 11, 2014
t-8ch commentedon Feb 11, 2014
Do you also have
pyasn1andndg-httpsclientinstalled? (If they andpyOpenSSLare installed they trigger a different codepath)e-manuel commentedon Feb 11, 2014
Yes, I have:
py27-asn1-0.1.4_1,1,py27-ndg_httpsclient-0.3.2,py-openssl 0.13but following the FreeBSD ports tree:py27-asn1is required bypy27-ndg_httpsclientpy27-ndg_httpsclientis required bypy-urllib3(mentioned by @t-8ch) and requires to run:py-opensslandpy-asn1Of course, I can de-install any of them, but I like to keep full functionality of requests (SSL, cert. etc.). What I should to do - "to be or not to be, this is the question..." ;)
t-8ch commentedon Feb 11, 2014
So I managed to reproduce it:
Terminal 1:
Code:
It seems this only happens when using PyOpenSSL, timeouts and FreeBSD.
I can't reproduce it any other way, permutating those conditions and on Linux.
@e-manuel Pick your poison :-)
t-8ch commentedon Feb 11, 2014
Manually waiting for the buffer to be ready seems to fix it:
(Insert lengthy rant about platform differences, especially concerning openssl here)
13 remaining items
Lukasa commentedon Feb 18, 2014
Suits me. =)
e-manuel commentedon Feb 19, 2014
@t-8ch You are great - now timeout works fine in every case - and may CPUs can "sleep" calmly ;)
Lukasa commentedon Mar 23, 2014
This will be fixed in the next release of requests, so I'm closing this. Thanks for your help all!
tgalery commentedon Mar 26, 2014
Hi there, sorry to jump into this discussion, but I'm switching some legacy url resolver mechanism from urllib2 to requests 2.2.1 . Although requests works much better, the server's CPU started to scale in an erratic manner, whereas in the past it was kind of constant under 10% usage. We resolve,
httpandhttpsurls, using a custom header andverify=True. Do you know if this is an issue and what might be causing it?Lukasa commentedon Mar 26, 2014
It's possible that this is your bug, if you're accessing HTTPS urls and have
pyopensslinstalled. If both of those things are true, try applying the above patch to your installed requests package and check if it resolves your problem.tgalery commentedon Mar 26, 2014
Nope, I don't use
pyopenssland this also happens, when I don't set the verifyoption. I wonder whether there's any overhead associated withgetmethods, as opposed to initialising aSessionobject and have different threads callingsend. If none of this matters substantially, are you aware of any other high CPU issues related to requests?Lukasa commentedon Mar 26, 2014
There's definitely overhead when using
get: we create aSessionobject behind the scenes for each call.You should consider having a single
Sessionobject, but note that it's not really thread-safe. If using a singleSession, you should either serialize access to it or have it run in its own thread and send messages in and out on queues.Otherwise, we're not aware of any high CPU issues and it'd be interesting to get diags if you still hit it.
dav009 commentedon Mar 28, 2014
I have a similar issue. Basically there are cpu peaks after switching from urllib2 to request to make get and post petitions. Basically Im seeeing a lot of
FUTEX WAITafter stracing my process.I'm a bit confused with respect of the default behaviour of the connection pool.
Thank you in advance
Lukasa commentedon Mar 28, 2014
Sessionobject behind the scenes if you aren't using one yourself.Sessions, so if you aren't usingSessions you aren't using connection pools. We then have a pool of connections to each host. Whether requests to that host re-use a connection or not depends on whether or not the connection is still open.dav009 commentedon Mar 28, 2014
Basically in the cpu peaks Im getting lots of
futex(..., FUTEX_WAIT, 1, NULL)I thought that could be related to a some lock on some variables inside requests
Lukasa commentedon Mar 28, 2014
There is some locking around the connection pool and the cookies dictionary, so it's certainly possible.
fix 100% CPU usage on BSD system
fix 100% CPU usage on BSD system (OS X)