toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.52k stars 259 forks source link

High Memory usage while using RazorLight #458

Closed NagarajMasub closed 2 years ago

NagarajMasub commented 3 years ago

Hi team, I have been using the RazorLight engine for resolving my email templates, I am facing high memory usage from the RazorLight engine. Please find the attached snap of memory usage report, this below snap taken in localhost.

image

image

We have hosted this app in GCP k8s too, there also facing the same issue, sometimes around 6GB memory used when we are having high incoming request.

image

Used Version: 2.0.0-rc.3 Thanks in advance.

KarthikJothi39 commented 2 years ago

Facing this same issue, Any solution?

NagarajMasub commented 2 years ago

@jzabroski do you have any idea on this?

jzabroski commented 2 years ago

There isn't anything here for me to look at. I am pretty surprised there is a report of high memory usage without a repro or using a professional .NET memory profiling tool. Screenshots of Windows Task Manager Performance tab are not acceptable. It should be immediately obvious where your problem is if you are using professional tools to analyze the problem.

I would also note that in your second screenshot, it does not look like a memory leak is there. That looks pretty steady to me, and does not match your description that your app normally takes only 200MB. Are you really suggesting that one RazorLight request takes 12 hours to execute? There's also no data suggesting you are using 6GB on GCP.

Given your code sample shows you are manually building a new engine on every call, maybe start your investigation there and use dependency injection and see if your performance improves?

Some basic tips:

  1. When posting an issue, follow the issue template.
  2. When posting code, don't post a screenshot of the code. (I never understand why people post screenshots of code in their IDE, when they can just paste it - this is like the most annoying behavior unless the person then marks the code up with illustrations to point out some problem. It's like you won't take the time to create a full repro, and you won't even take the time to copy-paste. I am being hard on you because if a team member of mine did this, I would give them the same feedback).
  3. If it's a performance issue, use a performance tool to measure the problem before going to someone else, who you are not paying, for help and/or blaming them.
  4. If you have an e-mail generation system that has very high load, you need to either scale out or make the e-mail generation more static content and use donut caching to eliminate memory usage overhead. (I do not volunteer my time any further than this hint, however.)
jzabroski commented 2 years ago

Closing. Please open a new issue if you have some more concrete details.

michael-freidgeim-webjet commented 2 years ago

@jzabroski "you are manually building a new engine on every call" We did the same by blindly following examples in Readme. May I suggest to add to Readme a tip to use dependency injection/singleton to use single instance of razorLightEngine