In the trend of global economic integration, enterprises have established more and more websites, operators have provided more and more server rental services, and there are also Huawei virtual machines on the cloud. No matter what kind of server, the performance of the server cannot be ignored. In order to maximize benefits, improve server performance, and maximize the use of The server This is the demand of many enterprises. It can be seen that optimizing server performance is a very important and necessary work.
Micronet believes that it is very simple to improve the server performance, but it is difficult to see the real effect. Before optimization, we should first find out what the specific business requirements of the server are, and optimize them according to these requirements, so the main points are as follows:
1. Use of memory database
Memory database is actually a database that puts data on memory for direct operation. Compared with disk, the data read and write speed of memory is several orders of magnitude faster. Saving data in memory can greatly improve the performance of applications. The memory database abandons the traditional disk data management mode, redesigns the system structure based on the storage of all data in the memory, and makes corresponding improvements in data cache, fast algorithm, parallel operation, etc., making the data processing speed much higher than traditional database.
But the security problem can be said to be the biggest hard injury to the memory database. Because the storage itself has the natural defect of power loss, when we use the storage database, we usually take some protection mechanisms in advance to protect the data in the storage, such as backup, log recording, hot backup or cluster, synchronization with the disk database, and so on. Although some data is not very important, if you want to respond quickly to users' requests, you can consider using an in memory database for storage, and regularly store the data on disk.
2. Use of RDD
Spark can be used to accelerate data processing in applications related to big data cloud computing. The core of Spark is RDD, which is the original source of a paper "Resilient Distributed Datasets: Foundation of AFault Tarrant Analysis Framework" published by Berkeley Lab.
Existing data stream systems cannot effectively deal with two applications: one is the iterative algorithm that is prevalent in the field of graphic applications and machine learning, and the other is interactive data mining tools. In either case, saving data in memory can greatly improve performance.
3. Cache increase
Many web applications have a large amount of static content, most of which are small files and can be read frequently. Apache and nginx are used as "web servers". When the amount of web access is not large, these two http servers can be said to be very fast and efficient. If the load is large, we can build a cache server on the front end to cache the static resource files on the server to the operating system memory for direct reading, because reading directly from memory is faster than reading from hard disk. This actually increases the cost of memory to reduce the time required to access the disk.
4. Use of SSD
In addition to optimizing memory, you can also optimize the disk side. Compared with the traditional mechanical hard disk, the solid state disk has the advantages of fast reading and writing speed, light weight, low energy consumption, small size and so on. However, the price of SSDs is higher than that of traditional mechanical hard disks. If possible, SSDs can be used to replace mechanical hard disks.
5. Database optimization
Most server requests end up in the database, and as the amount of data increases, the speed of accessing the database will become slower. In order to improve the request processing speed, the original single table must be cut. The current mainstream Linux server uses MySQL as the database. If we use MySQL to store a separate data table, the query speed will be slower. Partitioning the database based on appropriate business rules can effectively improve the access speed of the database and the overall performance of the server. In addition, for business query requests, indexes can be set according to relevant requirements when creating tables to improve query speed.
6. Select the appropriate IO mode
Input and output models are divided into:
(1) Blocking I/O model: I/O is always blocked before the data arrives, and returns when it arrives. Usually recvfrom, which is blocked by default.
(2) Non blocking I/O model: In contrast to blocking, I/O returns immediately as long as it does not return. The current thread is not blocked.
IO reuse mode: part of self learning. Multiplexing refers to combining multiple signals into one line for processing, just like multiple pipes are combined into one, while multiple signals are the opposite.
IO reuse models are mainly select, poll, epoll; For an IO port, it is called twice and returned twice, which has no advantage over blocking IO; The key is to monitor multiple IO ports at the same time; This function also blocks processes, but unlike blocking I/O, it can block multiple I/O operations at the same time. The I/O function of multiple read operations and multiple write operations is detected at the same time. The I/O operation function will not be called until there is readable or writable data.
Signal lamp drive: first turn on the signal lamp drive function of the kit interface, and then call the signal lamp control function through the system. When preparing to read the datagram, a SIGIO signal will be generated for this process. Then call recvfrom to read the datagram in the signal processing program and notify the well that the main circulation data is ready for processing. You can also notify the main loop to read the datagram.
An asynchronous IO model: tell the kernel to start an operation, and notify the kernel after the entire operation is completed (including copying the kernel data to the user's own buffer). This does not mean that a certain model must be used. In all cases, epoll will not perform better than select. It is still combined with business requirements when making choices.
7. Use of multi-core processing strategy
The machine configuration of mainstream running servers are multi-core CPUs. When designing servers, we can make full use of multi-core features and adopt a multi process or multi-threaded framework. The selection of multithreading or multi process can be made according to the actual needs and in combination with their respective advantages and disadvantages. When dealing with multithreading, especially when using thread pools, you can set appropriate thread pools by testing the performance of different thread pool servers.
8. Distributed deployment tool
When a stand-alone server cannot find an appropriate optimization point, you can improve the response speed of the server through distributed deployment. Excellent server developers will provide some solutions for server expansion and disaster recovery. It is better for individual servers to be simple in design, so that later expansion will be convenient.
The server rental, rapid deployment, multiple line options, support for partitioned dedicated lines, and T-level bandwidth of the micro network can provide better IDC services for various customers. Micronet is an IDC service provider focusing on server rental and hosting. With more than 10 years of industry experience, it is safe, stable, reliable and reassuring. It is a leading enterprise in the domestic IDC industry. It helps thousands of enterprises to achieve network informatization, 7 * 24 hours of manual service, after-sales care free, and has a good reputation.