Small website architecture optimization: from 100 concurrency to 4000 concurrency

Source: Internet
Author: User
Tags vps
Preface:A long time ago, in the M memory + Access VPS, I wrote a series of classic technical principles of the autumn garden. One day later, I switched to 1 GB memory + MSSQL2000, and the autumn garden ran for another year. Later, the autumn garden and CYQ. Data were quietly optimized and improved, but they did not write any articles to share and share. The architecture of the autumn garden is basically from simple to complex, and finally returns to simple, constantly performing subtraction, removing a lot of algorithms previously used to reduce load, including AOP + SQLite partial pressure and text partial pressure mechanisms, there are also some cache algorithms. In many cases, if the hardware is not powerful, it will be forced to complicate the entire system architecture. 1. When the hardware is powerful, the system is light-loaded and the architecture can be simpler. Because the essence is request + return (the software does not need to develop too many algorithms if the hardware can accelerate ).

Next, let's share with you what I remember in my memory about the startup of load testing in the autumn Garden:

 

1: one day, I found that the CPU of the autumn garden is always full of 100%:After a year, I finally discovered that it was caused by a search engine (although I have written IIS log analysis tools, I have rarely used them myself and almost never used them, I did not expect to find the problem ).

I found that the keyword (Tag) of the autumn garden is directly linked to the search, and the search is like search for the entire table, with no cache optimization, therefore, when the search engine is in a good mood, it will be ruined.

2: One day, someone used hundreds of concurrent jobs to bring the autumn garden a hundred percent CPU:

I am confused that the autumn garden is almost always semi-static + cache. In addition to the queue cache-type update access count, and in addition to the background, it is impossible to stick to this concurrency.

By viewing the IIS log, I found from the log that it is caused by a URL: Because the autumn garden is cached Based on the URL, the concurrency of the other party adds some random parameters after the URL, as a result, the URLs of each request are different. As a result, the system re-reads and generates Html, causing the CPU to float. The solution is to reorganize All URL links and the corresponding cache mechanism.

3: One day, I also played with the load tool, and I got CPU from time to time.

 

Next, we will share several optimization solutions for the follow-up of the autumn garden under the load thrust:

 

After continuous load tests, some common optimization methods have also been used in the autumn Garden:

 

1: Separate static resource Domain Name: static.cyqdata.comArchitecture processing process:

1: process the template and image processing to another domain name. 2: open a new website and bind the static.cyqdata.com domain name. The location still points to the original location. 3: because it is a static site, you can turn off anything unrelated to. net. After this change, the image load is a change of Heaven and Earth: If not separated, the image will still be returned after. net resolution, and 1-2 Concurrent CPUs will be full. After separation, the. net-related resources are turned off, and more than 5000 of the concurrency is run, the CPU and memory are not dynamic. The number of concurrent threads of the three primary machines is about 5 kb at most, and the test cannot be performed, but the gap is already obvious.

2: Http 304: This is the client cache application:

In addition to the server cache, the client cache is also another focus. In addition to some static data processing caches, dynamic data is also used at 304 in a timely manner.

For example, there are some dynamic "download times" on the autumn Garden ":

Generally, files are downloaded separately from the document content.

As shown above, I need to provide downloads in the content of the article, and I need to consider the number of downloads mechanism. I used the image mechanism and returned image resources through a dynamic request. Because the real-time performance is not strong for the next few times and the changes are few, You Can cache the data by 304.

3: Disable Modules that are not commonly used:

If you have rewritten the URL or read the article about URL rewriting in the technical principle parsing of the autumn garden, the following code should be familiar:

Through debugging, we can see that there are only three Modules left in the autumn garden. At that time, all the other useless Modules were turned off. Originally, the Session module was to be switched off. It was suddenly found that oau22. You will also find a comments for statement that prints more than a dozen Moudules in the default system. It's easy to turn it off, web. config configuration:

4: Close the database link as soon as possible:

I used to like writing code like this: using (MAction action = new MAction (U_QBlogFileEnum.Blog_File) {action. setSelectColumns (Files. ID, Files. hits, Files. filePath); if (action. fill (id) {Document. load (action. data );.. Obtain database data processing. Some business logic is displayed on the interface.} Due to this bad habit, database links will be closed after the service time is extended, leading to a decline in concurrent performance, which cannot be seen at ordinary times. Improvement: MDataRow row; using (MAction action = new MAction (U_QBlogFileEnum.Blog_File) {action. setSelectColumns (Files. ID, Files. hits, Files. filePath); if (action. fill (id) {row = action. data ;}} if (row! = Null) {Document. Load (action. Data );.. Obtain database data processing. Some business logic is displayed on the interface .} Put the logic out and close the link in advance before processing the task. The performance will be improved a lot during concurrency.

 

5: Anti-concurrency capability of the Web Park:Based on the continuous optimization and improvement, the autumn garden has gone from 100 concurrent food-> basic optimization-> 1000 concurrent food-> architecture adjustment and optimization-> to about 2000 concurrency.

Finally, there is another trick, namely, the IIS Web garden. By setting up two processes as allowed, it is found that it can defend against 4000 concurrent connections. Although the CPU is close to 100%, it can still be accessed normally, it can be seen that the Web garden is indeed a strange trick. Enabling the Web garden means multi-process load. Of course, the default Session mode cannot be used. As mentioned above, the same hardware configuration: from 100 concurrency to 4000 concurrency, there are not many changes and the path is not long, but the average person knows how much. The above server environments are all us vps 10 M bandwidth CPU dual-core, the configuration is as follows:

6. How to perform load tests on websites:

Distributed website load stress testing tool: Click to download

After that:

Top half of hardware performance: a good server, poor program writing, no optimization, and easy to run.

Software capabilities: Good optimization mechanisms and architecture, poor servers can also run securely. In reality, you can only think about the importance of the other half when it exceeds the half-day.

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.