最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to profile startup of ASP.NET Core app locally? - Stack Overflow

programmeradmin3浏览0评论

I have this app which takes ~12 seconds to start and another 10 seconds to start accepting requests. Which I would like to make faster specifically for members on my team. I would be satisfied with ~3 seconds.

I timed the startup when I have 2 web apps nested (second one runs as a hosted service of the first).

The root one I call DevServer which setup YARP (for SPA development) and adds hacked authentication for local development. And than it runs the actual app which should run in the cloud.

When I do any kind of profiling it only shows my code which is 10% of the 12 seconds of the startup. After startup I init a lot of cached data, I know how to deal with that. My question is how to profile the framework calls in the asp core. If there are any hooks of some sort, I would be interested to move into AOT, possibly source generated DI container. But both are considerable undertaking and before I can get a buyin from stakeholders I need to know what I should focus on and what gains I can expect. I would like to know how long does it take to make instance of IServiceProvider and how long does it take to init endpoints (for example).

Essentially I want to measure what happens between:

  • Startup.ctor
  • Startup.ConfigureServices(IServiceCollection services)
  • StartupConfigure(IApplicationBuilder app)
  • startup finished

I know how long the gaps are, but not sure what influences them.

If anyone can chip in where to look for and what to expect to find or even how to make a startup faster I would appreciate that.

000.000s (000.007s) - DevServer Main
000.104s (000.078s) - DevServer ConfigureServices
000.541s (000.437s) - DevServer ConfigureServices END
000.561s (000.020s) - DevServer ConfigureApplication
000.902s (000.341s) - Static VstStartup ctor
000.902s (000.000s) - VstStartup ctor
001.138s (000.236s) - VstStartup ConfigureServices
002.001s (000.863s) - VstStartup ConfigureServices END

--- this is where I want to know what happens

011.971s (009.970s) - VstStartup Configure
012.265s (000.294s) - VstStartup Configure END
012.353s (000.088s) - StartedAsync

I have this app which takes ~12 seconds to start and another 10 seconds to start accepting requests. Which I would like to make faster specifically for members on my team. I would be satisfied with ~3 seconds.

I timed the startup when I have 2 web apps nested (second one runs as a hosted service of the first).

The root one I call DevServer which setup YARP (for SPA development) and adds hacked authentication for local development. And than it runs the actual app which should run in the cloud.

When I do any kind of profiling it only shows my code which is 10% of the 12 seconds of the startup. After startup I init a lot of cached data, I know how to deal with that. My question is how to profile the framework calls in the asp core. If there are any hooks of some sort, I would be interested to move into AOT, possibly source generated DI container. But both are considerable undertaking and before I can get a buyin from stakeholders I need to know what I should focus on and what gains I can expect. I would like to know how long does it take to make instance of IServiceProvider and how long does it take to init endpoints (for example).

Essentially I want to measure what happens between:

  • Startup.ctor
  • Startup.ConfigureServices(IServiceCollection services)
  • StartupConfigure(IApplicationBuilder app)
  • startup finished

I know how long the gaps are, but not sure what influences them.

If anyone can chip in where to look for and what to expect to find or even how to make a startup faster I would appreciate that.

000.000s (000.007s) - DevServer Main
000.104s (000.078s) - DevServer ConfigureServices
000.541s (000.437s) - DevServer ConfigureServices END
000.561s (000.020s) - DevServer ConfigureApplication
000.902s (000.341s) - Static VstStartup ctor
000.902s (000.000s) - VstStartup ctor
001.138s (000.236s) - VstStartup ConfigureServices
002.001s (000.863s) - VstStartup ConfigureServices END

--- this is where I want to know what happens

011.971s (009.970s) - VstStartup Configure
012.265s (000.294s) - VstStartup Configure END
012.353s (000.088s) - StartedAsync
Share Improve this question edited Mar 18 at 5:08 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 18 at 1:03 vmachacekvmachacek 5831 gold badge12 silver badges28 bronze badges 2
  • "When I do any kind of profiling", so what exactly did you do? With a specific profiler or something you created on your own? – Lex Li Commented Mar 18 at 3:56
  • I use Metalama and wrapped every method call with one which calls into miniprofiler/dotnet . This way I can see there are some queries into database before init finishes, but that comes to ~2 sec. Also there is init of DB driver. This only profiled my code and than I used dotTrace to sample function calls but that too only showed my code – vmachacek Commented Mar 18 at 10:10
Add a comment  | 

1 Answer 1

Reset to default 0

I suggest you could consider using the Visual Studio Diagnostic Tools to check why it takes so long, you could remote debug it if it hosted on the server. More details about how to use remote debug, you could refer to this article.

The Visual Studio Diagnostic Tools contains the perf tips which you could see why it takes so long time. More details, you could refer to this article.

Besides, if using this tool does not match your requirements, you could consider use some tool like perfview to see why the start up takes so long.

发布评论

评论列表(0)

  1. 暂无评论