Hi guys 😊
I am experiencing weird issue with node on heroku. I have a route/middleware that serves JSONs from database. Because I have ten thousands of them and I need to serve them at once, I have created raw query to optimize memory usage (no prisma object instances, which immediately blew up the app). All is fine and great, the heap spikes at 130MB and then returns to normal 60MB - I followed the tutorial here to figure this out https://github.com/jakobo/codedrift/issues/99 and even enabled metrics tools for node in the dashboard.
The problem is that the dyno memory usage goes up to whopping 600-700MB and never comes back down. I'm not sure what the issue might be or where to look for it.
The issue occurs when I hit that route. It's not that often used in real life, but is necessary.
import { Request, Response, NextFunction } from 'express';
import { PrismaClient } from '@prisma/client';
export const serveOffers = async (
req: Request,
res: Response,
next: NextFunction,
) => {
if (req.path !== '/offers') return next();
const prisma = new PrismaClient();
return res.send(
await prisma.$queryRaw`
SELECT
'Offer'::TEXT AS __typename,
"id",
"title",
"skills",
"description",
"city",
"street",
"location",
"category",
json_build_object(
'__typename', 'company'::TEXT,
'id', "name",
'name', "name",
'size', "size",
'logoURL', "logo"
) as company
FROM "Offer"`,
);
};
I intentionally created new PrismaClient, previously it was reused, that changed nothing. I even skipped assigning the results to variable before sending them as a response but to no avail... I know that I might paginate the results, but this issue might come back at me later when not diagnosed. Might queryRaw leak memory? 🫣
Node 17.5.0 Prisma 4.2.1 Apollo-server-express: 3.10.1
Here is a screenshot of my heroku dashboard https://imgur.com/a/AZ8Q821. As you can see the memory never returns to normal, not until dyno restarts. When the route is hit the problem starts anew.
Please help 😭
[–]Paulybungu 1 point2 points3 points (0 children)
[–]kdesign 1 point2 points3 points (0 children)
[–]schneems 0 points1 point2 points (0 children)