GithubHelp home page GithubHelp logo

Comments (20)

mykolasmith avatar mykolasmith commented on July 21, 2024 28

You should try using an existing SQL connection pooling application. We previously had each of our microservices running a dedicated container for cloudsql-proxy. This resulted in a lot of extra overhead and extraneous connections to the database. We opted to instead run a single instance of cloudsql-proxy and pgbouncer (https://pgbouncer.github.io/), which proxied and pooled connections to cloudsql-proxy. The result is a robust connection pool with aggregated stats that essentially acts as a proxy to the proxy that all of our microservices can connect to. We are finding that this works very well. I would argue that it is not the job of this application (cloudsql-proxy) to handle connection pooling. It should simply act as an auth layer & proxy. If you need advanced features, stick an existing solution in front of this. </2cents>

from cloud-sql-proxy.

schmitch avatar schmitch commented on July 21, 2024 5

actually to bring this issue up again, currently the biggest problem when using pgbouncer is, is that cloud sql postgres actually does not allow to read pg_shadow from a privileged user (i.e postgres user is not a superuser). This makes it super hard to have pgbouncer setup without hardcoding passwords into config files.
currently that is the biggest problem when running pgbouncer, not cloud-sql-proxy per se.

from cloud-sql-proxy.

mykolasmith avatar mykolasmith commented on July 21, 2024 2

@stekole Kubernetes. The Deployment/Service (pgbouncer) has two containers, pgbouncer + cloudsql-proxy. By scaling up the replicas on the Deployment, we get additional pgbouncer instances that create one or more connections to the cloudsql-proxy sidecar. The connection limit for GKE is ~100 actives, so we decided to have 3 replicas of pgbouncer running, each with a 20 connection limit. This keeps our active connections pegged at 60 and handles throttling at the pgbouncer layer rather than overload our cluster.

from cloud-sql-proxy.

paulwalker avatar paulwalker commented on July 21, 2024 1
Now, not every environment/language/driver/framework supports connection
pooling so it could make sense to do pooling at the Proxy level in some
applications and scenarios

I'm simply pointing out a scenario, within the Google ecosystem, a language invented by Google, in a container orchestration framework created by Google, in a cloud hosting service by Google where connection pooling is not working.

Can you explain more about how this is not relevant?

from cloud-sql-proxy.

schmitch avatar schmitch commented on July 21, 2024 1

actually isn't there still a quota: https://cloud.google.com/sql/docs/quotas#fixed-limits ?

from cloud-sql-proxy.

axot avatar axot commented on July 21, 2024 1

I understand using pgbouncer could improve the connection efficiency for Postgre, is there any production ready proxy for MySQL?

from cloud-sql-proxy.

GrantSheehan avatar GrantSheehan commented on July 21, 2024 1

I understand using pgbouncer could improve the connection efficiency for Postgre, is there any production ready proxy for MySQL?

ProxySQL is pretty robust + battle-tested, might be worth checking out.

from cloud-sql-proxy.

Carrotman42 avatar Carrotman42 commented on July 21, 2024

from cloud-sql-proxy.

paulwalker avatar paulwalker commented on July 21, 2024

It seems at least using the built in connection pooling in GoLang's database/sql built-in package does not work properly in GCE/GKE. https://github.com/jinzhu/gorm/issues/246

from cloud-sql-proxy.

Carrotman42 avatar Carrotman42 commented on July 21, 2024

from cloud-sql-proxy.

Carrotman42 avatar Carrotman42 commented on July 21, 2024

Ah I see, I mistakenly thought your initial post was an example of a case where implementing this feature request would help solve that issue. From my read of that issue (specifically https://github.com/jinzhu/gorm/issues/246#issuecomment-59162133), the problems arise when you are hosting your own database on GCE (or AWS, according to the comment) rather than when using Cloud SQL and the Cloud SQL Proxy (which only works with Cloud SQL, rather than self-hosted GCE/AWS).

As far my own testing has shown (and our regular probing inside Google continues to show), connection pooling via database/sql + Cloud SQL Proxy (+ Cloud SQL) works just fine. I'd be happy to investigate any issues you can find related to that combination of technology in another issue since I don't expect that to be broken. This issue is specifically about implementing connection pooling inside the Cloud SQL Proxy to alleviate any lack of connection pooling support in other client database drivers and libraries.

from cloud-sql-proxy.

paulwalker avatar paulwalker commented on July 21, 2024

@mykolasmith Thanks for the tip! May I ask, do you have any golang clients that are using cloudsql-proxy natively?

from cloud-sql-proxy.

badoet avatar badoet commented on July 21, 2024

hi @Carrotman42 i wrote that comments quite some time ago.
just to clarify, i was connecting to the Cloud SQL not setting it up in our own instance.
i cant quite remember the details of the application setup at the time and why i derive to that conclusion, but i think there were many other possible cause to this. e.g. at that time i was also developing locally (in Singapore) and Cloud SQL was in US.
and also it was quite some time ago, so im not sure if the problem still exists

from cloud-sql-proxy.

tsloughter avatar tsloughter commented on July 21, 2024

@mykolasmith curious, since I'm looking to switch to this setup now, do you use the cloudsql-proxy simply as a sidecar to the pgbouncer container in a single pod?

from cloud-sql-proxy.

stekole avatar stekole commented on July 21, 2024

@mykolasmith - how do you scale that pgbouncer/cloudsql-proxy container/box?

from cloud-sql-proxy.

unquietwiki avatar unquietwiki commented on July 21, 2024

Hey @mykolasmith , you might want to look into pgpool-II; testing that out now with gcp + read-replicas.

from cloud-sql-proxy.

nicknovitski avatar nicknovitski commented on July 21, 2024

The max_connections flag is now available (in beta) for Cloud SQL PostgresQL, and can be set up to 262143. That may be enough for a lot of people.

from cloud-sql-proxy.

enocom avatar enocom commented on July 21, 2024

We're not planning on implementing this feature. Others like pgbouncer or HAProxy will do this much better than the proxy ever would. Alternatively, application-level connection pooling is also a good option.

from cloud-sql-proxy.

d3vesh-bo avatar d3vesh-bo commented on July 21, 2024

We're not planning on implementing this feature. Others like pgbouncer or HAProxy will do this much better than the proxy ever would. Alternatively, application-level connection pooling is also a good option.

As mentioned by @schmitch Cloud SQL does not allow to read pg_shadow. So how can one integrate PgBouncer with Cloud SQL to authenticate database user using auth_user and auth_query.

I would appreciate your help guys!

from cloud-sql-proxy.

enocom avatar enocom commented on July 21, 2024

This issue has gotten a little unfocused. @d3vesh-bo if you're asking about best practices with pgbouncer, would you mind opening a "Question" issue with a descriptive title so we can discuss it there?

from cloud-sql-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.