Comments (20)
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.
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.
@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.
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.
actually isn't there still a quota: https://cloud.google.com/sql/docs/quotas#fixed-limits ?
from cloud-sql-proxy.
I understand using pgbouncer could improve the connection efficiency for Postgre, is there any production ready proxy for MySQL?
from cloud-sql-proxy.
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.
from cloud-sql-proxy.
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.
from cloud-sql-proxy.
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.
@mykolasmith Thanks for the tip! May I ask, do you have any golang clients that are using cloudsql-proxy natively?
from cloud-sql-proxy.
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.
@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.
@mykolasmith - how do you scale that pgbouncer/cloudsql-proxy container/box?
from cloud-sql-proxy.
Hey @mykolasmith , you might want to look into pgpool-II; testing that out now with gcp + read-replicas.
- https://dba.stackexchange.com/questions/58590/pgpool-replication-not-allowing-md5-authentication
- http://www.pgpool.net/docs/pgpool-II-3.7.1/en/html/runtime-config-load-balancing.html
from cloud-sql-proxy.
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.
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.
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.
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)
- Automate README version bumps HOT 1
- Replace zap with log/slog
- Credentials can't be read because of ownership issue HOT 8
- v2/tests: TestPostgresAuthentication failed HOT 2
- security: cloudsql-docker/gce-proxy:alpine is vulnerable to CVE-2023-5363 HOT 4
- Update renovate to use renovate.json5
- v2/tests: TestMySQLAuthentication failed HOT 3
- Update storage bucket link in proxy help message HOT 1
- Version 2.10.0 binaries are all ELF 64-bit LSB executable, x86-64 HOT 3
- No Such Host HOT 2
- How to use the cloud-sql-auth proxy with Private Service Connect from developer machines HOT 13
- v2/internal/proxy: TestClientInitialization failed HOT 2
- v2/tests: TestPostgresIAMDBAuthn failed HOT 1
- Do not require strict order in env variables for connections HOT 2
- Add support for a lazy refresh
- pgbouncer + proxy with transaction pooling is slow HOT 23
- Is there any way to connect to MS SQL using domain credentials? HOT 7
- v2/tests: TestSQLServerAuthentication failed HOT 4
- Telemetry doesn't work with non-ADC
- v2/internal/proxy: TestCheckConnections failed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloud-sql-proxy.