Build a backend server: Service side (asynchronous, large concurrency)

Source: Internet
Author: User

In the blocking mode of the last article, the server's concurrency is only a few k, and the real server like Nginx, Apache, Yumeiz Easy to handle tens of thousands of concurrent completely alone, so large concurrent circumstances can not be blocked.

1W concurrency is a separate point, if the single process model can be achieved, it means at least in the server you have been very powerful.

Server development is like a qigong, can not make a big concurrency, fault-tolerant treatment, that is, you have the internal strength, how deep the internal strength.

Asynchronous mode is specially for large concurrency, Linux under the general use of Epoll to manage the event, the following began our asynchronous large concurrent server combat it.

As with blocking development, take a look at the design process first:

1. Create the event model.

2. Create a listening connection and listen.

3. Join the listener connection to the event model.

4. When there are events, determine the type of event.

5. If the event is a listener connection, then the client connection is generated and the event model is added to the client connection to receive the send.

6. If the event is connected to the client, process the corresponding IO request.

In order to make the whole picture, I use a function (a function to write a 2W concurrent server, you tried), readability may be almost, but to deal with this interview problem is more than enough.

The actual development process is as follows:

First define an event structure to cache client connections

[CPP] View plaincopyprint?
01.struct my_event_s
02.{
- int fd;
- Char recv[64];
- Char send[64];
06.
Rc_pos int;
Sd_pos int;
09.};
struct my_event_s
{
int FD;
Char recv[64];
Char send[64];

int rc_pos;
int sd_pos;
};

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.