fossasia / open-event-server

The Open Event Organizer Server to Manage Events https://test-api.eventyay.com
https://api.eventyay.com
GNU General Public License v3.0
2.97k stars 1.89k forks source link

Idea to modernize the technological stack #7321

Open hongquan opened 3 years ago

hongquan commented 3 years ago

The reason of ASGI is:

In addition, I propose that if we use WebSocket, just use plain WebSocket instead of SocketIO. SocketIO is WebSocket, adding a protocol layer which are private to SocketIO community. It brings no other benefit than just locking us up with NodeJS ecosystem. In other word, using SocketIO on backend will force client side to use SocketIO-supported libraries too. If we use plain WebSocket at backend, the clients just need to support general WebSocket, no SocketIO specific.

The ASGI idea is a very big change and I don't expect it to happen soon.

iamareebjamal commented 3 years ago

SocketIO isn't working and removed from the system since v2. We run on eventlet worker to make WSGI somewhat asynchronous. I'm afraid ASGI won't be possible in foreseeable future because everything from ORM to HTTP layer in the project is synchronous. Even if Django has support for ASGI views, they don't have support for ASGI ORM and I don't think they will without breaking changes. Having async ORM is unfortunately not a task which can be migrated bit by bit as a single async function needs all its callers to be async and thus the runtime/server to be async as well. And calling a sync function in async framework is blocking the entire event loop. So, it's all or none. So unless SQLAlchemy adds a middle ground of supporting both, which I don't think it will since its author had written against the case of async ORMs in general single threaded applications regarding performance, we won't have a means to move to an ASGI framework. Besides, the heavy lifting of the API is done by flask-json-restapi which is inherently tied to flask's sync API and there is no async alternative for that as well.

hongquan commented 3 years ago

I am aware of lacking async ORM, but the current stack of Flask + SQAlchemy is not better. At least in ASGI, we can convert non-ORM parts to true async, still better than current stack where every things are still synchronous.

Another things about SQLAlchemy: SQLAlchemy ORM is not async-ready, but SQLAlchemy Core is. Actually, SQLAlchemy Core is not related with "sync or async", because it is just "query builder", it doesn't involve any IO.

Benefit of Dynaconf (not just fanciness):

hongquan commented 3 years ago

Because we no longer use SocketIO, let's skip the ASGI idea.

ShreehariVaasishta commented 3 years ago
  • Will look into poetry if it is not as slow as pipenv and does not drastically increase docker build time
  • We already use .env locally and config.py with environment variables to load the config, so Dynaconf would just be a fancier option with more supported formats, but that doesn't matter in production because we configure it using environment variables. It'll just help in local development, but I think .env is enough for that. Another case for .env is that it is supported both via flask-dotenv and docker so there is a single source of truth for settings

SocketIO isn't working and removed from the system since v2. We run on eventlet worker to make WSGI somewhat asynchronous. I'm afraid ASGI won't be possible in foreseeable future because everything from ORM to HTTP layer in the project is synchronous. Even if Django has support for ASGI views, they don't have support for ASGI ORM and I don't think they will without breaking changes. Having async ORM is unfortunately not a task which can be migrated bit by bit as a single async function needs all its callers to be async and thus the runtime/server to be async as well. And calling a sync function in async framework is blocking the entire event loop. So, it's all or none. So unless SQLAlchemy adds a middle ground of supporting both, which I don't think it will since its author had written against the case of async ORMs in general single threaded applications regarding performance, we won't have a means to move to an ASGI framework. Besides, the heavy lifting of the API is done by flask-json-restapi which is inherently tied to flask's sync API and there is no async alternative for that as well.

FYI FastAPI can be used. It seems promising.

iamareebjamal commented 3 years ago

FYI FastAPI can be used. It seems promising.

No, it can't be. Read the comment again. It'll take us months to migrate. There is no compatibility between ORM or views in FastAPI. It'll literally be a rewrite, which we don't want to do. There are much more important things to handle than rewriting the entire server.

ShreehariVaasishta commented 3 years ago

FYI FastAPI can be used. It seems promising.

No, it can't be. Read the comment again. It'll take us months to migrate. There is no compatibility between ORM or views in FastAPI. It'll literally be a rewrite, which we don't want to do. There are much more important things to handle than rewriting the entire server.

Okay, got it.