-
Notifications
You must be signed in to change notification settings - Fork 73
Query structure, session pinning #1980
Comments
Automatically generated comment to notify maintainers |
I think I've tracked down the most likely candidate...prepared statements. Does Graphback use prepared statements? Is there any way to turn them off if so? |
Digging into my logs more I get to the following message:
|
Seems this is going to be a problem with |
We do not use prepared statements. Executed queries are very vanilla (anything that knex would do), however I believe that problem is related to your app configuration and unrelated to how we do queries. I do think that if you use serverless and proxy, knex needs to be properly configured to not create connection pool (the part inside your app that setup knex database, similar to our templates). Pinning cannot be avoided anyway in some situations but if you have an external pool source we need to configure knex to initiate a connection every time it makes request. I would also see this as possible problem with the slowness of lambda as creating connection pool slows them. To confirm my thesis I have configured proxy on AWS and used pooling: How this causing issuesIf I setup knex to have pool of 50 connections it takes the entire proxy connection pool on each lamba startup. This is not only going to take lots of time for the startup but also going to block any other functions from accessing the pool. I do see connections being released after lambda is finished but with some delay etc. What our team can get from thisSetting up graphback as a serverless function took me quite some time (without even touching subscription support) so it will be cool if we build some community template that graphback can use. |
@lastmjs let me know if that helps you. As team we are devoted to your success with graphback. It was really nice to play with AWS capabilities - I never used lambdas and proxy before. |
Thanks for getting back to me, you guys still rock! So, as for your suggestion here:
How would I do this? I already have knex configured to have a min pool of 0 and max pool of 1. I'm not sure this is the issue, though I would like to try your suggestion. From what I understand, knex makes a prepared statement every time. So all graphback queries are prepared statements. I found that out here: knex/knex#3636 (comment) From all of my research, it seems that prepared statements are not supported in postgres proxies that do transaction pooling. This is true for AWS RDS and for pgBouncer. I've linked to the AWS documentation that says this above, and here is what pgBouncer has to say about it: https://www.pgbouncer.org/faq.html#how-to-use-prepared-statements-with-transaction-pooling So really it seems to be the prepared statements. Not supported by transaction pooling proxies. Knex does prepared statements for everything, and there is no way to turn them off. I've collected my research on the matter here on the One avenue that I have not gone down yet is attempting to use the libpq native bindings in More about the native libpq possible solution: |
It is still maintaining connection especially that AWS lambdas. There is sample app (broken) that knex maintainer explains how to fix. |
Alternatively, it will be better to create fastify middleware to disconnect database (that will be quick and easy) if pooling tricks do not work - I see they do. |
I've been doing quite bit of testing in my staging and production environments. I assume the fix you mentioned from knex/knex#3464 has to do with letting the connection pool die. I fiddled with the Have you had success with the pooling tricks you're mentioning? |
I moved out and no longer have access to the env. Using Aurora seems like the best choice in terms of efficiency and cost. Let us know how this works. |
I will let you know. I'm looking into optimizing my queries with indexes, VACUUM and ANALYZE. That doesn't seem to be having any affect. It looks like scaling the database with read replicas or going with Aurora Serverless might be the next options. I'll keep you updated. |
After all of my testing, the best path forward seems to be Aurora Serverless with the Data API. The Data API claims to abstract away connection handling. I'll be extensively testing it in my staging environment. If it looks promising, I'll most likely be moving forward with it. The problem now is how to hook up Graphback to use the Data API. It is an HTTP API that accepts SQL queries directly. I believe I would need to somehow intercept the SQL queries from knex or node-postgres to get this to work. Unfortunately, that path does not look very promising. I would love to know if you know of a way that this can be done. Unfortunately, this might be the end of the road for me and Graphback on the project I've been using it on. I love Graphback, but we need more stability and conservatism moving forward. Graphback not being easily compatible with the Data API seems to be the nail in the coffin. We have to have direct control over our SQL queries. I appreciate all of the help, and again if there is any simple way to allow Graphback to use the Data API, I would love to know soon. |
Hey, I'm attempting to deploy Graphback into a serverless environment (AWS Lambda) that uses AWS RDS Proxy to manage connections to the database. The proxy is supposed to multiplex connections, but it seems there is not multiplexing occuring whatsoever. This is leading to extremely bad performance.
I'm just wondering if there is anything in the PostgreSQL queries being created by Graphback that might cause session pinning in AWS RDS Proxy.
From the AWS docs linked to below:
Does Graphback set any kind of state information needed across requests? I can't believe how poorly my proxy is performing, and I hope to have a little insight if anyone here knows. Thank you!
More information on pinning: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html#rds-proxy-pinning
The text was updated successfully, but these errors were encountered: