Memory usage

Memory usage seems to be abnormally high for requests when using python 2.7.

Request version being tested is 2.9.1 installed by pip. "pip show requests" output will be at the end.

I'm unsure if this is an "issue", but it seems to be using 25MB just by importing requests.

Testing was done using memory_profiler. I've included simple test code and some output.
https://pypi.python.org/pypi/memory_profiler

There's also a noticeable wait time when importing with python 2.7.

```
from memory_profiler import profile

@profile
def request_test():
    import requests

@profile
def urllib3_test():
    import urllib3

request_test()
urllib3_test()
```

```
$ python test.py
Filename: test.py

Line #    Mem usage    Increment   Line Contents
================================================
     3     12.2 MiB      0.0 MiB   @profile
     4                             def request_test():
     5     37.8 MiB     25.6 MiB       import requests


Filename: test.py

Line #    Mem usage    Increment   Line Contents
================================================
     8     37.8 MiB      0.0 MiB   @profile
     9                             def urllib3_test():
    10     38.2 MiB      0.3 MiB       import urllib3

```

```
$ python3 test.py
Filename: test.py

Line #    Mem usage    Increment   Line Contents
================================================
     3     12.4 MiB      0.0 MiB   @profile
     4                             def request_test():
     5     19.4 MiB      7.0 MiB       import requests


Filename: test.py

Line #    Mem usage    Increment   Line Contents
================================================
     8     19.5 MiB      0.0 MiB   @profile
     9                             def urllib3_test():
    10     20.0 MiB      0.4 MiB       import urllib3
```

```
$ pip2.7 show requests

---
Metadata-Version: 2.0
Name: requests
Version: 2.9.1
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
```

```
$ pip3.4 show requests

---
Metadata-Version: 2.0
Name: requests
Version: 2.9.1
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: Apache 2.0
Location: /usr/local/lib/python3.4/dist-packages
```


update:

After upgrading all OTHER python packages, the memory usage with python 2.7 dropped down to 7.8 MiB

Seems to be an issue with another library that is imported into requests and not actually caused by requests itself.


@IDSninja do you have a list of the packages you upgraded? Requests doesn't import anything external, with a few small exceptions. 


I just used this command to update everything.... So I'm not really sure which one fixed it.

```
pip2.7 freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip2.7 install -U
```


@IDSninja can you show us the output of `$ pip2.7 freeze`?


Here you go. This is running on Kali so there's quite a bit installed.

