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

Lack of HTTP connection reuse makes repeated queries slow #98

Open
MattBlissett opened this issue Sep 9, 2022 · 0 comments
Open

Lack of HTTP connection reuse makes repeated queries slow #98

MattBlissett opened this issue Sep 9, 2022 · 0 comments
Milestone

Comments

@MattBlissett
Copy link
Member

MattBlissett commented Sep 9, 2022

PyGBIF makse makes a new HTTP connection for every request, which has a lot of overhead. It would be much quicker to use the requests module with sessions, so the connection can be reused.

(@mdoering's words via email, CC @juliancabezas)

Looking at the python client code I see it does not reuse connections at all, thus it has to do all the TCP/SSL overhead each time!
https://stackoverflow.com/questions/24873927/python-requests-module-and-connection-reuse

If I use the requests module manually with http sessions it becomes a lot quicker:

import logging, requests, timeit
timeit.timeit('_ = requests.get("https://api.gbif.org/v1/species/match?name=Poa%20annua")', 'import requests', number=100)
12.797771417999911
timeit.timeit('_ = session.get("https://api.gbif.org/v1/species/match?name=Poa%20annua")', 'import requests; session = requests.Session()', number=100)
3.185472910000044

It would need a bigger change to the pygbif codebase to support that.

@CecSve CecSve added this to the v0.7 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants