Connection Pooling/Management
alexbatis opened this issue · comments
Does this library provide external connection polling/management functionality?
On prisma: [https://www.prisma.io/docs/data-platform/data-proxy#connection-pooling-and-connection-management](data proxy docs):
Data Proxy provides connection pooling so that your application can reuse active connections and never exhaust the maximum number of connections that your database allows.
Connection pooling with the Data Proxy utilizes orchestrated Prisma query engine technology to open, maintain, and close connection pools. It helps applications load-balance and scale database requests based on demand.
A Data Proxy connection pool maintains active database connections and ensures that an application reuses them when new requests come in.
After a quick look through the code, I don't see anything explicit about connection pooling/management, but perhaps this is handled under the hood?
If I self-host this prisma data proxy, will I have to use it in conjunction with https://www.prisma.io/docs/guides/performance-and-optimization/connection-management/configure-pg-bouncer as an external connection pooler?
Request Flow
Prisma Edge DB Request -> Express -> ApolloServer - Reslover -> PrismaClient -> DB
The prisma-data-proxy-alt
transforms the Prisma schema to ApolloTypes and Apollo Resover.
prisma-data-proxy-alt/src/helpers/makeServerConfig.ts
Lines 12 to 13 in 0444bd9
Example:
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import gql from 'graphql-tag';
const typeDefs = gql` // types base on Prisma Schema
type Query {
me: User
}
type User {
id: ID!
username: String
}
`;
const resolvers = {
Query: {
me() {
return { id: '1', username: '@ava' }; // Use Prisam Client to query db
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
// Note the top-level await!
const { url } = await startStandaloneServer(server);
console.log(`🚀 Server ready at ${url}`);
About Connection Pool
https://www.prisma.io/docs/data-platform/data-proxy#reduced-bundle-size
By default, Prisma Client bundles the query engine that includes the connection logic for all databases that Prisma supports.
Performance
I think the Prisma Metric, Prisma OpenTelemetry Tracing, Apollo OpenTelemetry, should be enable by default.
We can use Crane and metrics to control the data-proxy instance on k8s.