Embed Server Performance Considerations #603
-
Thank you for this project, @gi0baro. I'm new to Granian and interested in trying it out. I currently have an existing project that is served via Uvicorn programmatically. To keep changes minimal, I've simply swapped Uvicorn with Embed Granian Server (minimal example for brevity).import asyncio
from granian.constants import Interfaces
from granian.server.embed import Server
from src.app import get_app
from src.settings import get_settings
async def run_server() -> None:
app = get_app()
settings = get_settings()
server = Server(
target=app,
port=settings.port,
address=settings.host,
interface=Interfaces.ASGI,
log_access=True,
)
await server.serve()
if __name__ == "__main__":
asyncio.run(run_server()) I wanted to ask if there are any other disadvantages to using Granian this way besides the ones you listed here in #35 I'm fine with the 1-worker limitation, since I'm already running it in a Docker container. The other two (existing & running event loop requiring and no support for reloading) are not an issue for me either. I did notice that it takes about 10 seconds to shut down the server (initiated by |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
First things first: the embedded server is still marked as experimental. So, while 10s still seems odd, it might be because the shutdown process is not at its best in the embedded server. More importantly: the embedded server is not designed for that. The idea behind the embedded server is.. well to be embedded. In projects that require more fine-grained control on the bootstrap and teardown phases. Or in general regarding processes management. In short: is designed for pojects like gradio, where they need to also manage a bunch of other stuff within the same process in addition to APIs serving. So, given your specific use case, I strongly advise you to just switch to CLI – even if performance-wise should be the same. Isn't |
Beta Was this translation helpful? Give feedback.
First things first: the embedded server is still marked as experimental. So, while 10s still seems odd, it might be because the shutdown process is not at its best in the embedded server.
More importantly: the embedded server is not designed for that. The idea behind the embedded server is.. well to be embedded. In projects that require more fine-grained control on the bootstrap and teardown phases. Or in general regarding processes management. In short: is designed for pojects like gradio, where they need to also manage a bunch of other stuff within the same process in addition to APIs serving.
So, given your specific use case, I strongly advise you to just switch to CLI – even if perfor…