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

Multi-tenancy connection management #83

Closed
vanobig opened this issue Jan 9, 2018 · 4 comments
Closed

Multi-tenancy connection management #83

vanobig opened this issue Jan 9, 2018 · 4 comments

Comments

@vanobig
Copy link

vanobig commented Jan 9, 2018

Hey guys, do you have any recommendations on how to approach this task?
I need to manage a pool of connections in a multi-tenancy environment, means I have multiple DBs to talk to. Since I cannot afford creating a new Db connection upon each request, I have to create a pool of connections.

The way how DB connection is meant to be created is to:

  1. conn, err := graphHTTP.NewConnection(...)
  2. c, err := graphDriver.NewClient(...)
  3. db, err := p.cl.Database(...)

Implementation of the #3 uses a copy of the conn from #1. What it means to me is that even if I maintain my own pool of the db objects, every single one will hold a copy of the identical connections (in fact it's a connection pool). Since Database constructor is defined as private (newDatabase), even if I want to write my own implementation of #3 (with a pointer to the conn), I cannot bypass it.

Any suggestion on how to address the issue?

@ewoutp
Copy link
Contributor

ewoutp commented Jan 9, 2018

Hi, note that the Connection you pass in is an interface, not an object.
Now it is safe to use that single Connection many times, since internally is used a standard http.Transport (from the go library) that already does connection pooling for you.

Does this answer your question?

@vanobig
Copy link
Author

vanobig commented Jan 9, 2018

I'm sorry but I still don't get it.
Connection is a property of the Client, right? And it's of Connection and not *Connection.
If I make this call 5 times
db, err := c.Database(context.Background(), databaseName) every instance of db will have its own copy of the Connection. Am I missing anything?

@ewoutp
Copy link
Contributor

ewoutp commented Jan 9, 2018

Connection is an interface. It is implemented by something like *httpConnection

@vanobig
Copy link
Author

vanobig commented Jan 9, 2018

I guess I've learned something new about interfaces today @ewoutp.
Thank you for explaining that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants