Obviously, this chapter is about performance optimization, so before we say performance, we have to understand the specific definition of performance, that is, how to assess whether a system performance is good or bad.
So let's talk about performance testing, then the performance of the front end, the performance of the application server, and the optimization of the storage performance.
Performance Test 1 Different people know about performance differently.
For users, they think the performance is the speed of the site response, specifically, they click the mouse, and then see the effect of the time required. For this part of the optimization, see the back end of the section
For developers, it's simple, including system latency, system throughput, concurrency, stability, and more. Of course, this part of the optimization is mainly in the application server layer.
For operations, it is the performance of infrastructure and the utilization of resources. This includes server bandwidth utilization, CPU, memory utilization, and so on.
2 Test indicators
Response time: This is a good understanding of the time it takes from making a request to getting the response data
Number of concurrent: the number of users who committed the request at the same time. For a website, we have to distinguish three concepts, the number of users of the website system, the number of users currently online, the number of concurrent users.
Throughput: The number of requests that the system processes per unit of time. However, metrics such as TPS (transactions per second) measure
Performance counters: Includes system load, number of objects and threads, memory usage, and so on. Monitoring system should monitor these indicators, one o'clock to a certain threshold on the alarm.
Here we talk about the system load: the sum of the number of processes being executed by the CPU and waiting to be executed by the CPU.
If the system load is less than the number of CPUs, the system resources are wasted, and conversely, if the system load is greater than the number of CPUs, then that means insufficient resources
The best case scenario is that the system load equals the number of CPUs
Under Linux, you can use the top command to view the system load
See also: How Linux uses the top command to view system status
3 Optimization Strategy
The first step must be performance analysis. You have to make sure that the user says the system responds slowly and that the module is dragging its hind legs. Then optimization, the overall optimization should be in three levels: Front end, application, storage.
Front-end Optimized browser optimization
Reduce HTTP requests: Merge Css,javascript, combine multiple images into one, use CSS offset when using.
Using caching: Using browser caching
Using compression
CSS on top, JavaScript on the bottom
Reduce cookie Transmission
CDN Acceleration
Put static resources closer to the user
Reverse Proxy
Put static resources in front of the application server
Application Server Tuning Cache
The cache is generally a large hash table that can be used to obtain data within O (1).
But we have to use the cache wisely, to avoid the following issues
1 Frequent modification data (in general, read and write ratios above 2:1, cache only makes sense)
2 No access to hotspots (i.e. access to data, not 2-8 laws)
4 inconsistent data (such as the seller has changed the product attributes, but the buyer is not seen in real time, if you want to enforce the same will also bring other problems)
Distributed Cache Architecture
One is that the JBoss cache represents the need to update the synchronization of the scheme, one is the memcached as the representative of the non-mutual communication scheme.
Asynchronous
The main thing is to use Message Queuing, and anything that can be done late can be done late, using Message Queuing to sharpen the peaks
Cluster
A horse does not move, it uses three horses. Very simple logic.
Code optimization
1 Multi-Threading (it is better to design the object as stateless or use a local object, use a lock when accessing the resource)
2 Resource reuse (Singleton and object pooling)
3 garbage Collection
Storage optimization does not understand
Large website Technical Architecture reading notes 3 High performance architecture