A summary of the slow load problem when the EF first load is slow or not accessed over a period of time

Source: Internet
Author: User

Optimization Scenario 1. Installing application Initialization

This is only available after Iis8, IIS8 built-in features, and for iis7.5 also provides an extension to support this feature.

Application initialization Module for IIS 7.5

At the bottom of the page, find the installation link that fits your architecture

    • x86 for Windows 7
    • x64 for Windows 7 or Windows Server R2

After installing this IIS module, there is no module icon and configuration interface in the IIS interface, and you need to install:

Http://pan.baidu.com/s/1c091WxM

After successful installation, there will be one more configuration such as:

If you are only configuring the program pool StartMode for Alwaysrunning,
You can also open preload and Doappinitafterrestart for the site at the same time.

To set up an application pool such as:

Set up Web sites such as

After the configuration, the test, the effect is very good.
The first time you open each site after you recycle the program pool, the latency is low.
In fact, the idea of this module and timing from the outside to trigger an access is the same, but the better part is that it itself in the program pool recovery restart when it completed the matter, without allowing external access to encounter the situation of the first visit.

2. Create a local image of EF with NGen installation

Because C # is using the just-in-time (JIT) compiler to compile the original assembly. Therefore, the first time you run a C # program (or DLL), the program starts very slowly. To improve the user experience, you can use Microsoft's native Image Generator (Ngen.exe) to improve the performance of your program. Ngen.exe Create native images (files that contain compiled processor-specific machine code) and install them into the native image cache on the local computer. Instead of compiling the original assembly with the just-in-time (JIT) compiler, the runtime can use the native image from the cache.

1) Navigate to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 in the command line. Because Ngen.exe is stored here, Ngen.exe cannot be executed correctly if it is not located.

CD C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

2) Raw machine native image.

NGen Install D:\SystemTool\ManagerNote.dll (Note: DLL mode)

NGen Install D:\SystemTool\ManagerNote.exe (Note: exe mode)

3) To uninstall native native images, use the same command-line options as when you installed the computer.

NGen Uninstall D:\SystemTool\ManagerNote.dll

Note: Here, depending on your own machine (32 or 64) and. NET version, select the appropriate command, just install EntityFramework.SqlServer.dll, because Ann relies on EntityFramework.dll, will automatically install the generated EntityFramework.dll Local mirror.

3.EF pre-generated Mapping Views (pre-build map view) Application_Start Add the following code:
using (varnew  Efdbcontext ()) {    var objectContext = ((iobjectcontextadapter) DbContext). ObjectContext;     var mappingcollection = (storagemappingitemcollection) ObjectContext.MetadataWorkspace.GetItemCollection (dataspace.csspace);    Mappingcollection.generateviews (new list<edmschemaerror>());     // do this for all dbcontext defined in the program}
4. Supplement

If you feel that this has not been resolved "after a period of time not to access the page and then open the page again slow" problem, and can not bear the first visit or a little slow, you can set the application pool "idle time-out" and recycle "fixed interval" longer or a scheduled task to visit the use of EF pages, This gives EF a warm-up so that EF does not get cold, which prevents a long time from not requesting the site, and the application process stops accessing the problem again slowly. The time to set the application pool is as follows:

The idle timeout is 20 minutes by default, and the application pool worker process is closed if it has not been requested for more than 20 minutes. Here you can set up a bit longer according to your needs.

A summary of the slow load problem when the EF first load is slow or not accessed over a period of time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.