Druue / prisma-issue-minimal-reproducible-repo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minimal, Reproducible Example of High RSS Memory Usage Issue with Prisma

This repository contains a minimal, reproducible example demonstrating an issue with high RSS memory usage during queries involving PostgreSQL JSON columns when using Prisma ORM. The seeded data provided mimics real business data where the issue was encountered. In the application, records with large JSON columns are fetched, manipulated, and updated, causing significant RAM consumption under certain circumstances.

Issue Description

When executing specific queries, the application's RSS memory usage spikes, sometimes reaching up to 1GB. This behavior has been observed consistently and can be reproduced using the code provided in this repository.

To demonstrate that the issue is related to Prisma, we have benchmarked the same operations using the Kysely ORM framework. Additionally, a workaround was implemented where a text field was used instead of a JSON column. While this reduces the problem, it is not a perfect solution.

Reproducing the Issue

To reproduce the issue locally, follow these steps:

  1. Set up the environment using Docker Compose:
  docker-compose up -d
  1. Install dependencies:
  pnpm install
  1. Run Prisma migrations:
  pnpm run migrate
  1. Seed the database:
  pnpm run seed
  1. Build the project:
  pnpm run build
  1. Start the server with prisma:
  pnpm run run prisma

or with kysely

pnpm run run kysely

Now, you can access the application endpoints:

Analyzing Performance

Performance analysis can be conducted using Clinic.js, a performance profiling tool. Use the following npm scripts along with Clinic.js:

  • Prisma with JSON column: pnpm run analysis:prisma:json

  • Prisma without JSON column: pnpm run analysis:prisma:no-json

  • Kysely with JSON column: pnpm run analysis:kysely:json

  • Kysely without JSON column: npm run analysis:kysely:no-json

About


Languages

Language:TypeScript 67.3%Language:JavaScript 32.7%