Web performance optimization is divided into two aspects: server-side and browser-side.
One, browser-side, about the browser-side optimization, in a number of ways
1, compressed source and pictures
JavaScript File source code can be used to confuse compression, CSS file source code for normal compression, JPG images can be compressed according to the specific quality of 50% to 70%,png can use some open source compression software to compress, such as 24 colors into 8 colors, remove some PNG format information.
2. Select the appropriate image format
If you have a large number of picture colors, use JPG format, if the image color number is used in PNG format, if you can determine the browser support WEBP through the server side, then use the WEBP format and SVG format.
3. Merging static resources
include CSS, JavaScript, and small images to reduce HTTP requests. A large portion of user access will benefit most from this article
6. Extended Static resource cache time
In this way, visitors who visit the site frequently will be able to access it more quickly. However, this is done by modifying the file name to ensure that the user pulls up the latest content when the resource is updated.
7, put the CSS on the page header, put JavaScript at the bottom of the page
This does not block page rendering, which makes the page appear blank for a long time.
Single-Case mode
Summarize
There are two issues to note:
1. If a singleton is loaded by a different class loader, there may be instances of multiple singleton classes. This is assumed not to be remote access, for example, some servlet containers use a completely different class loader for each servlet , so that if there are two servlets access a singleton class, and they will have their own instances.
2. if the Singleton implements the java.io.Serializable Interface, then instances of this class may be serialized and restored. In any case, if you serialize an object of a singleton class and then restore multiple objects, you will have multiple instances of the Singleton class.
The fix for the first problem is:
High Concurrency website Solution
2, Image server separation
as you know, for Web Server, whether it is Apache,IIS or other containers, the picture is the most resource-intensive, so we need to separate the picture and page, This is basically a large web site will adopt the strategy, they have independent, and even many of the picture server. Such architectures can reduce the pressure on the server system that provides page access requests and ensure that the system does not crash due to picture problems.
in the application server and picture server, can be different configuration optimization, such as Apache in the configuration of ContentType can be as little as possible to support, as little as possible LoadModuleto ensure higher system consumption and execution efficiency.
3, database cluster, library table hash
Large Web sites have complex applications, which must use databases, and in the face of a large number of accesses, the bottleneck of the database can soon be revealed, when a database will soon be unable to meet the application, so we need to use the database cluster or library table hash.
in the context of database clustering, many databases have their own solutions, Oracle , Sybase and so on have a very good solution, the common MySQL provided by Master/slave is similar to the scheme, you use what kind of DB, Just refer to the corresponding solution to implement it.
The database cluster mentioned above will be used in terms of architecture, cost, and extensibility DB type limits, we need to consider improving the system architecture from an application perspective, and the library table hash is a common and most effective solution.
we install the business and application in the application or function modules to separate the database, different modules corresponding to different databases or tables, and then according to a certain policy on a page or function of a smaller database hash, such as the user table, according to the user The ID is hashed so that the performance of the system can be improved at a low cost and has good scalability.
Sohu Forum is the use of such a framework, the Forum users, settings, posts and other information database separation, and then to the post, the user according to the plate and ID hash database and table, The result is a simple configuration in the configuration file that allows the system to add a low-cost database at any time to complement system performance.
4. Cache
The word cache has been touched by technology, and caches are used in many places. Caching in the Web site architecture and Web development is also very important. Here we first describe the two most basic caches. The advanced and distributed caches are described later.
schema-side caching, for Apache is familiar with the people can know that Apache provides its own cache module, you can also use the additional Squid module for caching, Both of these methods can effectively improve Apache 's access response capability.
Web site program development cache,Linuxprovided on theMemory Cacheis a common cache interface that can be used inWebused in development, such as withJavawhen you develop it, you can callMemoryCacheSome large communities use the same architecture for caching and sharing some data. In addition, when usingWeblanguage development, all kinds of languages have their own cache modules and methods,PHPhave aPearof theCachemodules,Javathat's more.. NETnot very familiar, I believe there must be.
5. Mirror
mirroring is often used by large web sites to improve performance and data security, mirroring technology can address the different network access providers and regions brought by the user access speed differences, such as The difference between chinanet and edunet has prompted many websites to build mirror sites within the education network, with data scheduled to be updated or updated in real time. In terms of mirror detail technology, this is not too deep, there are many professional ready-made solution architectures and products to choose from. There are also inexpensive ways to implement software, such as The tools of Rsync on Linux .
6. Load Balancing
Load balancing will be a high-end solution for large web sites that address high-load access and a large number of concurrent requests.
Load balancing technology has developed for many years, there are many professional service providers and products can be selected, I personally contacted a number of solutions, including two architecture can give you a reference.
(1), hardware four layer exchange
The fourth layer Exchange uses the header information of the third layer and fourth layer packets, according to the application interval to identify the business flow, the entire interval segment of the business flow distribution to the appropriate application server for processing.
The fourth level switching function is like a virtualIp, point to the physical server. It transmits a variety of business compliance protocols that haveHTTP,FTP,NFS,Telnetor other agreements. These services require complex load balancing on the basis of physical serversalgorithm. In theIpWorld, Business type by terminalTCPorUDPport address, the application interval in the fourth layer is determined by the source and terminalIPaddress,TCPand theUDPThe port is determined together.
in the hardware four-layer switching product area, there are some well-known products to choose from, such as Alteon,F5 and so on, these products are expensive, but value for money, can provide very good performance and very flexible management capabilities. "Yahoo China " at the beginning of the first server, only used three or four sets of Alteon it's done.
(2) , software four-layer switching
Once you know the rationale behind the hardware four-layer switch, The four-layer exchange of software implemented by the OSI model came into being, with the same principle as the solution, but with a slightly worse performance. But to meet a certain amount of pressure or comfortable, some people say that the software implementation is actually more flexible, the ability to handle the full look at your configuration of the familiar ability.
software Four-layer switching we can use Common lvs on Linux to solve,LVs is linux Virtual Server, he provides based on the heartbeat line Heartbeat 's real-time disaster response solutions improve system robustness while providing flexible virtual VIP configuration and management capabilities to meet a wide range of application needs This is essential for distributed systems.
A typical strategy for using load balancing is to build squid clusters on the basis of software or hardware four-layer switching , which is adopted on many large web sites including search engines , and the architecture is low-cost , high performance and strong expansion, it is easy to add or subtract nodes to the architecture at any time.
for large Web sites, each of the previously mentioned methods may be used at the same time, here is relatively simple introduction, the implementation of a lot of details in the process need to be familiar with and experience. Sometimes a very small squid parameter or Apache parameter settings, the impact on the system performance will be very large
Stored Procedures
So when can I use storage? Is there no need for small projects where the volume of data is not very large and the business process is not very complex?
Wrong. Stored procedures are not just for large projects, but for small and medium-sized projects, it is also necessary to use stored procedures. Its power and advantages are mainly reflected in:
1. The stored procedure is compiled only at creation time, and each subsequent execution of the stored procedure does not need to be recompiled, while the general SQL statements are compiled once per execution, so using stored procedures can increase the speed of the database execution.
2. When complex operations are performed on a database, such as when multiple tables are update,insert,query,delete, this complex operation can be encapsulated with stored procedures and used in conjunction with the transactional processing provided by the database. These operations, if done with a program, become a single SQL statement that may be connected to the database multiple times. Instead of storage, you only need to connect to the database once.
3. Stored procedures can be reused to reduce the workload of database developers.
4. High security, can be set only a certain user has the right to use the specified stored procedure.
Web performance optimization High concurrency Web site resolution single case