Introduction to Linux server development

Source: Internet
Author: User
Tags epoll

[Preparations before development]

Before developing a Linux server, you must have a clear understanding of the issues that need to be considered for the developed objects.
For example:
Functional Architecture: module architecture for providing services
Stability: server core output rate and Memory leakage
Performance: Speed and correctness of requests and responses
Load Capacity: Maximum number and frequency of simultaneous access

Based on the environment and application of different server objects, the corresponding methods for server development are quite different. For example, for a server (such as an HTTP server) with a short but frequent client connection time,
In the optional server structure, the pre-derived/thread structure is more efficient than the parallel structure.

In short, you must perform a complete server development requirement analysis before developing the server. Otherwise, once your server is developed, the efficiency or other things cannot satisfy your customers, it is very likely to fail!

[The server makes me understand this situation]

The server generally runs in the background and communicates with the client through requests and responses.
Taking epoll as an example, a server program developed by epoll waits for requests from 1 million of client users, polling to check whether there are requests from the client at a certain time point, and queuing to process requests in sequence, and return the result
Client application.
It involves several technical issues:
First, whether the priority of access from the client to the epoll polling queue needs to be controlled. For example, if user a is our VIP platinum user, I will always process the request sent by user a first, otherwise the platinum user will be angry.
Second, the request processing speed is greatly optimized, which is the core service designed by the server.
Third, if the client requests such a thing: I need to check all the information of an enterprise in the past one hundred years, then I think this information is very large, that is, how to transmit big data files quickly
Send these results from the server to the client. The faster the bandwidth is, the better! There will be a lot of measures here, of course, you can pack it into a package and directly throw it, but this is stupid, like a snail carrying
The heavy shell is moving, and the user can wait for so long. There are many smart practices, depending on your actual needs, such as compression, batch processing, and so on.
In fact, the entire development of the server, every detail determines the success or failure of your server. After developing a Linux server project, I personally decided that an important factor that makes your server powerful is --
-- You do not want to give up any factors that can be quite high-performance, even if it is 0.01ms or less than 1bt data!

[Popular server models]

1 PPC/TPC Model

These two models share the same idea, that is, to let every incoming connection do things on its own, so don't bother me any more. Only PPC opens a process for it, while TPC opens a thread. But don't bother me. I have a price,
It requires time and space. after too many connections, the overhead of switching so many processes/threads will come up. Therefore, the maximum number of connections acceptable to such models will not be high, it is usually about several hundred.

2 select model

2.1. maximum concurrency limit, because the FD (file descriptor) opened by a process is limited by fd_setsize. The default value is 1024/2048, therefore, the maximum concurrency of the select model is limited accordingly.
Modify fd_setsize by yourself? Although the idea is good, let's take a look at the following...

2.2. Efficiency problem: each select call will linearly scan all FD sets, which will result in a linear decline in efficiency. The consequence of increasing the fd_setsize is that everyone is coming slowly. What? All timeout ??!!

2.3. How can the kernel notify the user of the FD message when copying the kernel/user space memory? On this issue, select adopts the memory copy method.

3 poll Model

Basically, the efficiency is the same as that of select. The two and three disadvantages of select are not modified.

4 epoll Model

I criticized other models one by one. Let's take a look at epoll's improvements. In fact, the disadvantages of select are the advantages of epoll.

3.1. epoll does not have the maximum number of concurrent connections. The maximum number is the maximum number of files that can be opened. This number is generally greater than 2048. Generally, this number has a great relationship with the system memory,
You can view the specific number in CAT/proc/sys/fs/file-max.

3.2. the biggest advantage of epoll is that epoll only manages your "active" connections, regardless of the total number of connections. Therefore, in the actual network environment, epoll is much more efficient than select and poll.

3.3. memory copy, epoll uses "Shared Memory" at this point, and this memory copy is also omitted.

And so on.

Before developing your server, you should properly select the Server Model Based on your business needs and actual conditions. This is of great significance for the functional efficiency of this server.

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.