. The brief performance of several socket models under NET platform for reference

Source: Internet
Author: User
Tags net net thread reference socket thread client
Reference | performance

This content has also been discussed many times in the cnblogs, these two days probably saw some material, saw some simple performance index to come out and discuss with everybody.

Socket + Threads/threadpool

Approximate performance: less than 1500 connections

Implementation: accept a socket, to a thread to manage, more stupid, but also more effective, because it is synchronized way, control is very convenient. The advanced point is to a thread pool to manage, the thread pool is automatically hosted by the system, eliminating the overhead thread time. General small projects, with this completely enough, the development is also simple. Note, however, that if several sockets are consuming threads in the thread pool for a long time, and there are more connections, it is easy to say that you do not have enough threads to use. Oh, let the socket less do something, take less time, change a fast CPU is a good way. In addition, if there are some better third-party thread pool components, you can also choose to use, such as Smartthreadpool.

Socket + Select

Approximate performance: Performance drops after 1500 connections

Implementation: Select is a very common model. is to poll one or more sockets in the blocking function, the socket to be processed is placed in a IList, when the select poll is finished, then we handle the socket in the IList ourselves. You can look at MSDN for specific uses. The efficiency of a select cannot be said to be high, because when there are more sockets to be processed in the queue, processing the last few sockets is equivalent to traversing all the preceding sockets, which is very uneconomical.

Socket + Asynchronous

Approximate performance: About 7,500 client connections

Implementation: Beginxxxx,endxxxx, familiar with the bar. The asynchronous socket, in the final analysis, is still a thread pooling technique that handles asynchronous IO with a thread pool. This leads to another question. NET's thread pool is the use of what to implement the way, previously seen someone say. NET thread pool is implemented using the completion port, I do not know if this is correct, from the information found there is no way to confirm (I hope that some friends can tell me). Asynchronous sockets are a lot more complex than synchronization for the process flow of a program, and the control of asynchronous callback functions is not as intuitive as the synchronization approach. But one thing I think should be noted is that the callback function should be light, should not handle too many transactions, the transfer of data processing, should be given to other threads to deal with.

IOCP (completion port)

Approximate performance: About 20000~50000 client connections

Implementation: now. NET there are some pseudo IOCP, we can go to search, have not seen the open up with these pseudo IOCP to achieve the socket example. I said 20000~50000 a client connection, refers to the development of the situation in C + +, such cases, the need to use the basic technology also includes memory pool, query algorithm and so on.

Pseudo-IOCP can achieve how many maximum connections, there is no information to check, if a friend know, you can discuss. In addition, many of the data mentioned above are extracted from some data, I have not tried it, just take out and discuss with you. I think, a high-performance server-side program, the technology may need more than just what the model, there are many details to be noted, such as memory processing, what algorithm to use, of course, this is only the cost of software, hardware must also be input.



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.