Size of schema drastically spikes memory (RAM) usage
See original GitHub issueBug description
We are seeing high memory usage in our servers and I was able to track it down to including Prisma. Here are the stats:
Bare Nest server: 37.6MB Bare Nest server with simple Schema: 48.7MB Bare Nest server with our production PostgreSQL schema: 307.2MB
Production Schema Stats:
114 Models 32 enums
The memory spike seems to come from the size of our schema. Is this expected? a 250MB spike for running a production sized schema (non-trivial) seems massive.
How to reproduce
Unfortunately I cannot share our production schema (for obvious reasons) ~but this should be reproducible by generating a prisma client for a large schema and including it in a Nest (or express) server.~
A plain Nest app can get generated with npx create-nx-workspace --preset nest
and then just following the prisma setup instructions.
~Will gladly provide any additional information to help track it down, or if there is an open source “large” schema anyone knows of I can try and make a repro~
Reproduction:
This doesn’t provide the exact same memory spike as the schema is smaller than ours ~35 models not 114 but it does demonstrate the issue of climbing memory based on schema size:
Repo: https://github.com/yharaskrik/plain-nest-prisma-mem-spike-demo
Steps:
yarn install
yarn prisma generate
yarn nx build
node dist/apps/api/main.js
Startup was about 115MB for me and idle is about 80MB
Without Prisma at all startup is about 35MB and idle is 24MB.
Expected behavior
Memory increases but not at such a drastic rate.
Prisma information
// cannot share our production schema, should be reproducible with any large schema, we have 114 models
Pretty standard PrismaClient implementation for Nest
@Injectable()
export abstract class BaseCorePrismaService<T extends Prisma.PrismaClientOptions = Prisma.PrismaClientOptions>
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
protected constructor(
protected readonly config: BaseCorePrismaConfig,
protected readonly optionsArg?: Prisma.Subset<T, Prisma.PrismaClientOptions>
) {
super(optionsArg);
}
async onModuleInit(): Promise<void> {
await this.$connect();
}
async onModuleDestroy(): Promise<void> {
await this.$disconnect();
}
async enableShutdownHooks(app: INestApplication): Promise<void> {
this.$on('beforeExit', async () => {
await app.close();
});
}
}
Environment & setup
- OS: Apple M1 Max, 32GB of RAM, Ventura 13.0 (We also see high mem on our deployed alpine linux docker containers)
- Database: Postgres
- Node.js version: 14.20.2
Prisma Version
3.15.2
Issue Analytics
- State:
- Created 10 months ago
- Reactions:4
- Comments:10 (1 by maintainers)
Top GitHub Comments
@jkomyno heres the results from prisma 4.6.0 and node 18
Seems like there is something weird going on. (the 114 model schema is in our repo where as the others are in the repro repo, ill try and use our schema over in the other repo to keep it more consistent)
Ok so we recently upgrades to Prisma 4.7.1 (latest as of this writing).
103MB startup 88MB idle
This is using a fresh Nest server with nothing else in it.