1,摘要:测试send和sendmsg的性能,影响这两个函数性能主要有发送的字节大小,增加循环次数,从100到10000000(千万)
2,基本信息
cat /proc/cpuinfo查看CPU信息,如下:
Intel(R) Xeon(R) CPU E5-2698 v3 @ 2.30GHz
cat /proc/version 查看操作系统内核版本,如下:
Linux version 3.10.0-327.el7.x86_64
cat /proc/meminfo查看内存信息,如下:
MemTotal: 131748016 kB
MemFree: 42526620 kB
MemAvailable: 60623924 kB
3,send性能测试
服务器端 : nc -lu 8888
客服端:
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <netdb.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> #include <arpa/inet.h> #include<time.h> #include <sys/times.h> #include <unistd.h> //#define BUFSIZ 1024 #define recycle 1000000 static inline uint64_t rte_rdtsc(void) { union { uint64_t tsc_64; struct { uint32_t lo_32; uint32_t hi_32; }; }tsc; asm volatile("rdtsc": "=a" (tsc.lo_32), "=d" (tsc.hi_32)); return tsc.tsc_64; } int recycleSet[]={100,500,1000,5000,10000,50000,100000,500000,1000000,5000000,10000000}; int bufsizeSet[]={128,256,512,1024,2048,3072,4096}; int main(int argc,char *argv[]) { /*if(argc<3) { printf("paramaters error! ./socet_sendmsg 1000 1024"); return -1; } int recycle_times=atoi(argv[1]); int buf_len=atoi(argv[2]); */ int sockfd,numbytes; //char buf[BUFSIZ]; int sc_clk_tck; sc_clk_tck = sysconf(_SC_CLK_TCK); sc_clk_tck = sysconf(_SC_CLK_TCK); struct sockaddr_in their_addr; //printf("break! sc_clk_tck=%d ",sc_clk_tck); while((sockfd = socket(AF_INET,SOCK_DGRAM,0)) == -1); //printf("We get the sockfd~ "); their_addr.sin_family = AF_INET; their_addr.sin_port = htons(8888); their_addr.sin_addr.s_addr=inet_addr("192.168.10.8"); bzero(&(their_addr.sin_zero), 8); while(connect(sockfd,(struct sockaddr*)&their_addr,sizeof(struct sockaddr)) == -1); // printf("Get the Server~Cheers! "); 濉濞绔�俊姣 // numbytes = recv(sockfd, buf, BUFSIZ,0);//妤娑? // buf[numbytes]=' '; // printf("%s",buf); //clock_t start_time,end_time; // start_time=clock(); int buf_i=0; for(buf_i=0;buf_i<7;buf_i++){ int buf_len=bufsizeSet[buf_i]; char *buf=(char *)calloc(buf_len,sizeof(char)); int i=0; for(i=0;i<buf_len;i++) { buf[i]='a' + rand()%26; } buf[buf_len]='