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

Connection Pooling/Management #35

Open
alexbatis opened this issue Jun 21, 2023 · 1 comment
Open

Connection Pooling/Management #35

alexbatis opened this issue Jun 21, 2023 · 1 comment

Comments

@alexbatis
Copy link

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?

@zsnmwy
Copy link

zsnmwy commented Jun 24, 2023

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.

typeDefs: makeTypeDefs(dmmf),
resolvers: makeResolver(dmmf, db),

Example:

image

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.

image

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.

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