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

Use a read-only cache adapter for downloading files to workaround mem… #7

Merged
merged 1 commit into from
Dec 1, 2022

Conversation

airportyh
Copy link

@airportyh airportyh commented Nov 30, 2022

… usage issue

Why?

We have experienced and seen reports of poetry/pip running out of memory when installing certain large pypi packages:

  1. https://ask.replit.com/t/replit-does-not-allocate-enough-resources-when-installing-python-packages/2494
  2. https://replit.slack.com/archives/C03KS2B221W/p1669004177362729

We linked this to a known issue in pip: pypa#2984 and verified that disabling the cache mechanism solves the issue (at least for the large packages we tested).

What Changed?

Created a read-only version of src/pip/_vendor/cachecontrol/adapter.py in src/pip/_internal/network/ro_cache_adapter.py and replaced the original. This adapter disable the write-to-cache behavior when downloading a file, but it still reads from the cache when matching requests are found in the cache directory ~/.cache/pip/http.

How to test

  1. Create a python repl
  2. pip install nvidia_cublas_cu11 and see the install succeed
  3. pip install pyyaml and see that the download used the cached version

@airportyh airportyh added the boop label Nov 30, 2022
@masad-frost masad-frost requested review from ryantm, a team and masad-frost and removed request for a team November 30, 2022 23:10
cached_response = None
if cached_response:
return self.build_response(request, cached_response, from_cache=True)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove the lines

            # check for etags and add headers if appropriate
            request.headers.update(self.controller.conditional_headers(request))

on purpose here?

Copy link

@ryantm ryantm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this in a repl and worked.

@replbot replbot removed the boop label Dec 1, 2022
@airportyh airportyh merged commit aaef0bd into main Dec 1, 2022
@airportyh airportyh deleted the th-ro-download-cache branch December 1, 2022 20:51
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 this pull request may close these issues.

3 participants