Explore Try again in enterprise-level development ...... Catch performance problems

Source: Internet
Author: User

Introduction
I have written an article titled using Try... Catch... in enterprise-level development will affect efficiency? This article has attracted the attention of many friends and I have talked with you privately.

To help you understand the content of this article as soon as possible, I will first outline the content of this article as follows:

  1. The conclusion in Try... Catch is widely accepted.
  2. Try to test and analyze the real environment again.
  3. Which of the following are incorrect in the previous article?
  4. Summary

Body

Part 1

The main comments of previous articles are as follows:

  1. Try... Catch does not have performance problems
  2. Try... Catch may affect the performance.
  3. Controversial my test results
  4. The test did not consider all environments, such as preheating and network exceptions.
  5. Exception Handling should not be used as logic processing
  6. I still feel that try... catch still has a performance impact, but it is hard to say how big it will be.
  7. Doubt the concept of "enterprise-level development"

Part 2

In view of the above problems, in the spirit that there are no difficulties and difficulties to create, the author has done some tests, but considering the real environment and possible problems, the code is more or less changed. The following factors are taken into account:

  1. Throw new Exception ("Kevin made me abnormal"); this Exception throws a common Exception method. In actual development, the number of possible exception classes is very large. I have roughly estimated that there may be at least thousands of types, and you can also customize the exception classes, according to this, the number of exception classes should be infinite.
  2. Some of the exception classes can be processed for a long time, and some may be processed for a short time. Some may think that network processing exceptions may take a little longer to be processed... if catch occurs, it may take a long time to process it.
  3. If the performance loss time of a function Try... Catch is short, will the performance loss of the 1000 functions be long? For example, there are 1000 functions in the system, and each function has a try... catch, and then another method calls the 1000 functions. To solve this problem, you can put try... catch... In the for loop and like to test for 1000 times.
  4. During the test, you should consider the actual environment as much as possible.

To solve the above problems, I try to change some exception classes for testing, and then put try... catch... In the for loop for testing. The test results are as follows:

  1. When try... catch is not used, the exception does not occur, which is equivalent to the time when try... catch is used.
  2. The time of try... catch... = from the execution of the function to the time when an exception occurs + the time when the exception is caught + the time when the exception is processed. Exception capture usually takes a very short time. If it is a single time, it can be ignored and will not cause performance bottlenecks.
  3. If only exception capture is performed, but no exception processing is performed, the time for 1000 exceptions in a loop is about 391.9 times that of try... catch.
  4. Because the exception handling time is composed of multiple parts, because the capture time of different exceptions may be different, and the exception handling time may be different, this will lead to a difference between the final time and the result of my test.

Before proceeding to the following analysis, I also ask you to seriously consider two questions:

  1. What is the performance problem?
  2. What is a performance bottleneck?

Part 3

Correct the following errors in the previous article:

  1. Try... catch... may cause some performance loss, but it is not higher than try... catch.
  2. Database Operations are faster than transactions.

Concerning the problem that database operations use transactions faster than transactions are not used, two points should be taken into account:

  1. If it is operated by one person, the use of transactions is faster than the use of transactions.
  2. If it is a multi-person operation, the use of transactions is not necessarily fast, the principle is very simple, the use of transactions, is to use the lock for concurrency control, if blindly think that the use of transactions fast, misuse of transactions may cause serious performance problems. When multiple users perform concurrent operations, all of them are locked by one person. One by one can be imagined, it is very likely that the performance bottleneck will be caused by misuse of transactions. I did not consider the second point before, but fortunately, I have never abused the transaction.

Part 4

Summary
:

  1. Try... Catch... will consume a certain amount of performance, but will not cause performance bottlenecks.
  2. Try... catch is recommended.
  3. Consider possible exceptions and handle them as much as possible, so as to minimize or avoid exceptions.
  4. Do not abuse database transactions to improve performance, which may cause performance problems or performance bottlenecks for concurrent access.
  5. Do not use try... catch for process processing.
  6. If possible, write the loop in try... catch instead of putting try... catch inside the loop.
  7. If it is try... catch contains try... catch, exception handling mechanism is from the internal try... catch... for external objects, capture and process them internally.
  8. About testing. Although the test still cannot completely achieve the real environment, the real environment is actually complicated and difficult to fully balance, but at least for the current test, the author believes that, I still achieve what I want.

What is enterprise-level development? I just have a vague concept. I searched for a paragraph from Google and shared it with you:

Enterprise-level development mainly targets enterprise-level applications.
So what is an enterprise-level application?
Enterprise Applications refer to solutions and Applications created and deployed for commercial organizations and large enterprises. These large-scale enterprise applications have a complex structure and involve a large number of external resources, intensive transactions, a large amount of data, a large number of users, and have strong security considerations.
Contemporary Enterprise applications cannot be independent systems. In enterprises, multiple enterprise-level applications that are connected to each other and interact with each other through different integration levels are generally deployed. At the same time, these applications may be connected to related applications of other enterprises, this constitutes a complex distributed enterprise application cluster that spans the Intranet and Internet.
In addition, as an enterprise-level application, it must not only have powerful functions, but also be able to meet changes in future business needs, easy to upgrade and maintain.

In fact, you may have a rough understanding of enterprise-level development. Although the concept has been given, it is still difficult to understand what enterprise-level development is. Some may also ask you why the concept is so hard to understand? In fact, the author believes that a question can be deeply understood only from multiple aspects. For example, when you ask about idealism, in fact, idealism is defined for materialism. If you do not understand idealism, it is difficult to distinguish materialism.

Just like what category of enterprise applications are based on? Is there personal development ......?

Recently, many new words have become popular in the blog Park: "auspicious style" and "auspicious style water Stickers". But what is the auspicious style and what conditions are met? What conditions are met?

In fact, these are all very subjective concepts. Since they are subjective, there is no need to go further.

 

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.