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

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

Open
Matthew-Jenkins opened this issue Nov 5, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Matthew-Jenkins
Copy link

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

@moledaemon moledaemon self-assigned this Mar 17, 2021
@moledaemon
Copy link
Collaborator

Thanks, will work this in to a future commit

@moledaemon moledaemon added the enhancement New feature or request label Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants