-
Notifications
You must be signed in to change notification settings - Fork 81
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
Multi-tenant uwazi core #2393
Comments
Some resources regarding multi-tenancy in node apps:
|
Apparently this can also be solved via async hooks: https://nodejs.org/docs/latest-v10.x/api/async_hooks.html |
@txau, the solution with continuation-local-storage looks really nice, we should do a quick spike, should be "easy" to integrate into our app, maybe not (http://asim-malik.com/the-perils-of-node-continuation-local-storage/) with virtual hosts it looks like it does instantiate as many express apps as needed ? not so good for memory consumption ? not sure though did not read the async hooks but it is experimental apparently, maybe not yet. |
Regarding sockets. One approach is to separate the server operations that respond to user-requests and long-running async tasks. We could use a background worker for the async tasks like processing pdfs and semantic search. The server and worker would be decoupled, and a message queue would be put in place to handle communication between the two. Here's a simple workflow:
Which this approach, it will not matter whether the server that the user is connected to is the same one from which they made the request, because each server node will receive the notification and send to its clients. Here are some pros and cons that I can think of: Pros
Cons
In terms of implementation, the worker and the server could just be the same uwazi codebase, but with different entrypoints, e.g. Some popular message brokersRabbitMQ is a popular message broker that supports multiple messaging approaches like broadcasting, publish/subscribe, task queues that distribute incoming tasks across different workers, durable messages (e.g. messages stored on disk in case of crash), etc. Redis is an in-memory key-value database that's usually used for caching. It also supports messaging I believe. I've never deployed it though. But it's quite popular. If we're also considering using a shared in-memory storage for storing things like user sessions that could be shared across all nodes, it could be worth looking into. Kafka is also widely popular I think. But I've never used it and don't have much to say about it. I could read more about the topic to see what the current best practices are and important considerations I may not be aware of. |
I assume that the user account model will work like slack. That is, if one user has two accounts in two separate instances. Those two accounts are separate and isolated even if they have the same email address. Each instance is an isolated namespace. Which is different from services that have one namespace for users and the same user account can be "added" to different organizations/tenants (e.g. like GitHub). Is this assumption correct? |
@habbes that is correct. No centralization of user auth, its a per instance auth. |
This issue is now a priority for the team so that we can free up resources to improve performance and responsiveness for the Uwazi instances -- to address scalability. This is expected to take at least one month. |
To solve this problem i have tested AsyncLocalStorage (this feature is on node14, it is being backported to 12.17.0) on some routes in uwazi to check for the performance impact. This is an overview of how it looks on some of our most used endpoints: some key points on this:
|
Some things to keep in mind
|
Mongoose schema middleware hooks break async context, i had to reimplement updatelogs hook into the methods itself for this to work. this is a known issue that can be affecting other areas, more info here my approach is going to be as follows:
|
We are changing the implementation so that there is no special case with no tenant, single tenant instance its going to be a normal instance with one tenant, instead of multitenant flag to activate/deactivate, #2393 (comment) this means every process, tests, migrations, reindex etc should be run inside an async context and with the default tenant.
|
not true anymore, the current approach is:
|
|
@RafaPolit, when we have a multitenant/multiprocess architecture, what does "not responding or not working" mean ? i think if one is not working that will mean all instances are not working.
this kind of errors will work normally, the monitoring will depend on that and on how does it monitor ? is it expecting a 200 and that is it ? |
there will be 2 new flags, one is i think temporary:
System keys: this is completely removed this are the alternatives now:
the next list of "cron jobs" are only going to work with multitenant and multiprocess as false.
|
The idea of this issue is to discuss and track all the info regarding the idea of multiple Uwazi instances running in one node.
Issues detected so far:
this is not being addressed, migrations will work like they do now, env variables for the db index etc and script launch.
The text was updated successfully, but these errors were encountered: