How to Improve access efficiency for Java Web projects

Source: Internet
Author: User

Generally, the efficiency bottleneck of large-scale application projects is in the database

Summarize several considerations for database efficiency optimization.

1. Avoid using the Hibernate framework

Use hibernate to insert about 50 thousand pieces of data at a time. If the ID is generated using sequence, Hibernate obtains 50 thousand sequence records from the database for 50 thousand times and constructs the corresponding object, save the data to the database for another 50 thousand times. It took me 10 minutes. The main time was not spent on inserts, but on retrieving sequence from the database for 50 thousand times, which made me quite depressed. After that, I changed the ID generation method to increase to solve the problem, but I still had to wait for that ten minutes.

 

2. Do not use a statement similar to select * From x_table during query. Use select ID and name from x_table as much as possible to avoid unnecessary data waste. For massive data, a field occupies considerable resources and query time.

 

3. When we perform a query, we usually submit a query form to the background at the front end, parse the form in the background, and then perform the query operation. When parsing forms, for convenience, we often prefer to replace some conditions that do not need to be queried with permanent conditions (such as: Select count (ID) from x_table where name like '%'), in fact, such an SQL statement is a terrible waste of resources. I tried to use select count (ID) from x_table for the same query of nearly 10 million records. It takes 11 seconds to use select count (ID) from x_table where name like '%' takes 33 seconds.

 

4. When querying massive data, try to avoid table connections (especially left and right connections). When you have to connect tables, the data volume of the connected table must not be too large, if tens of thousands of tables are connected, you can think about re-designing the database table, because the waiting time is by no means tolerable to normal users.

 

I used to do a banking analysis system with a data volume of hundreds of millions. Additional points

1. How to Create a Java object. There is a saying: as few objects as possible. Let alone tens of millions, that is, tens of thousands of users should not consider object creation. Because a few requests are sent at the same time, the system will surely be finished.
2. properly align the system design. A large amount of data operations must be separated from a small amount of data operations. A large amount of data operations are certainly not implemented by the ORM framework. It is absolutely not an Orm, because 1 requires less object creation; 2. Rational use of database resources. Id allocation is a good example.
3. Make Rational Use of database partitioning and indexing technologies.
4. Sometimes you can consider temporary tables, especially large data volumes.
5. Some people say that a large amount of data must be stored in the stored procedure. My stored procedure is not good, so JDBC is still used. Haha has very good results, so in addition to the above notes, pay attention:
1. Control the memory and let the data stream get up, instead of reading all the memory for processing, but reading and processing;
2. make proper use of memory and cache some data;
3. I admit that there are still some technical content here. It is not simple anyway. Not easy to say.

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.