-
Notifications
You must be signed in to change notification settings - Fork 27
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
long-term use of proxpi on a low-resource server #46
Comments
well... i cached some packages and rebooted my "field" NAS (with proxpi configured as a service). Before the reboot:
After reboot:
as a part of the experiment, I am going to run the script "pypi_warming_up.ps1" on my win10 PC which installs the "top 8000 most popular python packages", according to hugovk. pip is configured to query the NAS first, and in the case of 120sec timeout -- pypi repo. staying tuned! |
There are two caches:
The index cache has a TTL, which invalidates the cache on next access (ie download attempt from a client like pip). This has no memory bound, so for a sufficiently large TTL it can cause The files cache has a configurable max disk usage, and should use very little memory. It is also resilient to server restarts. If you need a persistent cache that survives server restarts, Footnotes
|
the alternatives don't work for me because they are performance-oriented, and i need data availability — performance doesn't really bother me. when there is no internet access, slow index searches are not the biggest problem. on the other hand, NAS resources consumption does bother me. please tell me, are there architectural obstacles in your application to saving the index on disk and loading it when needed? i want to know this before making changes to the code. |
I'm not sure. If you keep the API of I won't merge any PR that makes this change (unless you create a subclass of |
Good afternoon. In the server.py file you wrote:
However, this does not allow you to use the app in Windows. I rewrote this part like this:
So it works now in Windows as well, but I am not sure if this could cause any problems? |
I think a better solution is to return a different type (eg Diff (click to expand):diff --git a/src/proxpi/_cache.py b/src/proxpi/_cache.py
index 3e09f51..85049c5 100644
--- a/src/proxpi/_cache.py
+++ b/src/proxpi/_cache.py
@@ -7,6 +7,7 @@ import abc
import time
import shutil
import logging
+import pathlib
import tempfile
import warnings
import functools
@@ -719,13 +720,13 @@ class _FileCache:
return True # default to original URL (due to timeout or HTTP error)
return False
- def _get_cached(self, url: str) -> t.Union[str, None]:
+ def _get_cached(self, url: str) -> t.Union[pathlib.Path, None]:
"""Get file from cache."""
if url in self._files:
file = self._files[url]
assert isinstance(file, _CachedFile)
file.n_hits += 1
- return file.path
+ return pathlib.Path(file.path)
return None
def _start_downloading(self, url: str):
@@ -751,7 +752,7 @@ class _FileCache:
os.unlink(file.path)
existing_size -= file.size
- def get(self, url: str) -> str:
+ def get(self, url: str) -> t.Union[str, pathlib.Path]:
"""Get a file using or updating cache.
Args:
@@ -884,7 +885,7 @@ class Cache:
raise exc
return files
- def get_file(self, package_name: str, file_name: str) -> str:
+ def get_file(self, package_name: str, file_name: str) -> t.Union[str, pathlib.Path]:
"""Get a file.
Args:
diff --git a/src/proxpi/server.py b/src/proxpi/server.py
index 1124eca..69c754b 100644
--- a/src/proxpi/server.py
+++ b/src/proxpi/server.py
@@ -4,8 +4,8 @@ import os
import gzip
import zlib
import logging
+import pathlib
import typing as t
-import urllib.parse
import flask
import jinja2
@@ -203,8 +203,7 @@ def get_file(package_name: str, file_name: str):
except _cache.NotFound:
flask.abort(404)
raise
- scheme = urllib.parse.urlparse(path).scheme
- if scheme and scheme != "file":
+ if not isinstance(path, pathlib.Path):
return flask.redirect(path)
return flask.send_file(path, mimetype=_file_mime_type)
See #48 |
dear EpicWink, i am considering using your caching proxy
proxpi
on my field (semi-portable) NAS. the server is solely for my use, and it has a pretty weak CPU and 1.5GB of RAM.i wonder if your caching proxy is suitable for long-term cache storage in case of internet disruptions. for instance, if i set
PROXPI_INDEX_TTL=6570000
(several years) and accumulate cache over a few months (and after numerous power cycles), will the server operate normally? will i be able to use the cached files for up to a year?i would appreciate any information or recommendations you could provide.
best regards, ~le berouque
EDIT: added remarks about "semi-portable" and "power cycles"
The text was updated successfully, but these errors were encountered: