Test report on performance impact (Database Version)

Source: Internet
Author: User
Introduction
Premise: the project team does not use spring for transactions Management. Projects are divided into functions by everyone,
Bo, Dao, action, and view are created by a single person. In Dao
Closed Form.

Problem: Cause transaction inconsistency. The function is made, and performance problems will be exposed sooner or later.
Test: Mainly for frequent requests from programsDatabaseTest the impact of connection on Web applications.

First, make necessary explanations, introduce the subject step by step, and start from the performance bottleneck:

Performance bottleneck

All applications have performance bottlenecks. To improve the performance of applications, We must minimize the bottlenecks. The following are common performance bottlenecks in Java programs.

After learning about these bottlenecks, we can reduce these bottlenecks to Improve the Performance of Java applications.

Database Connection PoolWorkPrinciple

Test Solution on the implementation principle of the Connection Pool:
AfterMaterialsCollection and query of the Connection Pool in Apache DBCP, there are two ways to work with the existing connection pool:
1. Database Pre-SetupConfigurationNumber of connections. After a user requests a connection, a connection is sent out, and then a connection is created in advance to maintain the number of supplies, that is, the number of connections is prepared in advance for the request. For example:
Five channels represent the maximum number of activated connections and the minimum number of idle connections. That is to say, there are always two available connections in the connection pool. The connection creation overhead is relatively large, and the existence of the connection pool can minimize the waiting time for creation.

1 o
2 O
3 *
4 *
5 *

For example, when 1 is allocated, a new connection is automatically created to prevent another request from waiting for creation. This reduces the waiting time, but the overhead of database creation is not solved. If we compare 1-5 to a car, in this case, each vehicle is used at one time. 1. The next connection after the request is sent will be replaced by 6. SoHowReuse 1 to reduce database overhead. The second method is introduced.

2. Recycle the connections after use and put them back to the pool for recycling. To do so, we must ensure 2 points.
1. Enable the connection to be effectively recycled.
2. Restrict the user to use the release action, rather than directly close the connection.

I used the basic IMPLEMENTATION OF THE basicdatasource connection pool in Apache DBCP,
The code and test results show that the working method is based on two.

Basicdatasource test case

The following showsTest Cases
Test results:

2nd groups of data:
Concurrent applications: 100 simulated connections: 6
Average running time: 2956
51 connections in total
Average running time: 3391
2. A total of 52 connections are used.
Average running time: 2616
47 connections in total
Average running time: 3377
41 connections in total
Average running time: 3673
46 connections in total
2nd groups of data were executed 5 times; Average time consumption: 3229 milliseconds
47 connections on average

3rd groups of data:
Concurrent applications: 85 simulated connections: 9
Average running time: 4830
53 connections in total
Average running time: 3247
A total of 49 connections are used
Average running time: 4116
40 connections in total
Average running time: 4070
A total of 43 connections are used.
Average running time: 4053
54 connections in total
3rd groups of data were executed 5 times; Average time consumption: 4063 milliseconds
47 connections on average

4th groups of data:
Concurrent applications: 140 simulated connections: 3
Average running time: 2076
47 connections in total
Average running time: 3104
51 connections in total
Average running time: 2048
A total of 43 connections are used.
Average running time: 2421
50 connections in total
Average running time: 2751
50 connections in total
4th groups of data were executed 5 times; Average time consumption: 2480 milliseconds
Average use of 48 connections

The results of each test may be different, but the conclusions are consistent. The data shows that the unreasonable request connection seriously affects the number of concurrent requests that the application can afford, and the response time is also affected.

Common Problems

If the transaction is not properly controlled, the following situations may occur:

Transaction (){
Process 1 ();
Process 2 ();
}

We can see that the connection is created separately in process 1 and 2, andProcess.
If an exception occurs in process 2, the operations performed in process 1 cannot be recovered.
If it can be controlled within the transaction scope, such:

Transaction (){
Connection con;
Process 1 (CON );
Process 2 (CON );
Con. Close ();
}

As a result, the database provides less than one connection, and the Transaction completion is also reflected. When the concurrency is large,
There are obvious differences in efficiency.

Solution

1. Keep as few requests as possible
If there is an update () method in Dao, an additional update (connection conn) method should be extended)
Call Update (connection conn) in a business logic transaction. Generally, update () is called ()

2. cache is used when data remains unchangedTechnology, Or some caching technologies.
For more information, seeOpen SourceProject (jive ).

Tag:Test Report database performance test report

 

Related Article

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.