IIS application pool _ cache collection

Source: Internet
Author: User
Original article: IIS application pool _ cache collection

Recently, due to my company's business, I need to store the questions and answers of the questionnaire into the cache, which has increased the loading speed of the questionnaire and reduced the pressure on the database.

Cache key code (company code has been encapsulated and only key code is pasted here ):

Httpruntime. cache. insert (Key, value, new cachedependency (dependencyfile), cache. noabsoluteexpiration, slidingexpiration, cacheitempriority. High, onremovecallback );

The cache is stored in the IIS application pool, which uses the relative cache time mode. It is unrealistic to wait for enough time to perform the operation. Therefore, the cache is used to query information online and ask colleagues, two solutions are found:

1-manually recycle the application pool on the corresponding server IIS (cache data is cleared and used after impact evaluation)
2-after modifying the configuration file of the project, the collection time of the IIS application pool will be triggered. (This can be set in the advanced settings of the IIS application pool)

/// <Summary> /// insert a cache object (relative expiration time, cache dependency) /// </Summary> /// <Param name = "key"> </param> /// <Param name = "value"> </param> /// <Param name = "slidingexpiration"> relative expiration time </param> /// <Param name = "dependencyfile"> file dependency </param> /// <Param name =" onremovecallback "> processing method after the cache disappears </param> Public static void insert (string key, object value, timespan slidingexpiration, string dependencyfile, cacheitemremovedcallback onremovecallback) {generatefile (dependencyfile); httpruntime. cache. insert (Key, value, new cachedependency (dependencyfile), cache. noabsoluteexpiration, slidingexpiration, cacheitempriority. high, onremovecallback );}

 

 

Article: http://www.cnblogs.com/guohu/p/5209209.html

 

IIS can be set to automatically recycle at a scheduled time, which is 1740 minutes by default, that is, 29 hours. IIS automatic recovery is equivalent to IIS restart on the server, memory in the application pool is cleared, and all data is cleared. It is equivalent to IIS restart. on the server side of the measurement and rapid development platform, in order to reduce the burden on the database, A lot of information is saved in the memory, which is not suitable for frequent recovery. Because recovery will cause all data in memory on the server side to be lost. If the data is not saved to the database in time, it may cause program problems. If the system is not suitable for recycling during peak hours, recycling may result in dozens of seconds of no response from IIS. This is a bad experience for working staff, it may be caused by problems such as network or disconnection. Therefore, based on the above analysis, we need to set IIS to recycle regularly within the specified time.
The measurement quick development platform (hereinafter referred to as the measurement platform) uses the WebService method to build the server. Therefore, you need to correctly configure IIS (Internet Information Service) to ensure reliable and stable operation of the server, to provide customers with a better user experience. To protect server resources, IIS has an application pool recycle function, and is already set to recycle once every 1740 minutes (29 hours) by default. To better set this attribute, we need to master the IIS recycle function settings and adjust them according to the actual situation of the application to achieve the best effect of system operation.
In the IIS application pool recycle, find the corresponding application pool and click Advanced Settings to view the recycle settings (this article takes iis7 under windows2008r2 as an example, similar to windows2012 ).

(Figure 1)

Recycling is prohibited in case of configuration changes: If it is true, the application pool will not be recycled when configuration changes occur.
Fixed interval (minutes ):After the set time is exceeded, the application pool is recycled. If the value is 0, the application pool is not recycled at a fixed interval. The default setting time is 1740 (29 hours ).
Disable overlap collection:If this parameter is set to true, the application pool is reclaimed to exit the existing workflow before another workflow is created.
Request restrictions:The maximum number of requests that can be processed by the application pool before collection. If the value is 0, there is no limit on the number of requests that can be processed by the application pool.
Generate collection event log entries:Each time a specified collection event occurs, an event log entry is generated. The detailed settings are not described in detail.

According to the server configuration of the measurement platform, the default 1740-minute Recycle Process Policy of IIS is not reasonable, because every 1740-minute recycle may be in the peak hours when users use the system, to avoid uncontrollable problems during peak hours, we recommend that you recycle IIS every Saturday night (such as and.

If we perform the recycle setting in the advanced settings of the IIS application pool, there are only two methods, one is fixed interval, and the other is manual collection. Fixed interval settings, which are not very easy to set in the middle of the night, to ensure that the week is collected late on Saturday. We recommend that you use the Windows "Task Scheduler" to configure a script program for scheduled task execution in the operating system for IIS collection, which is easy to set and flexible to adjust. To use scripts to execute IIS functions, you must check "IIS management scripts and Tools" in the management tool when installing and configuring IIS (SEE ).

With vbs scripts and batch files, combined with the task scheduler, IIS recycling is ensured at every Saturday night.

Recyclepool. vbsFile Content:

Apppoolname = wscript. Arguments (0)

Set owebadmin = GetObject ("winmgmts: Root \ webadministration ")

Set oapppool = owebadmin. Get ("applicationpool. Name = '" + apppoolname + "'")

Oapppool. Recycle

Set FSO = Createobject ("scripting. FileSystemObject ")

If (FSO. fileexists ("D: \ apppool \ recycleiispool. log") then

'1-forreading, 2-forwriting, 8-appending

Set file = FSO. opentextfile ("D: \ apppool \ recycleiispool. log", 8, ture)

Else

Set file = FSO. createtextfile ("D: \ apppool \ recycleiispool. log", 8, ture)

End if

'Write (x) Write x characters, writeline write line breaks, writeblanklines (n) Write n empty lines

File. writeline now & "application pool" & apppoolname & "" has been recycled successfully. "

File. Close

Recyclepool. batFile Content:

Cscript D: \ apppool \ recyclepool. vbs platweb

 

With vbs scripts and batch files, combined with the task scheduler, IIS recycling is ensured at every Saturday night.

The scheduled IIS task is successfully executed in windows.

 

IIS application pool _ cache collection

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.