Muduo Network Programming Example (vi) limit the maximum number of concurrent connections to a server

Source: Internet
Author: User

This article describes how to limit the number of concurrent connections to a server with echoserver that are familiar to you.

The code for this article is shown in http://code.google.com/p/muduo/source/browse/trunk/examples/maxconnection/

The sixth article in the "Muduo Network programming Example series" was originally "Pingpong program for testing the bandwidth of two machines", and the Pingpong protocol program is in "Muduo and boost ASIO throughput comparisons" and "Muduo and Libevent2 swallowing Spit Volume Contrast "two articles are introduced, so I write another one that has a little meaning."

The "Concurrent connections" in this article refers to the number of client connections that a server program can support at the same time, the connection is initiated by the client, and the service side passively accepts (accept) connections. (If you want to limit the connections that the application initiates, the problem is much simpler, after all, the initiative and the decision are in the program itself.) )

Why do you want to limit the number of concurrent connections?

On the one hand, we do not want the service program to overload, on the other hand, because file descriptor is a scarce resource, if the file descriptor exhaustion, it is tricky (and "malloc failure/new () throw std::bad_alloc" almost the same tricky).

In the article "the Engineering development method of distributed Systems", I talked about the Libev author's proposal for a response to "accept () the file descriptor run out" approach.

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.