Java web project optimization record: Optimization Test System

Source: Internet
Author: User

During stress testing, the examination system found that the button did not respond after the concurrency was high and the answer to the questions could not be written to the database. Therefore, the examination system optimized these core questions.

Database:

Select statement: Select * from TEB_VB_XZTRecord is changed to form TEB_VB_XZTRecord, which is a required column in select. It is best to use it in the tutorial video. * because unnecessary columns are queried, the efficiency is reduced.

Insert optimization: the reason for the examination business. You need to insert the queried questions into the database one by one. Before optimization: loop + insert an insert statement each time. After optimization: insert Table Name (field name) select (field name) from table name where questionID in (,,,,,,,)

This kind of optimization uses the select statement and the in keyword in the insert statement, which is equivalent to directly performing a query after the database executes the query, without repeating the java project again and again. I used to use an insert + multiple values method. I found this method works in mysql, but it does not work in oracle.


Program Design and algorithm optimization:

Algorithms are often influenced by personal ideas. For example, if you have a deep understanding of reuse, you can save the results and use them more efficiently. The same is true for programming.

Cache same data

The examination surface of a candidate must be composed of four parts: Examination Information, personal information, examination surface score distribution, and examination content. The Examination Information and examination surface score distribution are the same for each examinee, therefore, caching the same information reduces a large number of queries instead of one query.


Plan ahead and prepare in advance

When there is a large amount of concurrency, you can do the work in advance, just like asking people to eat at their own house. At the time of the meal, you must prepare the food temporarily, it's time to prepare in advance.

For the Exam System: during the exam, each examinee randomly selects a set of exam from the question bank. This method contains a large number of queries and a loop. Therefore, the performance requirement is high, and the system does not respond when the concurrency is large.

Optimization for the first time: select the exam for the examinee before the exam. When the examinee logs on, he only needs to query the answer record table. In this way, the question extraction process is prepared in advance.

Second optimization: Considering that a large number of queries are required during the first optimization, the logic of this optimization is to extract a fixed number of volumes. For example, to extract 50 sets, each set of volumes has a number, before the test, 50 sets of volumes are loaded into the memory. The examinee randomly selects a volume number and obtains the test paper from the memory based on the volume number. In this way, only one query is required, other candidates can obtain the exam from the memory to avoid a large number of queries.


Separate tasks

When you are very busy, we should push back the things that can be pushed back, and reasonably plan the resources and time. During the answer process, the process of determining objective questions is moved to the instructor's scoring logic. Because the correct answer needs to be queried, a large number of query and update operations will be performed during the answer process, removing the score, the answer is updated only.


Then there is the optimization of the String, because the examination system needs to display the questions on the interface, so you need to splice the questions in the background and display them on the front-end. At that time, the String is used, but the String is not dynamically resized. It only copies the original String and adds new content to produce a new one. Therefore, there is a lot of storage waste. After being changed to StringBuffer, the memory requirements are much lower.

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.