-
Notifications
You must be signed in to change notification settings - Fork 65
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
Switch mongodb databases with sharedb #56
Comments
@kapeskittu I am facing the same issue, is there any resolution? |
The ShareDB server doesn't directly support reading/writing to different databases, depending on information in the client messages. I think you could indirectly achieve that by instantiating one ShareDB A quick illustration based off the Counter example: const backendMap = new Map();
for (const mongoConfig of mongoConfigs) {
const db = new ShareDBMongo(mongoConfig.url);
const backend = new ShareDB({db});
backendMap.set(mongoConfig.countryCode, backend);
}
// Register WebSocket connection with appropriate Share Backend for the country
wss.on('connection', function(ws, req) {
var stream = new WebSocketJSONStream(ws);
const countryCode = getUserCountryCode(req.getHeader('Cookie')); // However you determine country
const backend = backendMap.get(countryCode);
if (backend) {
backend.listen(stream);
} else {
// error handling
}
}); |
Hi Kanwar,
I was able to imagine such a situation with less minimal code changes using
mongos and shard keys of mongodb cluster environment:
https://docs.mongodb.com/manual/core/sharded-cluster-query-router/
If it is multitenant application you can introduce country or region of
database as shard key for every collection and implement mongos.
Other than multiple sharedb instance is another solution as discussed by
other user in the forum. Where you will have a gateway app which will route
to specific instance of sharedb application based user login and which
region he belongs to.
Let me know, if you need any other details.
Thanks,
Krishna Prasad Kattula.
…On Wed, Apr 3, 2019, 6:16 PM Kanwarjeet singh ***@***.***> wrote:
@kapeskittu <https://github.com/kapeskittu> I am facing the same issue,
is there any resolution?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADXPJpJY5VVdR4e33K0N_vc9bbPGnmz7ks5vdKKbgaJpZM4TuhQO>
.
|
@ericyhwang isn't shareDb providing multiple DB support?
While creating racer backend connections? |
Closing due to inactivity. |
Hello. (Sorry for resurrecting an old issue.) a) If we use url for db parameter, sharedb creates new client for each database. That will be a performance penalty. For that reason you suggest to use case b) When we implement according to b) case, for 1000 databases, there will be over 5000 connections that is causing mondodb server to be killed. ** c) If sharedb were using our db instance (instead of creating the Db instance from our given client), it would be possible to use the same connection pool for entire application. Does my suggestion sound nice? Mongodb documents about connection pooling: "To reduce the number of connection pools created by your application, we recommend calling MongoClient.connect once and reusing the database variable returned by the callback:" |
@ihsanciftci my first question is why are you running and connecting to 1000 databases? That sounds like a lot. My second question is if you need to have that many databases, is connecting to them from a single server a sensible and scalable approach? This sounds like you may need to run more backends? To your question, providing a DB instance might work, but would have at least these issues:
At any rate, if this is an issue you want to persue, you're better off opening a new issue please. |
Thanks for your reply. @alecgibson
I'm creating 4000 sharedb instances at a rate of 20 instances/seconds, in that case mongodb creates 150 connections.
I think mongodb and sharedb can handle over ten thousand databases. I think it depends on websocket performance.
Yes. For example if my one backend handles 10 thousands sharedb instances. 10 server scales to 100 000 sharedb instances. One MongoDB connection pool can work across multiple databases over a mongodb server. I think this is a modern connection pool. I think ShareDB missed that part of connection reusing. This will enable using Sharedb in SaaS.
I did not try the query polling. |
How can i switch between multiple mongodbs using sharedb?
We are trying to implement a multi tenant application where transactions should be performed only to the database of country from where user belongs to. We maintaing one database for one country on same mongo server. How does this work with sharedb?
The text was updated successfully, but these errors were encountered: