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

Re-use Session object not to create a new connection each time #5

Open
cryoff opened this issue Aug 15, 2022 · 1 comment
Open

Re-use Session object not to create a new connection each time #5

cryoff opened this issue Aug 15, 2022 · 1 comment

Comments

@cryoff
Copy link

cryoff commented Aug 15, 2022

When doing a lot of requests to the same endpoint, it is probably helpful for runtime (and also is "cheaper" on OA server side, I guess) not to create a new connection each time but re-use Session object.
Please correct me if I am wrong here.
I also have done minor changes to test that - it seems to work faster (and hopefully "cheaper" on server side), so i can do a small PR.

@smierz
Copy link
Owner

smierz commented Aug 25, 2022

Hello @cryoff ,
thanks for your issue. I was already thinking about using sessions but haven't had time yet to look deeper into it.

As far as I understand it, they may be helpful for doing multiple requests but would be a bit over the top for few or single requests since they are costly to create --> should not be the default.

To me the main questions are where to put the session and when to use it?

  • About Where : Maybe the session could hold the values that the api_caller currently holds and be stored there.

  • About When: it's hard to say if a method call will require a lot of requests, I think. In the end the user should decide if it makes sense to create a session for their use case or not, so the best place may be when creating the openalex object, there could be a boolean that decides if a session will be created.

Does that make sense to you or did you have other ideas?

Another thing connected to this issue is that the OpenAlex API now introduced a burst rate limit of 10 requests per second. This would also affect the session object since it might make multiple requests too fast, so they fail. So this should be considered and handled at this point as well when introducing a session to the library, so a bit of research is needed to look into available solutions/libraries.
Maybe you know of one?

Let me know what you think!

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