Complete the performance optimization of ports (1)

xiaoxiao2021-03-05  27

Author: sodme article Source:

http://blog.9cbs.net/sodme

Copyright Notice: This article can be arbitrarily reprinted by the author, but when reprint, please keep the article to start the top two lines of copyright, author and information.

Where is the main advantages of the completion port? The maximum advantage of completing the port is to manage the processing efficiency when the massive connection is managed, and the efficiency of IO processing is completed by the related mechanism of the operating system kernel. Note: The advantage of completing the port is huge to manage the connection, not the huge amount of data. In this case, it is best to use the completion port: the amount of connection is huge, and the data packets sent by each connection can be smaller, usually only a few k or less than 1K bytes. Since completing the port processing is a massive connection problem, then our optimization of the completion port should also be placed on the management of massive connection. To this end, we introduce the concept of "pool". In the design of the port, "pool" is almost the principle that must be adopted. The "pool" here includes multiple aspects, divided into: thread pool, memory pool, connection pool, etc. Next, these "pool" meanings and use will be described one by one. In the later article, if possible, I will give the efficiency comparison of "pool" and "pool" in both cases, you will I found that "pool" is so cute. In large online systems, frequent creation and release of data space is quite occupied by system resources. To this end, we introduced "memory pool" on the management of data space. Everyone knows that in every WSasend and WSARECV, we have to deliver a structural variable. The creation and release of this structural variable can be used. Method 1: That is, it is created, that is, declare a new structural space every time, and WSARECV, the GET is completed after the worker thread is destroyed; mode 2: When we have a new connection, we only follow The new connection creates a new structural space, bind it with the new client socket, only destroyed with the client object when the client socket is turned off; mode three: establish a certain amount of structural space And put it in an idle queue, no matter when you perform WSasend and WSARECV, you will use a structural space from the idle queue. After use, put it back into the idle queue. It is recommended to manage these idle structural spaces in the form of a manner in the form of implementation of the efficiency and implementation of implementation. The difficulty of using the way 3 is that how many structural space created is more appropriate? This may depend on the processing efficiency of the completion port you on on your own server. If the completion of the port is relatively high, then the required queue length may be relatively small. If the completion of the port is low, then the queue length is large a little. Let's talk about "connecting pool". We know that after using a traditional Accept to receive a connection to a client, this function returns a client Socket that creates a success, that is, this function has completed the creation of the socket. Very good, Windows gives us another function that allows us to create a socket in advance before accepting the connection, making it associated with the accepted connection, this function is acceptex, in the ACCEPTEX parameters, Socket type parameters The value is a Socket that we created in advance with the socket function. When you call AcceptEx, pass this already created Socket to AcceptEx. Speaking here, the people who understand may have smiled - in this case, isn't that allowed us to create a lot of Socket waiting for Acceptex before accepting the connection? This saves the temporary creation of a SOCKET system overhead? Oh, the fact is true. In actual operation, we can create a lot of socket in advance, and then accept the client connection function using AcceptEx.

转载请注明原文地址:https://www.9cbs.com/read-35802.html

New Post(0)