Discussion on Linux server development

Source: Internet
Author: User
Tags epoll

[Pre-development preparation]

Before developing a Linux server, you must have a clear understanding of the issues that need to be considered for the objects being developed
Like what:
Functional Architecture: Modular architecture for service delivery
Stability: Server Core rate, memory leak
Performance: speed and correctness of requests and returns
Load capacity: Maximum number and frequency of simultaneous access

Depending on the environment and application of different server objects, the corresponding means of server development is far apart. For example, in the case of a server with a shorter client connection time but more frequent (for example, an HTTP server),
In an optional server structure, the pre-derived/threading structure is more efficient than the concurrency structure

In short, before the development of the server, you must perform a full server development requirements analysis, or once your server development is completed because of efficiency or some other thing can not meet your customer, then it is likely to fail!

[The server let me understand this matter]

The server typically runs in the background, interacting with the client by requesting and returning two ways to communicate.
Take Epoll as an example, a server program developed by Epoll, waiting for 1 million of the client user's request, polling to see if there is a request from the client at some point, queued to process the sent request, and return the result to
Client applications.
Several technical issues are involved:
First, the priority of client access into the Epoll polling queue needs to be controlled. For example, A is our VIP platinum user, then, I always first deal with a request, otherwise the platinum user to be angry.
Second, it is extremely possible to optimize the speed of processing requests, which is the core business of server design.
Third, if the client requests such a thing: I need to see the 100 years of a business all the information, then I think that the amount is very large, that is, now very popular big data large file transfer problem, how to quickly
Pass these results from the server to the client, and the faster the bandwidth allows, the better! There will be a lot of treatment here, of course you can throw it into a bag directly, but it's foolish to like a snail carrying a
Heavy shell in the move, the user can not wait so long, the smart way of course a lot, according to your actual needs, for example, you can compress, you can batch, and so on.
And so on, in fact the entire development of the server, each of the details determine the success or failure of your server. After developing a project for a Linux server, I personally decided that one of the important factors that made your server powerful was--
--You don't want to give up any one of those high performance factors, even if it's fast 0.01ms or less 1BT of data!

[Popular server model]

1 PPC/TPC Model

These two models are similar in thinking, that is, let each of the incoming connections on their own work, do not bother me. Just PPC is for it to open a process, and TPC opened a thread. But don't bother me, there's a price.
It takes time and space Ah, after more connections, so many process/thread switching, this overhead comes up, so this kind of model can accept the maximum number of connections are not high, generally around hundreds of.

2 Select model

2.1. Maximum concurrency limit, because the FD (file descriptor) opened by a process is limited by the Fd_setsize setting and the default value is 1024/2048, so the maximum number of concurrent Select models is limited.
Change this fd_setsize yourself? Although the idea is good, let's look at the following ...

2.2. Efficiency issues, select each call will be linear scan all of the FD set, so efficiency will appear linear decline, the result of fd_setsize change is, everybody slowly, what? All over the time??!!

2.3. Kernel/user space memory copy problem, how to let the kernel to notify the FD message to user space? On this issue, select takes a memory copy method.

3 Poll Model

Basically the efficiency and the select are the same, and the select disadvantage of 2 and 3 does not get rid of it.

4 Epoll Model

The other models to criticize one by one, and then look at the improvement of epoll, in fact, the shortcomings of the select in turn that is epoll advantage.

3.1. Epoll There is no maximum concurrent connection limit, the maximum number of open files, this number is generally far greater than 2048, generally speaking, this number and system memory relationship is very large,
The exact number can be cat/proc/sys/fs/file-max.

3.2. Efficiency improvement, the biggest advantage of Epoll is that it is just your "active" connection, but not the total number of connections, so in the actual network environment, epoll efficiency will be much higher than the select and poll.

3.3. Memory copy, Epoll use "Shared memory" on this point, this memory copy is also omitted.

Wait a minute.

Before you develop your server, you should choose the server model according to your business needs and actual situation, which is of great significance to the function efficiency of this server.

Discussion on Linux server development

Related Article

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.