Tauhoo
Tauhoo
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
In the end, it's not problem with Pisma. It's problem with our PM2 config. We set instances to "max" which is too much. I reduced the instances number and it works now. Thank you for support. @Nurul (Prisma)
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
But, on local, it has value after being set.
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
I tried changing the code and add more log.
import { PrismaClient } from "@prisma/client";
import { countPismaInitiation, updatePrismaMetrics } from "./monitor/database";
import { getLogger } from "./api/logging";

declare global {
var prismaGlobal: PrismaClient | undefined;
}

const logger = getLogger("Prisma");

const prismaClientSingleton = () => {
logger.info(
"Getting Prisma Client typeof prismaGlobal: " + typeof global.prismaGlobal,
);

if (global.prismaGlobal !== undefined) return global.prismaGlobal;
logger.info("Creating Prisma Client");
const prisma = new PrismaClient();
countPismaInitiation();
setInterval(async () => {
updatePrismaMetrics(prisma);
}, 10000);

global.prismaGlobal = prisma;
return prisma;
};

export const db = prismaClientSingleton();
import { PrismaClient } from "@prisma/client";
import { countPismaInitiation, updatePrismaMetrics } from "./monitor/database";
import { getLogger } from "./api/logging";

declare global {
var prismaGlobal: PrismaClient | undefined;
}

const logger = getLogger("Prisma");

const prismaClientSingleton = () => {
logger.info(
"Getting Prisma Client typeof prismaGlobal: " + typeof global.prismaGlobal,
);

if (global.prismaGlobal !== undefined) return global.prismaGlobal;
logger.info("Creating Prisma Client");
const prisma = new PrismaClient();
countPismaInitiation();
setInterval(async () => {
updatePrismaMetrics(prisma);
}, 10000);

global.prismaGlobal = prisma;
return prisma;
};

export const db = prismaClientSingleton();
global.prismaGlobal still always be undefined on prod.
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
prismaClientSingleton is called multiple times and globalThis.prismaGlobal always be undefined on prod.
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
No description
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
@Nurul (Prisma) Thank you very much. I will try adding counter in the prismaClientSingleton function to make sure that the code didn't run more than one time too then.
17 replies
PPrisma
Created by Hinky on 6/11/2024 in #help-and-questions
too many db connections on Prisma Accelerate
Do your connections go over the limit? I'm facing a similar issue. I don't know if they are related. https://discord.com/channels/937751382725886062/1269957438497493042
16 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
I only have a server container connect to the database.
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
No description
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
I also checked each activity one by one to see if idle activities really have the sql statements from server too.
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
No description
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
No description
17 replies
PPrisma
Created by Tauhoo on 8/5/2024 in #help-and-questions
Connections are over connection limit
Here is how I send data to Statsd
export async function updatePrismaMetrics(prisma: PrismaClient) {
if (client === null) return;
const metrics = await prisma.$metrics.json();
for (const { key, value } of metrics.counters) {
client.gauge(`prisma_${host.replaceAll("_", ".")}_${key}`, value);
}
for (const { key, value } of metrics.gauges) {
client.gauge(`prisma_${host.replaceAll("_", ".")}_${key}`, value);
}
}
export async function updatePrismaMetrics(prisma: PrismaClient) {
if (client === null) return;
const metrics = await prisma.$metrics.json();
for (const { key, value } of metrics.counters) {
client.gauge(`prisma_${host.replaceAll("_", ".")}_${key}`, value);
}
for (const { key, value } of metrics.gauges) {
client.gauge(`prisma_${host.replaceAll("_", ".")}_${key}`, value);
}
}
I use node-statsd to send data
17 replies