High concurrency Processing

Source: Internet
Author: User

To the following article content I want to explain under, in the deep-pocketed Internet company or for the deep-pocketed customer service not lack of money of the Lord, please immediately detour, the following content is not suitable for you.

The following is a shortage of computing resources for customers, budget constraints, unable to increase bandwidth, increase the number of servers, the purchase of a variety of high-level services of the program members to discuss.

Thank you

For how to improve the performance of your application (whether it's an Internet application or an enterprise application) My point of view has been to consider a core: IO processing. Because I think the current CPU processing capacity is very high, the normal writing in memory processing code is not too serious problems will not have a significant impact on the CPU, performance is often limited by IO. As my team and I communicated for a long time, a simple IO description between us often covered a lot of meanings, including disk IO, network io, memory io, and IO processing for various devices. Our team experience is to find out the efficiency that can be improved in the various IO processes as much as possible.



Below, I will explain the experience and understanding of our team in enhancing IO processing


1 database
Database is the most obvious consumption of disk IO components, improve data performance There are many, SQL statement is good, also reduce the table scan (obviously IO action), design a reasonable index is to improve the IO processing ability, will not change the historical data independent storage also reduces the processing of complex IO, Designing redundant fields for tables is also to reduce IO read and write performance, and distributing data tables on different disks also improves IO efficiency. There are other ways, such as querying the cache, connecting the pool of gods and horses, as well as the principle.

In a word, reducing the excessive activity between database and disk can improve database efficiency as much as possible.




2 Data cache
Memory Io is naturally much more efficient than disk IO, where the data is cached to reduce disk operations or at least lower performance database operations. For the results of page data caching our usual simple scenario is to prepare two buffers: one memory, one file
Memory of the buffer, we directly with Httpruntime.cache, in this buffer we place the signature and data (data is often the page needs data, generally we put JSON format), the expiration policy we naturally choose Noabsoluteexpiration.
When the data needs to be removed from the memory buffer, we process the stale data again, and we have a collection in the cache that sets the signature of the cached data that was dropped, and the corresponding data is written to a file on disk.
When the user requests the data, first check whether the signature is in the normal cache, if not, check whether in the expiration area, if it is expired, then read the disk file (at least the database overhead), do not, go to the database.


3 Code handling of collections
Whether it is the JavaScript on the page, or the java,c# in the background, the operation of the collection/array in the current business is certainly the most frequent, consider the optimization with some details, also can improve the performance

[CSharp]View PlainCopy
    1. Int[] arr = {1, 3, 6, 7, 3, 6, 7, 3, 5};
    2. for (int i = 0, max = arr. Length; i < Max; i++)
    3. {
    4. System.Console.WriteLine (Arr[i]);
    5. }



Similar to many techniques, it is useful to reduce the repeated acknowledgment of set Length/count to the collection operation of high frequencies. Of course, there is no dynamic addition and subtraction of data in the collection. Array precedence, generics second, ArrayList the last consideration, the reason for these selections is to reduce the IO overhead.
There are many more details of the code that can improve efficiency, such as the perception of string.
(Lin Yongjian MVP hint I did not express clearly the above meaning, my idea is: Set my test is, if repeatedly judge count will be slower, not better for when the count first to find out, there is as far as possible to use the array, because the array is initialized when the assignment is complete, and is strongly typed, I don't know what I'm saying, No.





4 Network Transmission
Background data ultimately to be passed to the browser, reduce the network transmission of bytes is also the focus of increased throughput, simply speaking, is the Network IO processing optimization. Reduce ViewState information in WebForm, or simply use MVC instead of webform, or control all state information directly HttpContext yourself. We use ASHX and open different ashx channels for different services to improve performance. Because ASHX does not have to do a series of actions, not through a series of event processing, a lot of control state management (load and parse viewstate, restore, update the value of the control, save viewstate, etc.), directly return the results of the operation, do not consume more server resources, The return format is also very flexible, all with ashx in a document-based Web site we use very well.
Another point of ashx is also very good for working with development members.
In addition to the programming impact on the transmission, the page needs images and CSS files, JS file reasonable processing to reduce the HTTP request can also improve network IO efficiency: For example, the image merge, JS, CSS compression and other simple ways, although the change is not much, but the concurrency of the pressure is always good to reduce the server.




5 Page rendering and experience
Optimize the HTML structure of the page, sometimes in order to speed up the rendering, do not have to fully conform to the specifications, reduce div nesting, use fixed width, the main JavaScript details can improve the good experience. My test results in chrome show that, in many cases, the speed of the network is much higher than the rendering speed, so it can improve the processing of the page, the experience of individual users is very effective.




4 Data submission
In the case of reliability, consider asynchronous mode or multi-threaded. For database submissions, Web service access can use the asynchronous model, of course, in a reliable situation.
The Ajax nature of the page is also an asynchronous way, and the loading of JS files can also be asynchronous.


5 Lock

Too tired to write first.

High concurrency Processing

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.