使用webBench对tinyHttpd服务器测试

1.测试出现问题


jhon@jhpnComputer:~/322g/C_C++Project/WebBench$ ./webbench -c 500 -t 30 http://170.0.0.1:80/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Request:
GET / HTTP/1.0
User-Agent: WebBench 1.5
Host: 170.0.0.1

Runing info: 500 clients, running 30 sec.

Connect to server failed. Aborting benchmark.

全部失败且TinyHttpd自动断开;

2.错误原因

因为WebBench在一次访问完之后就断掉了,但是TinyHttpd要分次把一个网页的内容发送给WebBench,所以第一次发的时候是成功的,第二次就失败了。而且TinyHttpd在send的时候没有异常判断和处理,所以程序卡死

3.解决方法

  • 将httpd.c的unimplemented中send(client, buf, strlen(buf), 0)后面代码发送注释掉:
//返回给浏览器表明收到的HTTP请求所用的method方法不被支持
void unimplemented(int client)
{
 char buf[1024];`在这里插入代码片`
 //sprintf函数将信息打印到字符串中;
 sprintf(buf, "HTTP/1.0 501 Method Not Implemented\r\n");
 send(client, buf, strlen(buf), 0);
 //send()函数用于向一个已经连接的socket发送数据,
 //如果无错误,返回值为所发数据的总数,否则返回SOCKET_ERROR;
 /*
 sprintf(buf, SERVER_STRING);
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "Content-Type: text/html\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<HTML><HEAD><TITLE>Method Not Implemented\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</TITLE></HEAD>\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "<BODY><P>HTTP request method not supported.\r\n");
 send(client, buf, strlen(buf), 0);
 sprintf(buf, "</BODY></HTML>\r\n");
 send(client, buf, strlen(buf), 0);
 */
}
  • 再次测试:
jhon@jhpnComputer:~/322g/C_C++Project/WebBench$ ./webbench -c 500 -t 10 http://localhost:11000/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Request:
GET / HTTP/1.0
User-Agent: WebBench 1.5
Host: localhost


Runing info: 500 clients, running 10 sec.

Speed=430326 pages/min, 2051106 bytes/sec.
Requests: 71717 susceed, 4 failed.

参考

猜你喜欢

转载自blog.csdn.net/qq_42698422/article/details/106884966