首页 > 代码库 > Socket网络编程--简单Web服务器(6)
Socket网络编程--简单Web服务器(6)
本来是想实现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/
1 siege -c100 -r5 url #对url地址进行100个并发用户5次的测试 2 ##############我的WebServer############ 3 Transactions: 500 hits 4 Availability: 100.00 % 5 Elapsed time: 8.87 secs 6 Data transferred: 0.60 MB 7 Response time: 0.75 secs 8 Transaction rate: 56.37 trans/sec 9 Throughput: 0.07 MB/sec 10 Concurrency: 42.26 11 Successful transactions: 500 12 Failed transactions: 0 13 Longest transaction: 3.95 14 Shortest transaction: 0.01 15 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 16 Transactions: 500 hits 17 Availability: 100.00 % 18 Elapsed time: 8.64 secs 19 Data transferred: 0.60 MB 20 Response time: 0.66 secs 21 Transaction rate: 57.87 trans/sec 22 Throughput: 0.07 MB/sec 23 Concurrency: 37.96 24 Successful transactions: 500 25 Failed transactions: 0 26 Longest transaction: 2.87 27 Shortest transaction: 0.01 28 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 29 Transactions: 500 hits 30 Availability: 100.00 % 31 Elapsed time: 8.58 secs 32 Data transferred: 0.60 MB 33 Response time: 0.62 secs 34 Transaction rate: 58.28 trans/sec 35 Throughput: 0.07 MB/sec 36 Concurrency: 36.41 37 Successful transactions: 500 38 Failed transactions: 0 39 Longest transaction: 3.01 40 Shortest transaction: 0.01 41 42 ##############本地Nginx################ 43 Transactions: 500 hits 44 Availability: 100.00 % 45 Elapsed time: 5.07 secs 46 Data transferred: 0.29 MB 47 Response time: 0.02 secs 48 Transaction rate: 98.62 trans/sec 49 Throughput: 0.06 MB/sec 50 Concurrency: 2.40 51 Successful transactions: 500 52 Failed transactions: 0 53 Longest transaction: 0.08 54 Shortest transaction: 0.00 55 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 56 Transactions: 500 hits 57 Availability: 100.00 % 58 Elapsed time: 5.19 secs 59 Data transferred: 0.29 MB 60 Response time: 0.02 secs 61 Transaction rate: 96.34 trans/sec 62 Throughput: 0.06 MB/sec 63 Concurrency: 2.40 64 Successful transactions: 500 65 Failed transactions: 0 66 Longest transaction: 0.08 67 Shortest transaction: 0.00 68 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 69 Transactions: 500 hits 70 Availability: 100.00 % 71 Elapsed time: 5.15 secs 72 Data transferred: 0.29 MB 73 Response time: 0.02 secs 74 Transaction rate: 97.09 trans/sec 75 Throughput: 0.06 MB/sec 76 Concurrency: 1.83 77 Successful transactions: 500 78 Failed transactions: 0 79 Longest transaction: 0.05 80 Shortest transaction: 0.00 81 ##############本地httpd################ 82 Transactions: 500 hits 83 Availability: 100.00 % 84 Elapsed time: 5.18 secs 85 Data transferred: 0.11 MB 86 Response time: 0.02 secs 87 Transaction rate: 96.53 trans/sec 88 Throughput: 0.02 MB/sec 89 Concurrency: 2.18 90 Successful transactions: 500 91 Failed transactions: 0 92 Longest transaction: 0.18 93 Shortest transaction: 0.00 94 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 95 Transactions: 500 hits 96 Availability: 100.00 % 97 Elapsed time: 5.17 secs 98 Data transferred: 0.11 MB 99 Response time: 0.02 secs100 Transaction rate: 96.71 trans/sec101 Throughput: 0.02 MB/sec102 Concurrency: 1.55103 Successful transactions: 500104 Failed transactions: 0105 Longest transaction: 0.17106 Shortest transaction: 0.00107 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$108 Transactions: 500 hits109 Availability: 100.00 %110 Elapsed time: 5.14 secs111 Data transferred: 0.11 MB112 Response time: 0.02 secs113 Transaction rate: 97.28 trans/sec114 Throughput: 0.02 MB/sec115 Concurrency: 1.77116 Successful transactions: 500117 Failed transactions: 0118 Longest transaction: 0.12119 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
参考资料: http://www.zihou.me/html/2011/01/27/2737.html
本文地址: http://www.cnblogs.com/wunaozai/p/3949324.html
Socket网络编程--简单Web服务器(6)