Performance optimization for back-end systems (II.)

Source: Internet
Author: User
Tags dba log hazelcast

Today, what kind of code is bad code, how to find out these bad code.

Quite a few apes in spit-rotten code. But what we're talking about today is not bad code, it just needs to change a little bit, get rid of its bad, he's still good code. And bad code, only to write back, it will make you feel relaxed, pressure release, and before you write you have to spend 90% of the time to read it. So I say get rid of bad code, because only bad code can be changed, and bad code is used to see. I am glad that I am in the team's code control ability is good, very few bad code. But why would there be bad code? Bad code is not innate, he was just on the line may also be good code, slowly become bad, it doesn't matter, we find it out.

Find the bad code, we have two stages

The first phase is that our application cannot monitor its own performance, and can only provide SQL with poor performance and high execution frequency through DB. The DBA will show you the SQL that is consuming too much resources, and these SQL can roughly let you find out which feature is more specific to which method. Bo Master is responsible for the project using the MyBatis framework (with hibernate, I can only hehe), if there is SQL, we can quickly locate the specific method, and then further look at the code, understanding the business, and modify the impact of performance code. But this approach to SQL positioning is not comprehensive, only to find a single method with performance problem SQL, the performance of SQL itself is in the bar, and our approach often contains more than one SQL. such as: 2 each only need 250ms of SQL, in the same method, that will consume 500ms, this situation, SQL performance is not a big problem, through DB is difficult to find out. A few single SQL with performance problems (more queries) and sql,dba that perform more frequently are easier to provide. And this problem of SQL performance, optimization means very limited, such as adding some conditions or hint way to enforce the index, DBA execution plan to reduce the consumption of SQL, more complex query SQL split into a single table query, increase the field of the associated properties of the redundancy, The dictionary values in the database are put directly into memory, minimizing the association queries between the large tables ... Detailed optimization means the use of the scene, I will be detailed in the next section.

The second phase is to build self monitoring within the application, and we use spring's AOP to implement a simple and efficient monitoring function that can be cut into layers, such as Service,manager,dao, and so on, The amount of time consumed by the methods in each layer is put into memory, and when the method call is over, it is useful and simple and elegant to have the time for the methods executed by each call to be printed in a log if it exceeds the preset execution time, such as the 500ms alert line. Basic to meet the application of the performance monitoring of the data required. But it is also flawed, if the alarm line set too low, the consumption of Io is still a little serious. In general, the performance optimization of the early warning line we set the time to 500ms. This way, a method that executes longer than 500ms is collected in the log.

There is also a very obvious benefit in using internal self-monitoring, when the average response time of the system suddenly slows down, and we open the log to quickly locate what exactly is the problem. A few months ago in our application, the use of a cache component called Hazelcast, the JVM without any indication of oom, and by our operational system automatically restart, we open this log, positioned to be hazelcast operation timeout, and soon, we have the next move.

With the performance-monitored log files, we have the underlying data, which is used to analyze the worst performing top10 and Top10 over the 500ms execution times per day. Get data similar to the following

Number of requests, average response time, request method name

238 1346.82 Bserviceimpl.createa

184 6750.17 Aserviceimpl.querya

159 2620.29 Cserviceimpl.getc

This simple and effective, can have so many benefits of small things, in the end is how to achieve?

The format of the file It records is probably:

2014-05-04 23:12:00 [550,100%,0] A.createa ()

----------------------------[10,50%,5] B.queryb ()

---------------------------------[5,50%,10] C.QUERYC ()

----------------------------[20,100%,30] C.queryd ();

The things in front are very well understood, what the square brackets mean is the total time that the first digit method executes, the second percentage number, the method execution takes up the total amount of time taken by the method invocation, and the third number means the period, and how long it takes to execute to which method, starting at 0.

This way of recording allows us to quickly find the corresponding bad code place.

In short, only the application of their own understanding, in order to accurately find the bad code. Found them, performance optimization is half the success.

has not implemented its own application of internal monitoring, hurriedly write a, so that bad code can not be hidden.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

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.