System performance optimization method

Recently, I was reading the book "Java Program Performance Optimization". The author wrote it very well. For those who have not read it, I suggest that you buy it and have a look. Since I'm just starting to watch it, I'll do a review here after reading it. Here are mainly three methods for optimizing system performance: increasing buffers, using caches, and load balancing. As for the design pattern, it will not be introduced here.
1. Buffer
The buffer is a specific memory area. The purpose of opening the buffer is to improve the performance of the system by alleviating the performance difference between the upper and lower layers of the application. For example: pour the water in the teapot (upper system) into a water bottle (lower system), the teapot can output water quickly, but the bottle mouth of the water bottle is very thin, at this time, a funnel (equivalent to a buffer) needs to be added. ), pour the water in the kettle into the funnel first, and the water in the funnel slowly flows into the water bottle. Since the teapot discharges water faster, when all the water in the teapot is poured into the funnel, it is equivalent to the completion of the operation of the upper system. , just wait for all the water in the funnel to flow into the water bottle. Just like writing the data in the memory to the hard disk, the speed of writing data from the memory is fast, while the speed of writing data to the hard disk is relatively slow, so a buffer needs to be added in the middle to write the data lines in the memory to the buffer. Then write the data in the buffer to the hard disk. After all the data in the memory is written to the buffer, the memory can perform other operations without waiting for all the data in the buffer to be written to the hard disk. In the hard disk, after all the data in the buffer is written to the hard disk, the data in the buffer is emptied. When the memory writes data to the hard disk, a buffer is used to coordinate the poor performance of the upper-level components and the lower-level components. The advantage is that the upper-layer application components do not need to wait for the lower-layer components to actually receive all the data before returning to the operation, which speeds up the processing speed of the upper-layer components, thereby improving the overall performance of the system.
2. Cache
Cache is a memory space opened up to improve system performance. Its main function is to temporarily store data processing results and provide them for next access. The cache can save some hard-won data or calculation results. When the data needs to be used again, it can be obtained from the cache at a low cost without occupying valuable system resources. If you are interested, you can learn about caching frameworks such as ehcache, oscache, and jbosscache, and I will not discuss them in depth here.
3. Load balancing
For large-scale applications, the system load may be very important. Taking a website as an example, if the number of concurrent applications is too large, a single computer cannot bear it. At this time, in order to ensure the service quality of the application, multiple computers need to be used Work together to distribute the system load as evenly as possible across computer nodes.
3.1. tomcat cluster:
use the apache server as a load distributor to transfer requests to each tomcat server to achieve load balancing. The tomcat cluster has two session sharing modes: sticky session mode and complex session mode. Sticky session mode: All sessions are evenly distributed to each tomcat node to achieve load balancing, but if a tomcat goes down, the session information on the tomcat will be lost, so it is not recommended to use the session mode. Complex session mode: It will keep all sessions consistent on all tomcat nodes. If a tomcat node is down, the session information on the tomcat node is still on other tomcat nodes, so there is no need to worry about losing client sessions. I recommend a framework dedicated to distributed caching, Terracotta. Interested students can learn about it, and I will not introduce it here.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326253434&siteId=291194637