-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: otaproxy: implement resource limit for requests handling and cache r/w, refactor cache_streaming with r/w thread pools #575
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
base: main
Are you sure you want to change the base?
Changes from 11 commits
ed921b1
cbc01bb
3bef7f4
98589b1
98a4e73
d7fbd8c
8ece84f
2575ee4
405296f
98c939d
03807ba
a662b1f
316475c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,11 @@ def run_otaproxy( | |
enable_https: bool, | ||
external_cache_mnt_point: str | None = None, | ||
): | ||
import asyncio | ||
|
||
import anyio | ||
import uvicorn | ||
import uvloop | ||
|
||
from . import App, OTACache | ||
|
||
|
@@ -70,4 +73,10 @@ def run_otaproxy( | |
http="h11", | ||
) | ||
_server = uvicorn.Server(_config) | ||
anyio.run(_server.serve, backend="asyncio", backend_options={"use_uvloop": True}) | ||
|
||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | ||
anyio.run( | ||
_server.serve, | ||
backend="asyncio", | ||
backend_options={"loop_factory": uvloop.new_event_loop}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The anyio recommended way to setup uvloop. |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
from . import run_otaproxy | ||
from .config import config as cfg | ||
|
||
logger = logging.getLogger(__name__) | ||
logger = logging.getLogger("ota_proxy") | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
|
@@ -74,6 +74,9 @@ | |
) | ||
args = parser.parse_args() | ||
|
||
# suppress logging from third-party deps | ||
logging.basicConfig(level=logging.CRITICAL) | ||
logger.setLevel(logging.INFO) | ||
Comment on lines
+77
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For standalone starting otaproxy, configure logging. Note that here we filter out third-party deps' logging, and set the |
||
logger.info(f"launch ota_proxy at {args.host}:{args.port}") | ||
run_otaproxy( | ||
host=args.host, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup and refactor of cache header parsing/exporting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, ORM will apply a custom row_factory to try to convert the raw result into cache db entry, but here we do
SELECT count(*)
here, the result is not an entry of db.Although the custom row_factory will detect whether the raw result if actually an entry or not, if not, return the result as it, but it is better to use
sqlite3.Row
as row_factory if we know we are not selecting db entry in the first place.