Skip to content

Performance: use requests.Session() to reduce tcp and ssl handshake overhead.  #8

@Matthew-Jenkins

Description

@Matthew-Jenkins

sess = requests.Session()
sess.get()

will have far better performance and use less bandwidth due to not having to repeat tcp handshake and ssl handshakes. My tests show about twice as fast.

See 2 examples:
(venv) 15645(0811)mattjenkins@DatapriseMBP:Automox$ cat test.py test2.py
import requests

for x in range(1,100):
if (result := requests.get('https://www.google.com')):
pass
else:
print(False)
import requests

sess = requests.Session()
for x in range(1,100):
if (result := sess.get('https://www.google.com')):
pass
else:
print(False)

(venv) 15646(0811)mattjenkins@DatapriseMBP:Automox$ time python test.py

real 0m13.911s
user 0m1.774s
sys 0m0.149s
(venv) 15647(0811)mattjenkins@DatapriseMBP:Automox$ time python test2.py

real 0m6.672s
user 0m0.488s
sys 0m0.083s

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions