Server Design: Transaction splitting and Asynchronization

Source: Internet
Author: User

Server Design: Transaction splitting and Asynchronization

 

Now, basically all the server programs that are generally a little larger (this refers to the server programs that can accommodate at least thousands of clients ), it is inevitable that remote calls and database operations are involved. Both of these operations are operations with long latency. The back and forth of any network may be measured in milliseconds, and database operations may be performed in seconds. The result is: on the modern CPU, basic business processing may be completed in nanoseconds. However, due to the drag of remote calls and database operations, the processing process has to be stopped and waited, as a result, the final processing time must be calculated in dozens, hundreds of milliseconds, or even seconds. Even if IOCP is a powerful tool, it will be helpless in the face of such a situation. In this way, the performance of the server program will be much smaller than the theoretical value (or the design value). Even if the capacity cannot reach the theoretical value or the theoretical value, the speed may be 1% or 1‰ of the theoretical value, if there are other cases (for example, a large number of concurrent database operations lead to congestion, and if there is no good database design, this is also frequent), it is possible to have one in ten.

 

In this case, it is necessary to improve the transaction processing mechanism to split the original single and serialized transactions into several fine-grained transactions that can be parallel (if possible) and perform asynchronous processing on delayed operations (such as database access) in the split step. Note that transaction splitting is the basis for subsequent asynchronous processing, and there is no need to asynchronous the entire transaction. This is not appropriate and inappropriate. Splitting depends on the specific transaction processing logic and operating environment. Only after a transaction is well split, long-delayed operations can be easily split out, and asynchronous processing can be more convenient, which is also beneficial to the implementation. Transaction splitting and Asynchronization reduce unnecessary waiting and latency. Although the processing time of a single transaction may be extended at the micro level, the overall processing speed is improved at the macro level, the system performance will also be greatly improved.

 

Transaction splitting

Transaction splitting must be based on a complete understanding of the transaction processing logic (which is simplified as a transaction and must be done. Splitting may affect the structure of the system (this is inevitable). Therefore, you must be careful not only to establish a good splitting policy and mechanism, but also to consider a single transaction and the overall situation of the system. A common strategy is that operations with long latency should be split into separate steps.

 

Because the pre-and post-processing steps of a transaction are often associated, if the split transaction cannot be processed in parallel (this is common ), A one-way chain mechanism needs to be established so that the steps can be completed in the correct order. In addition, after completing the previous step, the system can find the next step, automatically traverse and process the remaining steps, and finally complete the entire transaction.

 

By carefully designing the structure, we can also make it capable of parallel processing.

 

Asynchronous

Asynchronization is usually used for long-latency operations. After a transaction is split, operations with long latency are stripped out, and asynchronous processing can be performed on the transaction. For Asynchronous processing, you can use COM in Windows. It should be noted that, after completing asynchronous processing, the next step should be processed correctly, which also depends on the design and implementation of the above chain mechanism.

 

Implementation difficulty and complexity

The difficulty of splitting and Asynchronization lies in the design and implementation of transaction processing, and the technical difficulty is the second. If it is to transform the original implementation, the difficulty and complexity will be greatly increased, may cause a large number of code to be overwritten, or even pushed to the entire system. Therefore, you need to make a choice based on the situation.

Undoubtedly, the complexity of the system is increased through splitting and Asynchronization, which is a required price. If we can carefully design sharding policies and mechanisms to establish a good structure, the cost is worthwhile relative to the gains we have made. As for Asynchronization, it is simpler.

 

 

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.