During the memcpy operation, although it is a memory operation, it still consumes a little CPU. Today we tested the efficiency of executing memcpy in a single thread. The result is for configuring the work thread in TCP epoll.
The quantity has guiding significance. The following example shows how to execute memcpy quickly based on 8 K memory. One thread can copy 500 m in about 1 second. If the server bandwidth or network card reach the upper limit of 1 GB, the network I/O work thread can be opened with two threads. Considering the message parsing loss, the three threads are sufficient to resist the maximum Hardware load.
The test result is as follows:
Intel (r) Xeon (r) CPU e5405 @ 2.00 GHz
Do memcpy speed: 12.27 MS/MB
Each threads can do memcpy 667.645 MB
1 # Include <iostream>
2 # Include <sys/time. h>
3 # Include < String . H>
4
5 Using Namespace STD;
6
7 Int Main ( Int Argc, Char * Argv [])
8 {
9 Long Len = 8192 ;
10 Int Loop = 200 ;
11 Char * P = New Char [Len];
12 Char * Q = P;
13 Struct Timeval start, end;
14 Gettimeofday (& START, null );
15 For (Int I = 0 ; I <loop; ++ I)
16 {
17 Char * P = New Char [Len];
18 * P = Char (I );
19 Memcpy (p, q, Len );
20 Delete [] P;
21 }
22 Gettimeofday (& End, null );
23 Cout < " Do memcpy speed: " <(End. TV _sec-start. TV _sec )* 1000 + Double (End. TV _usec-start. TV _usec)/(LEN * loop/ 1000 / 1000 )/Loop < " MS/MB \ n " ;
24 Cout < " Each thread can do memcpy " < Double (LEN) * loop/ 1000 / 1000 /(End. TV _sec-start. TV _sec) + Double (End. TV _usec-start. TV _usec )/ 1000 / 1000 ) < " MB \ n " ;
25
26 }