Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of performance Infrastructure of web website

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "web website performance infrastructure example analysis", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "web website performance infrastructure example analysis" bar!

Http Compression (compression); Content Expirations (content expiration); Content Distribution Networks-CDN (content delivery network); Etags (E tag); remove unnecessary Http header

[Compression]

As we mentioned earlier, one of the performance rules is that the less data is transferred between the server and the browser, the better. Because of this rule, we can use a more mature technology: Http Compression.

The Server side evaluates the "Accept-Encoding" in the header in the http request sent by the client. To determine whether the client can handle compressed data. If supported, the server side will compress the data and return the results to the client.

According to the evaluation of keynote, a third-party service, it can save an average of 53% of the bandwidth, and the website is 25% faster on average.

Now IIS also provides support for this technology (free)

IIS7 support for compression

Support configuration when cpu occupancy is too high, automatically stop using

The default minimum file size is 256k.

Compression of static content is enabled by default

[configure Compression in IIS]

Open IIS. Select one of your websites. Select compression in the right tab.

Maybe some friends will find that dynamic compression is gray. Actually, we didn't install the dynamic compression module. I am using win7. The installation method is as follows:

Control Panel-"programs -" turn windows on or off-"Internet Information Services -" World wide Web Services-"performance Features (obscene) -" dynamic content Compression

If you are a friend of win server version, you need to:

Administrative Tools | Server Manager.

Expand Roles and click Web Server (IIS).

Scroll to Role Services, click Add Role Services, and open the Add Role Services wizard.

On the Select Role Services page, scroll to Performance, select Dynamic Content Compression, and select next.

Now we still use the website used in the chapter to do the test. Open fiddler.

Write down the size of each file. Return to IIS and turn on dynamic and static compression. Now when IIS receives the js and css files that request me again. It will first determine whether the requested file has been compressed. If not, it will be compressed and stored in a directory. When other users also request the same file, it can get the compressed file directly.

Now let's go back to fiddler and see the results.

The jquery file is compressed from 236k to 90k. Other js and css files are compressed accordingly.

Now let's use another sharp tool in the previous chapter, microsoft network monitor, to look at the changes before and after compression.

Before compression:

After compression:

It's very easy to compare with MS Network monitor. Before and after compression, the number of frame decreased significantly, from 40 to 9.

Because more than 95% of requests are asked if compression is enabled. So mainstream browsers support compression.

Enabling compression takes up a little bit of cpu. IIS7 optimizes this piece.

To ensure that compression does not overload CPU, IIS7 calculates average CPU utilization every 30 seconds. When CPU utilization exceeds a limit, it automatically turns off compression. When CPU utilization falls below the limit, it re-enables compression.

The default value for the limit is:

Note that this means that if the CPU on the server is always above 50%, but occasionally higher than 90%, dynamic file compression will be turned off, but will never be turned back on.

You can modify these restrictions by modifying the applicationHost.config file, which is usually under the C:\ Windows\ System32\ inetsrv\ config folder.

Find the section.

two。 Modify the httpdynamicCompressionEnableCpuUsage property:

3. Restart IIS.

[Content Expirations]

Review the performance rules we * * Zhang talked about. One is to transfer data as infrequently as possible.

When a user visits the home page of my website, he will get my js,css and pictures and other files. The browser saves it to the local cache for him. A few days later, users came to visit my website again. The server also checks the browser cache to see if there are any files he wants. If there is, it will tell server. I have this file. But I want to know if its version is *. The server will see if the file has been changed or not. If it changes, the server will send a new file. If not, the server will return to the browser status code 304. The sound of the waves is still there.

three hundred and four。 No change.

Take advantage of browser cache:

Set expiration time for content folder

Try to avoid requesting files that are changed infrequently

Rename the file, if you need to rewrite the browser cache (version number / timestamp)

[configure Content Expirations in IIS]

Open IIS. Select your site. Select the scripts folder (where the js is installed. If any) find the HTTP response header in the view tab and enter.

In the upper-right corner, set the commonly used header-"to expire web content." Let's set it for five days. Visit our website at this time. Using fiddler, the results are as follows:

That max-age, let's do the math. Exactly 5 days:) now let's open IE again. Internet options-"Browse History -" Settings-"View Files"

Find our js file. Check the properties, which expires on August 7, exactly 5 days:)

[CDN]

Another effective way to improve the performance of a website is to use CDN.

The full name of CDN is Content Delivery Network, that is, content delivery network. The basic idea is to avoid the bottlenecks and links that may affect the speed and stability of data transmission on the Internet as far as possible, so as to make the content transmission faster and more stable. By placing node servers everywhere in the network to form a layer of intelligent virtual network based on the existing Internet, the CDN system can redirect the user's request to the nearest service node in real time according to the comprehensive information such as network traffic, connection of each node, load status, distance to the user and response time. Its purpose is to enable users to get the content they need nearby, solve the situation of Internet network congestion, and improve the response speed of users visiting the website.

Let me talk about the CDN that we can take advantage of:

JQuery is one of the current js library. Google, microsoft, and jquery.com all have free host jquery libraries on their cdn. Please take a look at the following picture:

I can use the jquery file on our own server here. You can also choose to read it from cnd on the official websites of google, Microsoft and jquery. That is, you can reduce the pressure on your server. You can also use cnd to speed up reads.

[ETags]

What is ETags? The full name of Etag is entity tag. ETag is actually a value made up of hash+changeNumber. Hash is generated from the contents of the file. ChangeNumber in IIS7 defaults to 0

As mentioned earlier in this chapter, we use browser cache to optimize performance by setting the content to expire. We will use expires headers to tell the browser that instead of sending conditional GET requests to the server, we can just cache the data in it, thus speeding up access.

The process of using Etags is as follows:

1. The client requests a resource source.

two。 The server returns the page souce and adds an ETag to the source.

3. The client displays the page and caches the page along with ETag.

4. The client requests the resource source again and passes the ETag returned by the server to the server when the last request was made.

5. The server examines the ETag, determines that the page has not been modified since the last client request, and returns a response of304 (unmodified-- Not Modified) and an empty response body.

From then on, it seems that Etag may mislead the browser into ignoring the cache and repeatedly downloading the same file.

We try to delete ETAG from.

Let's see what ETAG looked like before it was deleted.

Using System; using System.Collections.Generic; using System.Linq; using System.Web / Summary description for ETagRemoveModule / public class ETagRemoveModule: System.Web.IHttpModule {public ETagRemoveModule () {/ TODO: Add constructor logic here / /} public void Dispose () {} public void Init (HttpApplication context) {context.EndRequest + = new EventHandler (HandlerEndRequest) } public void HandlerEndRequest (Object sender, EventArgs e) {System.Web.HttpContext.Current.Response.Headers.Remove ("ETag");}}

ETags is gone:)

[remove unnecessary Http header]

Using fiddler, we can see that http response header contains a lot of information.

But there is no need to show some information to the user. For example, we use. Netframework 4. 0. We use IIS7.5.

First of all, it is redundant information. Secondly, it may also be used by some hackers.

So let's modify our code:

Public void HandlerEndRequest (Object sender, EventArgs e) {HttpResponse oResponse = System.Web.HttpContext.Current.Response; if (null! = oResponse) {oResponse.Headers.Remove ("X-AspNet-Version"); oResponse.Headers.Remove ("Server"); oResponse.Headers.Remove ("ETag") }} Thank you for your reading. the above is the content of "example Analysis of web website performance Infrastructure". After the study of this article, I believe you have a deeper understanding of the problem of web website performance infrastructure analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report