```
$ pip2.7 freeze
adns-python==1.2.1
apsw==3.9.2.post1
argcomplete==1.0.0
async==0.6.2
backports-abc==0.4
backports.ssl-match-hostname==3.5.0.1
BBQSQL==1.2
BeautifulSoup==3.2.1
beautifulsoup4==4.4.1
binwalk==2.1.0
bitarray==0.8.1
BlindElephant==1.0
blinker==1.4
capstone==3.0.4
catfacts==0.1.0
certifi==2015.11.20.1
cffi==1.5.2
characteristic==14.3.0
chardet==2.3.0
Cheetah==2.4.4
chirp==1.2.2
clamd==1.0.2
cluster==1.3.1
coinbase==2.0.3
colorama==0.3.6
ConfigArgParse==0.10.0
configobj==5.0.6
configparser==3.3.0.post2
construct==2.5.2
cryptography==1.2.2
ctypeslib==0.5.6
cycler==0.9.0
d2to1==0.2.12.post1
darts.util.lru==0.5
decorator==4.0.9
defusedxml==0.4.1
dicttoxml==1.6.6
dissy==9
distorm3==3.3.0
dnspython==1.12.0
docutils==0.12
easygui==0.97.4
ecdsa==0.13
Elixir==0.7.1
enum34==1.1.2
esmre==0.3.1
et-xmlfile==1.0.1
feedparser==5.2.1
Flask==0.10.1
flickrapi==2.1.2
funcsigs==0.4
funkload==1.16.1
fuse-python==0.2.1
futures==3.0.4
GeoIP==1.3.2
gevent==1.0.2
gitdb==0.6.4
GitPython==1.0.2
greenlet==0.4.9
grey-harvest==0.1.3.5
guess-language==0.2
gyp==0.1
halberd==0.2.4
hpack==2.0.1
html2text==2015.11.4
html5lib==0.9999999
httplib2==0.9.2
idna==2.0
impacket==0.9.14
intelhex==2.0
ipaddress==1.0.16
IPy==0.83
itsdangerous==0.24
jdcal==1.2
Jinja2==2.8
jsonpickle==0.9.2
jsonrpclib==0.1.7
keepnote==0.7.8
killerbee==1.0
livestreamer==1.12.2
lxml==3.4.0
M2Crypto==0.21.1
Magic-file-extensions==0.2
Mako==1.0.3
Markdown==2.6.5
MarkupSafe==0.23
matplotlib==1.5.1
mechanize==0.2.5
memory-profiler==0.41
mercurial==3.7.1
metaconfig==0.1.4
mitmproxy==0.13
mock==1.3.0
msgpack-python==0.4.7
MySQL-python==1.2.5
ndg-httpsclient==0.4.0
netaddr==0.7.18
netlib==0.15.1
networkx==1.11
NfSpy==1.0
nltk==3.1
nose==1.3.7
numpy==1.10.4
oauth==1.0.1
oauthlib==1.0.3
openpyxl==2.3.3
oursql==0.9.3.1
PAM==0.4.2
pandas==0.17.1
paramiko==1.16.0
parse==1.6.6
passlib==1.6.5
Paste==2.0.2
PasteDeploy==1.5.2
PasteScript==2.0.2
pbr==1.8.1
pcapy==0.10.8
pdfminer==20140328
pefile==1.2.10.post114
pexpect==4.0.1
phply==0.9.1
Pillow==2.6.1
ply==3.8
prettytable==0.7.2
psutil==3.4.2
psycopg2==2.5.4
ptyprocess==0.5.1
pyasn1==0.1.9
pyasn1-modules==0.0.8
pybloomfiltermmap==0.3.14
PyBluez==0.22
pycparser==2.14
pycrypto==2.6.1
pycryptopp==0.7.1.869544967005693312591928092448767568728501330214
pycups==1.9.63
pycurl==7.43.0
pydns==2.3.6
PyGithub==1.26.0
Pygments==2.1
pygobject==3.14.0
pygraphviz==1.3rc2
pyinotify==0.9.6
pylibmc==1.5.0
pymssql==1.0.2
PyMySQL==0.7.1
PyOpenGL==3.1.0
pyOpenSSL==0.15.1
pyparsing==2.1.0
pyPdf==1.13
pyperclip==1.5.26
pyqtgraph==0.9.10
pyregfi==99.99.99.277
pyrit==0.4.0
pyrtlsdr==0.2.0
pyscard==1.6.14
pyserial==3.0.1
pysmbc==1.0.15.3
pysmi==0.0.7
pysnmp==4.3.2
pysnmp-apps==0.4.1
pysnmp-mibs==0.1.6
PySocks==1.5.6
pysqlite==2.6.3
python-apt==0.9.3.11
python-dateutil==2.4.2
python-debian==0.1.27
python-debianbts==1.11
python-Levenshtein==0.12.0
python-ntlm==1.1.0
pytidylib==0.2.4
pytz==2015.7
pyusb==1.0.0b2
PyX==0.12.1
pyxdg==0.25
PyYAML==3.11
pyzmq==14.4.0
reportbug==6.6.3
requesocks==0.10.8
requests==2.9.1
requests-oauthlib==0.6.0
requests-toolbelt==0.6.0
rfidiot==1.0
roman==2.0.0
ruamel.ordereddict==0.4.9
scapy==2.3.2
scipy==0.14.0
service-identity==14.0.0
shove==0.6.6
simplejson==3.8.1
singledispatch==3.4.0.3
six==1.10.0
slowaes==0.1a1
smmap==0.9.0
SOAPpy==0.12.22
SQLAlchemy==1.0.11
stopit==1.1.1
stuf==0.9.16
tblib==1.2.0
tornado==4.3
tweepy==3.5.0
twilio==5.3.0
Twisted==15.5.0
Twisted-Conch==14.0.2
Twisted-Core==14.0.2
Twisted-Lore==14.0.2
Twisted-Mail==14.0.2
Twisted-Names==14.0.2
Twisted-News==14.0.2
Twisted-Runner==14.0.2
Twisted-Web==14.0.2
Twisted-Words==14.0.2
urllib3==1.14
urwid==1.3.1
uTidylib==0.2
volatility==2.4
vulndb==0.0.19
wapiti==2.3.0
webunit==1.3.10
Werkzeug==0.11.3
wfuzz==0.0.0
wheel==0.29.0
wstools==0.4.3
wxPython==3.0.1.1
wxPython-common==3.0.1.1
xdot==0.6
XlsxWriter==0.8.4
xsser==1.6
Yapsy==1.11.223
yara-python==3.1
zenmap==7.1
zim==0.62
zope.interface==4.1.3
```


Aha, you do have `pyOpenSSL`! I suspect that was the cause of your memory usage. It was definitely what caused the delayed startup time. 


Interesting. Removing pyOpenSSL brings memory usage down even more (from 7.9 to 5.4MiB)

Is this recommended and does it impact functionality?


@IDSninja that's a complex question. Basically, the standard library's `ssl` library has some limitations, which `pyOpenSSL` fixes. Using it is best practice if security is a large priority for application (or you need the extra functionality it provides), but there's a slight cost. 


ok, thanks for everything.


:sparkles: :cake: :sparkles: