ASPPHP Cache Improvement Web Performance

xiaoxiao2021-03-06  15

First, what is the ASP cache / why to cache

When your Web site uses ASP technology, it is possible to feel the convenience of ASP dynamic web technology, as well as random modifications, free HTTP control. However, as the number of visits increases, you will definitely find your own site access speed is getting slower and slower, IIS is restarted to get more and more frequent. Next, you must optimize the ASP, such as replacement of more performance databases, establish indexes, writing stored procedures, and more. Some of these measures do not need to increase cost pressure, and some have a large cost pressure (such as Access to SQL), and the effect is not necessarily.

In the face of web access, I think the most economical approach is to use cache optimization techniques to achieve the WEB service pressure.

The increase in web access usually means rapid growth in the following resource requirements:

1. Network card traffic increases, need to consume more CPU processing network traffic and network I / O threads.

2, need more frequent opening / closing database links (if you use database technology - usually use databases as data storage), severely consuming resources, and deadlocks caused by transaction competitive resources, will increase network I / O Or CPU consumption.

3. If you use session, IIS will consume more memory in order to maintain a state, and memory consumption may cause insufficient physical memory, causing frequent exchange of physical memory with auxiliary intervals, causing a pause, web response blocking .

4. Since the accessible response is not prompted, it will cause web-access failures, resulting in user refresh, thus exacerbating resources such as CPUs, memory.

In fact, consider the usual web application, many times of dynamic code execution is unnecessary.

Second, the classification of ASP cache

Summary, ASP caching can be divided into two categories:

1, file cache

The so-called file cache is based on the logic judgment. The specific execution of an ASP will not change in a period of time, so it is stored in a static HTML, and then the client will access the static file with the Web redirection. To achieve demand for reducing CPU, database resources, etc. There are many applications, such as many forums regenerate the entire post to a static file when replying to post, then redirect, such as Donews.com forum. There is also a side effect (benefit) - can be easily recorded by search engines such as Google. Some so-called news distribution systems have adopted this technology.

2, file clip cache

