本来是想实现ssl连接的,但是弄了好久都不成功,就索性不做了,等以后有能力再做了。所以这一小节就是本次的最后一节了。就简单的说几个注意点。
1.加个配置文件
使用单例模式,使用一个类,该类保存一些信息,例如一个配置类的一个属性为PAGE404的字符串,该字符串保存一个文件地址,然后我们的Page_404函数就可以用access判断PAGE404这个字符串对应的文件是否存在,如果存在那么如果是404页面那么就cat这个文件,而不是默认的404函数里面的页面。还有个端口什么的都是通过一个类似宏定义一样,代替程序中的魔数。还有各种配置的就不多说了。
2.访问控制
这个就更简单了,通过一个配置文件读取运行的IP,和拒绝的IP,然后在WebServer::ServerAccept()函数中可以判断,在这个函数中可以获取到连接进来的IP地址,然后可以通过这个IP地址进行约束。具体也不是很难。
3.siege性能测试
这个就是本小节的重点了。(这里要说明的是我这个服务器性能差的很,求不吐槽。)
下载地址: http://www.joedog.org/2013/07/siege-3-0-3-url-encoding/
siege -c100 -r5 url #对url地址进行100个并发用户5次的测试
##############我的WebServer############
Transactions: hits
Availability: 100.00 %
Elapsed time: 8.87 secs
Data transferred: 0.60 MB
Response time: 0.75 secs
Transaction rate: 56.37 trans/sec
Throughput: 0.07 MB/sec
Concurrency: 42.26
Successful transactions:
Failed transactions:
Longest transaction: 3.95
Shortest transaction: 0.01
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Transactions: hits
Availability: 100.00 %
Elapsed time: 8.64 secs
Data transferred: 0.60 MB
Response time: 0.66 secs
Transaction rate: 57.87 trans/sec
Throughput: 0.07 MB/sec
Concurrency: 37.96
Successful transactions:
Failed transactions:
Longest transaction: 2.87
Shortest transaction: 0.01
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Transactions: hits
Availability: 100.00 %
Elapsed time: 8.58 secs
Data transferred: 0.60 MB
Response time: 0.62 secs
Transaction rate: 58.28 trans/sec
Throughput: 0.07 MB/sec
Concurrency: 36.41
Successful transactions:
Failed transactions:
Longest transaction: 3.01
Shortest transaction: 0.01 ##############本地Nginx################
Transactions: hits
Availability: 100.00 %
Elapsed time: 5.07 secs
Data transferred: 0.29 MB
Response time: 0.02 secs
Transaction rate: 98.62 trans/sec
Throughput: 0.06 MB/sec
Concurrency: 2.40
Successful transactions:
Failed transactions:
Longest transaction: 0.08
Shortest transaction: 0.00
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Transactions: hits
Availability: 100.00 %
Elapsed time: 5.19 secs
Data transferred: 0.29 MB
Response time: 0.02 secs
Transaction rate: 96.34 trans/sec
Throughput: 0.06 MB/sec
Concurrency: 2.40
Successful transactions:
Failed transactions:
Longest transaction: 0.08
Shortest transaction: 0.00
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Transactions: hits
Availability: 100.00 %
Elapsed time: 5.15 secs
Data transferred: 0.29 MB
Response time: 0.02 secs
Transaction rate: 97.09 trans/sec
Throughput: 0.06 MB/sec
Concurrency: 1.83
Successful transactions:
Failed transactions:
Longest transaction: 0.05
Shortest transaction: 0.00
##############本地httpd################
Transactions: hits
Availability: 100.00 %
Elapsed time: 5.18 secs
Data transferred: 0.11 MB
Response time: 0.02 secs
Transaction rate: 96.53 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 2.18
Successful transactions:
Failed transactions:
Longest transaction: 0.18
Shortest transaction: 0.00
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Transactions: hits
Availability: 100.00 %
Elapsed time: 5.17 secs
Data transferred: 0.11 MB
Response time: 0.02 secs
Transaction rate: 96.71 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 1.55
Successful transactions:
Failed transactions:
Longest transaction: 0.17
Shortest transaction: 0.00
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Transactions: hits
Availability: 100.00 %
Elapsed time: 5.14 secs
Data transferred: 0.11 MB
Response time: 0.02 secs
Transaction rate: 97.28 trans/sec
Throughput: 0.02 MB/sec
Concurrency: 1.77
Successful transactions:
Failed transactions:
Longest transaction: 0.12
Shortest transaction: 0.00
一看才知道,我的服务器是有多渣呀,好不开心。
Socket网络编程--简单Web服务器各章节传送门
Socket网络编程--简单Web服务器(1) http://www.cnblogs.com/wunaozai/p/3926033.html
Socket网络编程--简单Web服务器(2) http://www.cnblogs.com/wunaozai/p/3936295.html
Socket网络编程--简单Web服务器(3) http://www.cnblogs.com/wunaozai/p/3943952.html
Socket网络编程--简单Web服务器(4) http://www.cnblogs.com/wunaozai/p/3945218.html
Socket网络编程--简单Web服务器(5) http://www.cnblogs.com/wunaozai/p/3946486.html
Socket网络编程--简单Web服务器(6) http://www.cnblogs.com/wunaozai/p/3949324.html
Web服务器源码下载: http://files.cnblogs.com/wunaozai/WebServer.zip