C # multithreading and high concurrency

Source: Internet
Author: User

    • In any TCP Server implementation, there must be an accept Socket Loop that receives a CONNECT request from the client to establish a TCP Connection.
    • In any TCP Server implementation, there must be a Read Socket Loop that receives the client Write data.

If the Accept loop is blocked, it will result in the inability to quickly establish a connection, and the service-side Pending Backlog, causing the client side to receive a connect Timeout exception. If the Read loop is blocked, it will obviously lead to the inability to receive data from the client side in time, resulting in a client-side send Buffer full and no longer able to send data.

From the implementation details point of view, the location that can cause service blocking may be:

    1. Accept to the new Socket, build a new Connection need to allocate various resources, allocation of resources is slow;
    2. Accept to the new Socket, did not trigger the next time to accept;
    3. Read to the new Buffer, determine the length of the Payload message, the decision process is long;
    4. Read to the new buffer, found that the Payload has not been fully received, continue to Read, "may" cause a Buffer Copy;
    5. Payload received, the de-serialization turned into a recognizable Protocol Message, deserialization slow;
    6. The business Module handles the corresponding Protocol Message, and the processing process is slow;

1-2 involves the process of establishing the Accept process and the Connection, 3-4 involves the processing of receivebuffer, and 5-6 involves the implementation of the application logic side.

The famous Netty network library in Java, starting with version 4.0, has made a fresh attempt at the buffer section, using a design called BYTEBUF, which implements buffer Zero copy to reduce the performance loss and GC pressure caused by the buffer copy under high concurrency conditions. Dotnetty,orleans, Helios and other projects are trying to implement similar BYTEBUF implementations in C #.

1 individual tests are continuously available when a new client connects to the server:

Test method: Write a client to create software, call the timer, every few seconds to create a new client to the server between the connection, test open more than one client to create software

Asynchronous Programming Mode Leafsoft software writes a server on millions of available connection states, only if the connection has no other data interaction, 2 million

The number of connections to a certain extent, at this time the server blocked, unable to allocate new resources to the next client, the equivalent of the server stopped listening, the client software will have an exception, the exception location in the client Connection server method, the exception is as follows:

C # multithreading and high concurrency

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.