ASP.NET startup Performance profiling web

前端 未结 4 1585
情深已故
情深已故 2021-02-09 17:39

I\'m trying to determine the cause of a very long (imho) initial start up of an ASP.NET application.

The application uses various third party libraries, and lots of refe

相关标签:
4条回答
  • 2021-02-09 17:47

    Your DLL references are loaded as needed, not all at once.

    Do external references slow down my ASP.NET application? (VS: Add Reference dialog)

    If startup is taking 2-5 minutes, I would look at what happens in Application_Start, and at what the DLLs do once loaded. Are they trying to connect to a remote service that is very slow? Is the machine far too small for what it's doing (e.g. running a DB with large amounts of data plus the web server on an AWS micro instance or similar)?

    Since the load time is probably not the IIS worker process resolving references, I would turn to traditional application profilers (e.g. Jetbrains, Antz, dotTrace) to see where the time is being spent as the DLLs initialize, and in your Application_Start method.

    0 讨论(0)
  • 2021-02-09 17:58

    Entertainment options check along with profiling:

    • profile everything, add time tracing to everything and log the information
    • if you have many ASPX views that need to be compiled on startup (I think it is default for release configuration) than it will take some time
    • references to Web services or other XML serialization related code will need to compile serialization assemblies if none are present yet
    • access to remote services (including local SQL) may require the services start up too
    • aggressive caching in application/remote services may require per-population of caches

    Production:

    • What is the goal for start up time? Figure out it first, otherwise you will not be able to reach it.
    • What is price you are willing to pay to decrease start up time. Adding 1-10 more servers may be cheaper than spending months of development/test time and delaying the product.
    • Consider multiple servers, rolling restarts with warm up calls, web gardens
    • If caching of DB objects or in general is an issue consider existing distributed in-memory caches...
    0 讨论(0)
  • 2021-02-09 18:10

    Separate answer on profiling/debugging start up code:

    w3wp is just a process that runs .Net code. So you can use all profiling and debugging tools you would use for normal .Net application.

    One tricky point is that w3wp process starts automatically on first request to an application and if your tools do not support attaching to process whenever it start it makes problematic to investigate startup code of your application.

    Trick to solve it is to add another application to the same Application Pool. This way you can trigger w3wp creation by navigating to another application, than attach/configure your tools against already running process. When you finally trigger your original application tools will see loading happening in existing w3wp process.

    With 2-5 minutes delay you may not even need profiler - simply attach Visual Studio debugger the way suggested above and randomly trigger "break all" several times during load of your site. There is a good chance that slowest portion of the code will be on the stack of one of many threads. Also watch out for debug output - may give you some clues what is going on.

    You may also use WinDbg to capture stacks of all threads in similar way (could be more light way than VS).

    0 讨论(0)
  • 2021-02-09 18:12

    Despite a large number of dlls I'm almost sure that for a reasonable application it cannot be a cause of problem. Most of the time it is static objects initialization is causing slow startup.

    In C# static variables are initialized when a type is first time accessed. I would recommend to use a sql profiler and see what are the queries that are performed during the start time of the application and from there see what are the objects that are expensive to initialized.

    0 讨论(0)
提交回复
热议问题