Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing requests very slow (4 seconds) on Raspberry Pi #5080

Closed
dagwieers opened this issue May 3, 2019 · 2 comments
Closed

Importing requests very slow (4 seconds) on Raspberry Pi #5080

dagwieers opened this issue May 3, 2019 · 2 comments

Comments

@dagwieers
Copy link

We found that importing requests on Raspberry Pi is very slow.
It takes 4 seconds.

Given that Kodi calls python addons for every menu change, navigating within addons is dreadfully slow (at least 4 seconds in between clicks).

Profiling and system call tracing output at: Freso/script.module.requests#25

Looking for a way to disable specific packages and keep requests more simple in nature.

Expected Result

Sub-second behaviour as on Windows and Android.

Actual Result

It appears that compiling the rfc3986 regular expressions is taking up most of the meat here.

Reproduction Steps

#!/usr/bin/python

import sys

sys.path.append('/storage/.kodi/addons/script.module.chardet/lib')
sys.path.append('/storage/.kodi/addons/script.module.urllib3/lib')
sys.path.append('/storage/.kodi/addons/script.module.certifi/lib')
sys.path.append('/storage/.kodi/addons/script.module.idna/lib')
sys.path.append('/storage/.kodi/addons/script.module.requests/lib')

import cProfile

pr = cProfile.Profile()
pr.enable()
import requests

requests.get('https://vrtnu-api.vrt.be/suggest?facets[transcodingStatus]=AVAILABLE').json()
pr.disable()
pr.dump_stats('/tmp/profiling_stats')

System Information

$ python -m requests.help

This also takes 5 seconds ;-)

kodi03:~ # python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  }, 
  "cryptography": {
    "version": ""
  }, 
  "idna": {
    "version": "2.8"
  }, 
  "implementation": {
    "name": "CPython", 
    "version": "2.7.15"
  }, 
  "platform": {
    "release": "4.19.23", 
    "system": "Linux"
  }, 
  "pyOpenSSL": {
    "openssl_version": "", 
    "version": null
  }, 
  "requests": {
    "version": "2.21.0"
  }, 
  "system_ssl": {
    "version": "1000211f"
  }, 
  "urllib3": {
    "version": "1.25.2"
  }, 
  "using_pyopenssl": false
}
@Freso
Copy link

Freso commented May 3, 2019

As I said in Freso/script.module.requests#25 (comment), this is almost certainly directly due to urllib3/urllib3#1590 (@dagwieers even mentions rfc3986 compiling regexes himself as well) and may thus not really be a requests issue, though there might be something requests could maybe do to mitigate slowness induced by 3rd party dependencies?

Freso referenced this issue in Freso/script.module.urllib3 May 5, 2019
Due to urllib3 v1.25.x’s inclusion of `rfc3986` it’s compiling a bunch
of regexes every time `urllib3` is imported… which it is every time
`requests` is imported, which is imported by a ton of Kodi add‐ons.

The best solution here would be either for `urllib3` (or `rfc3986`) to
be smarter about the regex compiling, or for Kodi to not need to
reimport Python libraries on every view change… However, neither of
those are here‐and‐now fixes and upstream `urllib3` have released a
version of 1.24.x which includes the security fix that was previously
only available in the 1.25.x releases, so downgrading to 1.24.3 until
this is handled better either by urllib3, its consumers, or Kodi itself.

Fixes #3
and Freso/script.module.requests#25

See also issue reported to upstream:
urllib3/urllib3#1590

And issue reported to upstream `requests`:
https://github.com/kennethreitz/requests/issues/5080

Based on urllib3-1.24.3.tar.gz from PyPI:
https://pypi.org/project/urllib3/1.24.3/#files
@nateprewitt
Copy link
Member

This should have been resolved through the outcomes of urllib3/urllib3#1590.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants