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

chore: re-use reqwest::Client instead of constructing one per request #3333

Closed
EverlastingBugstopper opened this issue Jun 29, 2023 · 0 comments · Fixed by #3703
Closed

chore: re-use reqwest::Client instead of constructing one per request #3333

EverlastingBugstopper opened this issue Jun 29, 2023 · 0 comments · Fixed by #3703
Assignees

Comments

@EverlastingBugstopper
Copy link
Contributor

EverlastingBugstopper commented Jun 29, 2023

the code that handles sending requests to uplink creates a new reqwest::Client on each request.

Reasoning from the reqwest docs on why you should re-use a client instead of building a new one:

The Client holds a connection pool internally, so it is advised that you create one and reuse it.

You do not have to wrap the Client in an Rc or Arc to reuse it, because it already uses an Arc internally.

I propose making this client a Lazy<reqwest::Client> and using that instead.

BrynCooke pushed a commit that referenced this issue Aug 29, 2023
BrynCooke added a commit that referenced this issue Aug 29, 2023
Previously uplink requests created a new reqwest client each time, this
may cause CPU spikes especially on OSX.

Fixes #3333

<!-- start metadata -->

**Checklist**

Complete the checklist (and note appropriate exceptions) before a final
PR is raised.

- [ ] Changes are compatible[^1]
- [ ] Documentation[^2] completed
- [ ] Performance impact assessed and acceptable
- Tests added and passing[^3]
    - [ ] Unit Tests
    - [ ] Integration Tests
    - [ ] Manual Tests

**Exceptions**

*Note any exceptions here*

**Notes**

[^1]. It may be appropriate to bring upcoming changes to the attention
of other (impacted) groups. Please endeavour to do this before seeking
PR approval. The mechanism for doing this will vary considerably, so use
your judgement as to how and when to do this.
[^2]. Configuration is an important part of many changes. Where
applicable please try to document configuration examples.
[^3]. Tick whichever testing boxes are applicable. If you are adding
Manual Tests:
- please document the manual testing (extensively) in the Exceptions.
- please raise a separate issue to automate the test and label it (or
ask for it to be labeled) as `manual test`

Co-authored-by: bryn <[email protected]>
garypen pushed a commit that referenced this issue Sep 12, 2023
Previously uplink requests created a new reqwest client each time, this
may cause CPU spikes especially on OSX.

Fixes #3333

<!-- start metadata -->

**Checklist**

Complete the checklist (and note appropriate exceptions) before a final
PR is raised.

- [ ] Changes are compatible[^1]
- [ ] Documentation[^2] completed
- [ ] Performance impact assessed and acceptable
- Tests added and passing[^3]
    - [ ] Unit Tests
    - [ ] Integration Tests
    - [ ] Manual Tests

**Exceptions**

*Note any exceptions here*

**Notes**

[^1]. It may be appropriate to bring upcoming changes to the attention
of other (impacted) groups. Please endeavour to do this before seeking
PR approval. The mechanism for doing this will vary considerably, so use
your judgement as to how and when to do this.
[^2]. Configuration is an important part of many changes. Where
applicable please try to document configuration examples.
[^3]. Tick whichever testing boxes are applicable. If you are adding
Manual Tests:
- please document the manual testing (extensively) in the Exceptions.
- please raise a separate issue to automate the test and label it (or
ask for it to be labeled) as `manual test`

Co-authored-by: bryn <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants