The scope of Ajax and the performance impact on the server

Source: Internet
Author: User
Tags query client
Ajax| Server | performance

Ajax has been hot for more than two or three years, and it has revolutionized the web and is no doubt about the unprecedented experience it brings to the user.

While Ajax can bring a lot of benefits to Web applications, the use of AJAX applications is still a matter of serious consideration and should never be misused.

First, a few old questions:

The first old problem, because Ajax needs Javascrip support, and also need to use the XMLHTTP object, so for browser compatibility need to consider. Thankfully, most browsers in the market have already supported XMLHTTP and JavaScript. At present, we can almost minimize the degree of compatibility issues, but does not mean that you can ignore it, after all, different browsers to execute the same client code will have different effects.

Second, the user's habitual, many user habits and the use of traditional ways to interact with the server, although they may be tired, but the habit is a habit, suddenly appear a new way when it will let them know the wrong. Ajax does not need to refresh the browser, so in many cases the user performs an operation to find that the browser does not have any movement will feel very confused, especially when the network speed is slow, a user's request takes a long time to respond, during the waiting period, Users may think that the web has a problem shutting down the browser or doing something else. In addition, users will be accustomed to some of the features provided by the browser, for example, forward, back, refresh, stop, these features are often used by users, and when the use of Ajax will lead to the failure of these functions, of course, now a lot of people have written a solution, there are many of these solutions online.

Another issue that needs to be noted is the impact on the performance of the server.

Ajax asynchronous request, this method will bring a new problem. In the traditional way, for a user, each request to the server requires a response from the server before it can make another request to the server, so that subsequent requests are processed after the last request has been executed. But with Ajax breaking this constraint, a user can execute multiple requests quickly and continuously, which in contrast to the traditional way, raises higher requirements for the server and poses a greater challenge to the programmer. Usually, you should try to avoid this situation, for example, Sina's comment page, the paging bar adopts the way of asynchronous request, the user drag the cursor can be easily directed to the required paging, but in the process of dragging, the cursor every page points to the server to request the appropriate data, If the user drags the cursor to page 10th at a specific speed, then the server will have 9 requests that are redundant, and if the 9 extra requests have the server perform the task of reading the database, this will waste a lot of server resources. If the user finds that the 10th page does not have what he wants, and then moves to page 9th, the server will request the corresponding data, but in fact the server has obtained the same data, if such a thing happens in real life, perhaps you will feel that this is really a lot of waste.

OK, or to pagination as an example, if we do not have to drag the bar, according to the previous page idea of "income and need", each request a different page only to get the data of the page, and use Ajax to give users a better experience feeling. This seems to be reasonable, because we used to do so, but in fact, is not the most reasonable way. Typically, the first 3 pages are the most popular for users, and the 3 pages are the most likely to be repeatedly requested. In the traditional mode, because regardless of how will be loopback server processing, so in the page thinking on the "income and need" argument. However, if you use Ajax when the idea is a little more rigid. Now that you're using AJAX, it's pretty certain that your users need to support JavaScript, so why not page them at the client? As mentioned earlier, the user's favorite first 3 pages, if the user needs to read from page 1th to page 3rd, if it is "income and need", then regardless of the use of Ajax, users read to the 3rd page of the process will need to request 3 times server.
Let's compare the two situations (assuming there are no pages 10 data):

1, produce 3 requests + open 3 times database + each read and transfer 10 data amount of data
2, produce 1 requests + open 1 times database + read 30 data each and transmit

2 less than the situation 1 open 2 database, on the execution of 2 database queries, less than 2 requests, more than 20 rows of query data volume

Obviously, in the 2nd case, the user will wait for less time and the server will do less processing.

This is the new paging method that I put forward to read the data that the user will request more than once, and then page through the client. The user gets more data on the first request and then processes it through the client, so that the user does not need to request the server in the process of Reading page 3rd from page 1th, the first 3 pages are easier to switch, and the server's burden is reduced. The only downside is obviously that the first time a user asks for a little longer, but more than 20 data query volume and the amount of traffic compared to the time saved by the page switch is insignificant, in addition to the Ajax, we can use it to make users feel less than the amount of 20 data processing.

The use of Ajax can bring users a good user experience, but the handling of the bad words will cause the server to bear a greater burden, the same processing good, you can reduce the burden on the server redundant, the specific situation to see how to use.



Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.