Powerful tcpserver pressure test tool source code (with methods and tools to break the connection limit)

Source: Internet
Author: User
Tags unpack

Powerful tcpserver pressure test tool source code (with methods and tools to break the connection limit)

Key words: IOCP tcpserver tcpclient Complete port server reach 60,000 connection break-through connection limit pressure test tool plug lock non-blocking lock unlocked free concurrent queue concurrent Expandable ring queue

First of all thanks to the action and the spirit of my support to the colleagues, in the past days, making my IOCP research into a new field. This article and accessories hope to give more people help, limited to commercial and other reasons, in addition to the original version 0.85 open source, a higher version of the inconvenience of open source, only a brief description of some technical points, please understand. But the attachment of the pressure tool source code, still can give a lot of help, such as encapsulation, unpack, deal with sticky packets, and the same pressure tool can also help developers test the performance of the server, and this help is not only general help. (Other IOCP methods are introduced online, not much here.) )

First, TCPServer

1. Structure and process

A, the guard thread is responsible for responding to an event when the post is low and posting the accept request, dealing with the null connection and the heartbeat timeout

B, the worker is responsible for processing the read-write and read-write errors, and post to the processing thread

C, due to the work of processing data and file and database read and write operations may cause communication "card" phenomenon, so increased processing threads, through the completion of queues and thread pool, accept work threads posted events, processing threads through the callback function to pass IO operation results to the application layer, The application layer can handle the data in the callback function completely, which realizes the 0 copy function and ensures the data to be processed in order.

2. Operation Information

To better test the module, developers can refer to the screenshot of the information content, their own modules for testing and development work to help observe the operational situation to determine the problem.

Ii. closed work that cannot be neglected

Many people close the communication module by shutting down all connections and threads and then releasing all of the recorded memory to the end of the shutdown. In this way, while there is no memory leak, other problems may be concealed.

The correct approach is:

1. Close the Monitor

2. Close all online connections

3, Waiting for key counters (memory pool, connection pool, etc. using the counter) to zero (this step is very important, this step is definitely a problem)

4. Close all Threads

5. Free memory Resources

6. Variable Reset

Iii. The post-IOCP era

Personally, Microsoft's IOCP model is not the end of Windows socket, IOCP part of the function and efficiency is still to be improved, and Windows socket interface is still not efficient embodiment of the development of highly demanding people, especially those who have studied the Win2000 source, Have a deeper understanding. As we all know, to meet the powerful software, the efficiency will be reduced to some extent, for the efficient model to provide proprietary socket API is the key, rather than an API generic any model. Microsoft is the only one who knows how to improve existing functionality or to provide a more efficient model.

Iv. the higher realms of IOCP

Classification of locks that are synchronized to threads before entering the title: 1, blocking locks: The system provides the synchronization mechanism of the kernel State (the efficiency of the kernel switch is well known), 2., non-blocking locks: such as lockfree, such as the use of atomic operation instructions to complete the synchronization mechanism, 3, no lock: Blocking the lock, not blocking the synchronization mechanism, Indeed, there is no mechanism for locking. Network and books on the introduction of the IOCP, the common practice is to use blocking locks, breaking the traditional thinking to obtain innovation. In the past days, I have implemented the IOCP module, which is not blocking the synchronization of concurrent locks. According to the special situation of IOCP TCP server, the function of concurrent synchronization can be realized in some competitive places without the use of locks under multithreading. This module is implemented, need to IOCP TCP server data structure (mainly queues) for in-depth analysis, based on real-time, use frequency and so summed up, to determine: which need to immediately deal with, which can be deferred without affecting efficiency, which need to lock, which do not need to lock, Which need to plug the lock, which does not need to plug the lock, the need to plug the lock can be changed to the angle of the use of non blocking locks to solve.

V. Annex

1, break through the connection limit registry setting method and Tool

A more comprehensive introduction to break the connection limit.

2, the function is quite powerful the pressure test tool source code, G-tcpclient.lib (limited edition)

Help developers to learn and produce test pressure test tools, and other packages, unpack, handle sticky bags and so on. G-tcpclient.lib is a limited edition, mainly with pressure tools to facilitate the learning of pressure tools source code.

3, blocking the lock mode of the server EXE, blocking the lock mode of the pressure test tool exe

Helps test your own servers and clients. The pressure test tool can reach 60,000 connections, with instructions.

Previous version of the test run interface

16CPU Server:

8CPU Client:

Patch Again, download link (if you find bugs, please feedback, or download it again, thanks to the beta version of support):

http://download.csdn.net/source/2568402

Forget to set the 0-point download, you can re-register an ID without a download.

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.