歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Unix知識 >> 關於Unix

freebsd中的libnet發送性能


使用千兆網絡發數據包,FREEBSD的性能比Linux中差太多了!
使用4個千兆網口發送數據,Linux可以達到4*950Mbps
而FreeBsd:....看測試情況:
1口:940Mbps,還可以,奇怪的是CPU 60以上
2口:940*2 也不錯,很神奇的CPU變成了10左右
3口:600*3 不爽CPU 15
4口同時跑!!!問題來了,40*4。差差!!不可理喻。
而且不支持大幀。
配了MTU,沒有用。
神奇的BSD!!!
附上測試代碼:
多線程。但用多進程也是同樣結果
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
#include
#include
using namespace std;
int packet_len;
int sleep_tm;
struct send_info_t
{
pthread_t pt;
char *dev_name;
long long sended_count;
};
#define ETH_COUNT 16
send_info_t si[ETH_COUNT];
void *Thread_Send(void *pParam)
{
send_info_t *psi = (send_info_t *)pParam;

libnet_t *l;
char errbuf[LIBNET_ERRBUF_SIZE];
int c;
unsigned char ch = 0;
libnet_ptag_t t =0;
unsigned char hwdst[ETHER_ADDR_LEN] = {0x11,0x11,0x11,0x11,0x11,0x11};
unsigned char hwsrc[ETHER_ADDR_LEN] = {0x22,0x22,0x22,0x22,0x22,0x22};
unsigned char data[10000];
memset(data,ch,10000);

l = libnet_init(LIBNET_LINK,psi->dev_name,errbuf);
if(l==NULL)
{
cout <<"Send Thread:"<dev_name<< "ERR:" < return NULL;
}

cout<<"Send Thread:"<dev_name<<" Started"<
for(;;)
{
memset(data,ch,10000);

t = libnet_build_ethernet(hwdst,hwsrc,0x0808,data,packet_len,l,t);
if(t <0)
{
cout << "BUILD PACKET ERROR"< break;
}

c = libnet_write(l);
if(c <0)
{
usleep(5000);
}
psi->sended_count ++;
}

libnet_destroy(l);
cout<<"Send Thread:"<dev_name<<" Closed"< return NULL;
}
int main(int argc, char *argv[])
{
if(argc < 4)
{
cout<<"test packet_size sleep_tm(us) eth0 ethx"< return 0;
}

packet_len = atoi(argv[1]);
sleep_tm = atoi(argv[2]);

memset(si,0,sizeof(send_info_t)*ETH_COUNT );
int i;
for(i=3;i {
if((i-3) >= ETH_COUNT )
break;
send_info_t *psi = &si[i-3];
psi->dev_name = argv;
pthread_create(&psi->pt,NULL,Thread_Send,psi);

}


timeval tv_start,tv_now;
gettimeofday(&tv_start,NULL);

for(;;)
{
gettimeofday(&tv_now,NULL);
for(i=0;i {
send_info_t *psi = &si;
if(psi->dev_name != NULL)
{
if(s != s1)
{
double speed = (double)(psi->sended_count * packet_len * 8)/(((double)(s1 - s)) /1000000)/1000/1000;
cout<dev_name <<": "<sended_count<<"PacketSended,Speed="< }
}
}


sleep(2);
}


int aa;
cin >> aa;
return EXIT_SUCCESS;
}
Copyright © Linux教程網 All Rights Reserved