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

Fixing #779 by settings http protocol and allowing to set keep alive … #780

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CHANGELOG
6.0.0a2 (unreleased)
--------------------

- Adapt to HTTP1.1 protocol on uvicorn by default
[bloodbare]
- PatchField: added operation "multi"
[masipcat]
- @duplicate: added option to reset acl
Expand Down
2 changes: 2 additions & 0 deletions guillotina/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,7 @@
"search_parser": "default",
"object_reader": "guillotina.db.reader.reader",
"thread_pool_workers": 32,
"keep_alive": 5,
Copy link
Member

Choose a reason for hiding this comment

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

5 is very low and I'm not sure it'll actually help the situation if this is the same problem that I've seen.

fwiw, nginx defaults to 75sec keep alive I believe.

Copy link
Member Author

Choose a reason for hiding this comment

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

default keep alive timeout at uvicorn is 5 (https://github.com/encode/uvicorn/blob/master/uvicorn/config.py#L134)

"http_protocol": "h11"
Copy link
Member

Choose a reason for hiding this comment

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

it's a shame we end up with h11 here

Copy link
Member Author

Choose a reason for hiding this comment

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

Its temporal until encode/uvicorn#344 is fixed

}
default_settings = copy.deepcopy(app_settings)
13 changes: 11 additions & 2 deletions guillotina/commands/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@ def get_parser(self):
)
parser.add_argument("--port", help="Override port to run this server on", default=None, type=int)
parser.add_argument("--host", help="Override host to run this server on", default=None)

parser.add_argument("--http_protocol", help="HTTP protocol auto/h11/httptools on uvicorn", default=None)
parser.add_argument("--http_keep_alive", help="HTTP keep alive timeout", default=None, type=int)

parser.add_argument("--asgi-server", default="uvicorn", type=str)
return parser

def run(self, arguments, settings, app):
port = arguments.port or settings.get("address", settings.get("port"))
host = arguments.host or settings.get("host", "0.0.0.0")

http_protocol = arguments.http_protocol or settings.get("http_protocol")
http_keep_alive = arguments.http_keep_alive or settings.get("keep_alive")

if arguments.asgi_server == "uvicorn":
import uvicorn # type: ignore

config = uvicorn.Config(app, host=host, port=port, reload=arguments.reload, access_log=False)
config = uvicorn.Config(
app, http=http_protocol, timeout_keep_alive=int(http_keep_alive),
host=host, port=port,
reload=arguments.reload, access_log=False)
server = uvicorn.Server(config)
self.loop.run_until_complete(server.serve())

# uvicorn.run(app, host=host, port=port, reload=arguments.reload, access_log=False, loop=self.loop)
elif arguments.asgi_server == "hypercorn":
import asyncio

Expand Down