The problem of improper use of RAM in ASP.NET Core Web API project - memory-management

I have an ASP.NET Core 6 Web API project.
When I'm running the project, my project takes about 2 GB of memory!
I found this problem in the dotMemory application:
There seems to be a problem with this part (Routing)
My project has some routes.
For example for every action, It has four routes.
They are defined like this:
Where do you think the problem is, where did this memory problem come from and how should I solve it?

Related

Separating different parts of the project in Git

How can I efficiently separate different parts of the project in Git? I have a Laravel web application that includes admin panel + API for Mobile app to increase performance. I thought it would be a good idea to separate the admin part from the API to disable a service provider in API and even run the admin panel on a different server (connect to the database via remote MySQL) and dedicate a server API. How can I separate these parts without duplicating changes that I make in common parts like models? I thought of creating them as two branches in a Git repository. Is there a better way to do this separation or the whole optimization that is easier to maintain?
Update: The issue I'm facing is the response time. I put the following code into my routes, and it takes 400-600ms to respond.
Route::any('/test2', function()
{
return "test";
});
I tested it on two different servers, and the configuration is good enough, I think (10GB ram - 4 CPU core 3.6Ghz). By the way, I have less than 1k requests per hour for now, and soon I'm looking at 5k-20k at most.
I think dividing your source code into modules is good enough. Give a look to Laravel Module
I will suggest you to do as the creator of the Framework (Taylor): Packages and use Composer.
In the Laravel community, you have many Packages available like Horizon, Nova, Telescope, Spatie/* etc.
If you want to add them you just have to add a Composer dependency and it just work out of the box.
You can do the same with your code that will be in both project like Models etc.
Every Package has its own Git repo.
This is a more Laravel way to do it than separate into Module (compared to Symphony world). Laravel doesn't come with Modules at its core.
Now about separating projects:
As i read your need, i am not sure you will have performance issue if you run the API and the admin panel on the same project unless you have millions of http calls per hours.
I am currently working on a project with a lot of code for the client side, we also have an api with thousands of call per hours and everything is fine. We also run Nova for the internal backend.
You should consider that when you will have those scale problem, you will probably have database problem too and maybe servers problems (bandwith, memory, cost etc).
To be scalable 100% is not an easy task.
In my opinion, when you face it, solve it. Separating the Api/admin pannel at the beginning could be too much overhead to start/maintain a project.

ResolveRequestCache state takes much time

I have a C# MVC application hosted in IIS test environment with only one action method in APIController. Clients call this single method and depending upon the parameters different small processes are performed.
I am using IIS 10.0.17763. Application is built in .Net Framework 4.6
I have disabled these modules as i don't need them.
WebDAVModule
WindowsAuthentication
ScriptModule-4.0
DefaultAuthentication
ServiceModel-4.0
UrlAuthorization
FileAuthorization
The problem is that under load test from jmeter, all calls somehow stay longer in ResolveRequestCache State.
Can someone guide me the problem behind or suggest me something to check. I am not using any kind of caching due to business requirement.
Here is the Screenshot of requests states from IIS
Edit. I have removed some other modules too to check the effect.
Here is the list of loaded modules in my application

Can I just create a simple website project in VS without the .NET stuff?

I would like to split my .NET Core web application into multiple layers:
UI
API
Logic/Domain
Data
...
All of them seem clear enough apart from (1). Is it possible to create a simple web site which consumes the API layer? When I mean simple I mean that I do not think it needs .NET Core, just client side libraries such as Bootstrap/Angular.
I can create a simple project like this outside of VS easily, but I want it as part of my project, when I go to New Project all I see is:
What is the correct approach to take here?

MVC Areas and load-balancing servers causing intermittent 404 errors

I've created an MVC application and deployed it to our three load-balanced production servers. I initially had some problems with pages not always being displayed but solved that by adding the machineKey to the web.config.
I have now extended my application by adding an Area and deployed that to the production servers and I'm now seeing 404 errors every so often. My previous experience suggests to me that there is an issue with the load-balanced servers. I note that there is a web.config for the Area I created but adding the machineKey to that resulted in an error.
The rest of the site outside of this Area still works fine so I'm wondering if there is something I'm missing with regards to the set up.
The only thing I've found so far is this question but here the issue was due to an upgrade from MVC 3 to MVC 4. I'm using MVC 3. I don't think the issue is with routes since every third or so attempt results in a page being loaded.
EDIT
The Areas works fine on one web server but does not work on the other two. MVC is not installed on any of the three servers so when I push the code I deploy the dependant assemblies.
I asked a related question to this problem. The fix that solved that one, also solved this.
The solution was to remove this file MVC-AreaRegistrationTypeCache.xml from within the Temporary ASP.NET Files directory.

Why is pre-compiling my ASP .NET MVC project not improving my first time access speed?

I have tried two things. One is pre-compiling my ASP.NET MVC 3 project using aspnet_compiler, and the other is using RazorGenerator in the project to allow the views to be compiled. Using both methods, I still see that pages in my site are having to compile on the first access. I see csc.exe running on the server when they are first accessed and it doesn't happen the next time. Why are these pre-compiling steps not preventing this and thus letting me have faster first time access?
Pre-compiling an application won't improve the first request startup time because there are still many things that need to happen when the first request arrives:
The Application_Start method executes
Controllers and Views location are retrieved and cached for subsequent requests
...
You could use the AutoStart feature of IIS 7.5 and ASP.NET 4.0 if you want to preload an application in memory when the web server starts. This way the application will be hot and waiting for the first request.

Resources