This post was last edited by linux_c_py_php ProgramUnder the guidance of many friends and friends in the forum, the company's kernel Department eventually achieved 0.5 million QPS for persistent connections and 70 thousand QPS for short connections, the CPU of the test machine is 12 cores, 64 MB memory, and the test environment is a standalone lo network port. Based on the epolloneshot option of epoll, the program fully utilizes the epoll thread security feature and maximizes the connection establishment rate through an independent listening thread, the program structure of leader-follower is implemented through the thread pool and epoll, which is applicable to various business logics. In the process of program optimization, there are two major bottlenecks: 1. epoll thread security. Therefore, internal locks may cause bottlenecks for multi-threaded epoll FD sharing. By creating multiple groups of epoll FD, the bottleneck can be resolved by reducing the competition for locks and making full use of hardware performance. 2. The short connection setup capability is poor. Without Optimization of network parameters, the capability can only be set up at 30 thousand/second. After parameter optimization, the capability can be set up at 80 thousand/second. For details, referCodeReadme. The Code is as follows. The first 255 lines of small code have obvious bottlenecks:(0.15 million QPS) Server.tar.gz (1.85 kb, downloads: 89) Upload Downloads: 89 One server. c The code after solving the above two problems can support 0.5 million QPS: Lfepoll.tar.gz (2.69 kb, downloads: 106) Upload at a.m. on February 19 Downloads: 106 It's really efficient. This is the code that introduced Lua and does not support yield, because it is too difficult to change the code to a state machine, and the program itself is leader-follower, therefore, it is not necessary to provide some practical interfaces such as Asynchronous CONNECT: Lfepoll.tar.gz (4.27 kb, downloads: 33) Upload Downloads: 33 Supports Lua (an error has just been reported !) Test the Lua version performance and find that the lual_loadstring frequently calls a serious loss of performance. Therefore, the lual_loadstring is loaded only once and a reference is kept in the Registry for reuse, now the program bottleneck has been transferred to lua_pcall, and it cannot be optimized by visual testing. (modify logic before testing. change Lua to the pure echo service. Otherwise, the test stress tool may not work properly) Lfepoll.tar.gz (4.38 kb, downloads: 36) Upload Downloads: 36 Optimize lual_loadstring |