1. 程式人生 > >golang-web 和 net/http 原始碼分析

golang-web 和 net/http 原始碼分析

golang-web

開發 web 服務程式

開發簡單 web 服務程式 cloudgo,瞭解 web 伺服器工作原理。

基本要求

  • 程式設計 web 服務程式 類似 cloudgo 應用。
  • 使用 curl 測試,將測試結果寫入 README.md
  • 使用 ab 測試,將測試結果寫入 README.md。並解釋重要引數。
  • 擴充套件:分析net/http 原始碼,解釋一些關鍵功能實現

實驗結果:

執行web伺服器

$curl -v http://localhost:9090/Hello-web/whale

curl 測試

$ ab -n 1000 -c 100 http://localhost:9090/hello/your

ab 測試

  • ab測試分析
    • flag“-n” 全部請求數
    • flag“-c” 併發數
Concurrency Level:      100           //併發數  
Time taken for tests:   10.68 seconds //全部請求完成耗時
Complete requests:      1000         //全部請求數
Failed requests:        0           //失敗的請求
Total transferred:      176000bytes  //總傳輸大小 
HTML transferred:       53000bytes //整個場景中的HTML內容傳輸量
Requests per second:    936.76 [#/sec] (mean)   //每秒請求數(平均) 
Time per request:       106.751 [ms] (mean)   //每次併發請求時間
Transfer rate:         161.01 [Kbytes/sec] received    //傳輸速率
Percentage of the requests served within a certain time (ms)
  50%   107
  66%   108
  75%   109
  80%  109
  90%  111
  95%  112
  98%  115
  99%  122
 100%  210 (longest request)
//整個場景中所有請求的響應情況。在場景中每個請求都有一個響應時間,其中50%的使用者響應時間小於107毫秒,60% 的使用者響應時間小於108毫秒,最大的響應時間小於210毫秒
  • 分析net/http 原始碼