Socket網絡編程--簡單Web服務器(6)

  原本是想實現ssl鏈接的,可是弄了很久都不成功,就索性不作了,等之後有能力再作了。因此這一小節就是本次的最後一節了。就簡單的說幾個注意點。html

  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 secs
100 Transaction rate:              96.71 trans/sec
101 Throughput:                     0.02 MB/sec
102 Concurrency:                    1.55
103 Successful transactions:         500
104 Failed transactions:               0
105 Longest transaction:            0.17
106 Shortest transaction:           0.00
107 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
108 Transactions:                    500 hits
109 Availability:                 100.00 %
110 Elapsed time:                   5.14 secs
111 Data transferred:               0.11 MB
112 Response time:                  0.02 secs
113 Transaction rate:              97.28 trans/sec
114 Throughput:                     0.02 MB/sec
115 Concurrency:                    1.77
116 Successful transactions:         500
117 Failed transactions:               0
118 Longest transaction:            0.12
119 Shortest transaction:           0.00

   一看才知道,個人服務器是有多渣呀,好不開心。url

 

  Socket網絡編程--簡單Web服務器各章節傳送門spa

  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

  參考資料: http://www.zihou.me/html/2011/01/27/2737.html

  本文地址: http://www.cnblogs.com/wunaozai/p/3949324.html

相關文章
相關標籤/搜索