const int port = atoi(argv[2]);
const char *ip = argv[1];
ConfigServer::ServerInit Init;
WebServer server(ip, port);
server.run();
使用 C++ 语言开发,采用 Reactor+线程池 的结构,维护状态机解析 HTTP 请求,使用 RapidJSON 解析 JSON 配置文件,通过 FastCGI 协议与 PHP 后台引擎进行通讯。
- 使用多线程充分利用多核CPU,并使用 线程池 避免线程频繁创建销毁的开销
- 使用 Epoll ET 的 IO多路复用 技术,非阻塞式 IO,采用 Reactor+线程池 的结构
- 维护 有限状态机 去解析 Http 请求,提高解析速率
- 使用配置文件,配置服务器参数,并使用 RapidJSON库 解析 JSON 配置文件
- 通过 FastCGI 协议与 PHP 后台引擎进行通讯,以支持 PHP 请求
- 支持在浏览器页面播放 音频和视频
- OS: Linux
- Complier: g++ / clang++
$ git clone git@github.com:liushengxi13689209566/WebServer.git
$ cd WebServer/src
$ make
$ ./WebServer 127.0.0.1 9981
#include "Web_server.h"
using namespace std;
int main(int argc, char *argv[])
{
if (argc <= 2)
{
cout << "usage : " << basename(argv[0]) << " ip_address port_number " << endl;
return 1;
}
const char *ip = argv[1];
const int port = atoi(argv[2]);
try
{
ConfigServer::ServerInit Init;
WebServer my(ip, port);
my.run();
}
catch (CallFailed &failed)
{
std::cout << failed.ErrString << failed.LineNo << std::endl;
perror("The reason is :");
}
catch (...)
{
perror("发生了不可见的异常\n");
}
return 0;
}
统一使用命令
./webbench http://127.0.0.1:<端口号>/ -2 --get -c <客户端数量> -t 6
测试 | 5个客户端 | 20个客户端 | 50个客户端 | 200个客户端 | 5000个客户端 |
---|---|---|---|---|---|
bytes/sec大小 | 340414304 | 332031744 | 254892816 | 299588320 | 279898240 |