The so-called file cache is also based on logical judgment, some data (usually a large-capacity database query that needs to consume resources) will not change within a certain period of time, so we can store these data to the form of files, when needed, You can get data by reading the file to avoid increasing the burden on the database. For example, we usually store some data in XML format, and then use the XSLT technology to display (XML processing usually require a large number of CPU resources, so IE usually read XML directly to the client on the customer's CPU). 9CBS forum is handled.

3, main memory cache

In addition, it is also possible to consider processing the cache in memory, which will require a timely response to store in memory, once accessing requirements, immediately transfer from fast storage. If a very large number of access requirements are concentrated in a few small pages or the main memory is enough, I want to use the main memory cache to greatly improve web access performance.

Third, how to implement / use cache

Realizing the cache requires the following questions:

1, which pages will not change in a short time?

Analyze your site, there are many pages. For example, a site usually has a news-based column, which is usually the site maintenance personnel to publish information at a certain time of the day, and then rarely change the page. Then these pages are suitable for use in static file cache. In fact, the so-called news distribution system is doing this, then you can also refer to these system ideas to transform your original dynamic ASP page. 2, those pages use the same logic generated for all visits (that is, no visits).

In addition to the news, all visitors look at an interface, the application of consumption resources such as the forum can also be designed into unified logic generation (the same post, Zhang San Li four looks like this), and we also You can use a static cache. It is also possible to consider dilating data, using scripting technology to process the client browser outside of server processing capabilities.

3, adopt the price and gain of the cache.

Mainly "spatial replacement (response) time. Use the cache technology to preprocessing the content of frequently needed, enabling it to improve the Web server responsiveness, and more importantly won the visitor.

The cost is the increase in web space, and it may affect the access effect.

But I think the appropriate cache is the benefits.

4, those places are not suitable for adoption

Dynamic query page, each person's query is different, so the display result is not large, so it is unlikely to generate a cache, so the cache is more complicated and the cache utilization is under the bottom of the management cost (assuming you cache. 1000 query keywords, then manage these keywords, the corresponding caching is also troublesome.).

Fourth, instance analysis

Suppose a proposed forum's original layout is as follows:

Under the root directory:

Default.asp Home, generally the essence, recommended

Listborad.asp This file lists the names and presentations of all sections. If the Parameters Mainbid indicates that the columns under the board are listed.

Listthread.asp This file If you do not carry any parameters, you are listed in all posts, carrying the mainbid means listing all the posts of a block. If the subbid is carried out to list a post to the specific column. If the Page parameter is carried, the topic is listed.

ViewThread.asp lists a post content. We assume that the post is displayed as a statement, all of which are all listed behind. The ID parameter is the post to display.

Reply.asp responds to a post, carry the parameter ID to respond to a post

There is no discussion.

With the above, we can see that if all is made using the original ASP / PHP, the execution of almost every ASP file requires database operation, frequent queries, multi-table query. To know that the query database will eventually lead to performance, the response speed is lowered, bringing the slow browsing impact on the visitor, which is not conducive to the quality of the Web. More importantly, for two people, they will access ViewThread.asp, if the ID is consistent, so many times they see the same content (the HTML code received almost the same), but for this "The same content", the server needs to open the database link, query, read record, display, turn off record, database linkage. . . . The following is the operation of the server resource, and if it is more people to access, the final result is these people to exacerbate the consumption server resources. In fact, repetitive labor for these "same content" is an optimized avoidance of cache technology. For example:

After the reply.asp is submitted, we immediately call the generated static function, store the entire post content as a static HTML file such as ViewThread_xxx.htm, and then access ViewThread.asp? Id = xxxx, the system is automatically Redirect to the corresponding static file ViewThreadxxxx.htm. This way, when a post does not have the latest release, he is always provided to the browser; once a new submission will be updated to a static file, this will save many database operations, greatly improve response speed. ListBorad.asp can also be static. We can analyze the parameters that it may carry, set the cache file name to listboard_xx.htm, update listboard_xxx.htm when adding new columns. Listthread.asp is also similar, but because of its parameters, there will be a lot of cache files. To cache Listthread.asp? Subbid = XXX & Page = 2, then the corresponding static file is Listthread_xxx_p2.htm. DEFAULT.ASP is the same.

So how do I judge when updated? What time is updated?

Discussion Listthread.asp? Subbid = XXX & Page = 2, we extract subid and Page in executing Listthread.asp Russia, then detect if listthread_xxx_p2.htm exists, if there is no existence, the file is called to generate the file, and finally redirects to this Static file. Note that there is no existence that there is a new content that requires us to update.

How do you cause the file does not exist? delete. When we publish a new post, remove a post, we can remove all static files like Listthread_xxx_p2.htm. This will notify you to cache.

There is still a problem now, how to generate static files?

We noticed that the "same content" we mentioned before. We can copy a copy of Default.asp, ListthRead.asp before the transformation, named default_d.asp, listthread_2.asp, and in the same directory (theoretical ListthTrad.asp? Subid = 123 with Listthread_d.asp? Subid = 123 The access result will be the same content), so that we call the reproduced copy before the logic that needs to generate a static file, call the previous copy, get the HTML code, and store it as a static file. This web request is actually equivalent to any real browser to access the static content, and the server itself will look at the HTML that will be output, and then returns these code, and the file operation is used to store as a static file. In this way, the cache file is created before the real browser.

Such a program hardly touches the original layout, almost no causes of errors such as 404 due to the transformation. Second, static files will also help your site to be included in search engines such as Google. Why is it not?

Finally, remind, through web access, in the ASP programming environment, many people use XMLHTTP components to access many problems. XMLHTTP themselves will request resources in Cache, resulting in the content we have received through this component, causing logical confusion. Therefore, the XML Server HTTP object or WinHTTP component should be selected to implement the web request resource.

转载请注明原文地址:https://www.9cbs.com/read-45886.html

New Post(0)