Hi there, I am testing creating a hundred thousand...
# orm-help
r
Hi there, I am testing creating a hundred thousand records using createMany, checking on the memory usage, my container uses a lot of memory for this. It took more than 1GB RAM for this operation. Is this normal ? I have to batch the creation to prevent out of memory. I am using prisma 3.15.1 I am using nested createMany
Copy code
prisma.user.create({ data, Post: { createMany: {data: postData}});
1
l
I assume this is some kind of seeding operation? Or are you just benchmarking what the container can do at scale? Cause I would hope that no single instance creates a hundred thousand records on a regular basis 😬 If it's for seeding then maybe check our the seed.ts documentation as I feel like it's more optimised for something like this?
r
It is not for seeding, but basically a bulk process. I can move it as a background process only my concern is if it really consume a lot of memory, I will need to chunk the creation or increase the instance memory.
Just curious why it is consuming memory, is it because the engine storing the returned data ? but 100k record shouldn't take like 1GB+ right ?
l
You can log out all the SQL queries in dev. Might be a way to see how much of the data is being combined into single queries 🤷‍♂️
👍 1
n
It might be helpful for you to enable tracing to get a detailed log of the activity that Prisma Client carries out, at an operation level, including the time taken to execute each query. It helps you analyse your application’s performance and identify bottlenecks. Please note that tracing is a preview feature and available from prisma version
4.2.0
r
yeah just saw the tracing we might upgrade to that later. Time is not much an issue. I guess more to memory usage as we have prisma running in serverless environment where the memory have no discount on over usage if prisma reaching the max memory even as background job it will always fail. For now I am tweaking the code to do batching in application level with drawback of slow* + managing transaction, I was thinking that this would be handled by the engine under the hood, it will be nice though.