如何使用ApacheBench运行负载测试

时间:2016-07-27 17:59:24

标签: node.js go benchmarking apachebench

请假设我想测试Node和Go的HTTP功能,我怎样才能使用ApacheBench进行负载测试?注意:我已经安装了AB,我只是不知道如何运行测试。

节点:

  var http = require("http");
  http.createServer(function(request,response) {
  response.writeHeader(200);
  response.write("You requested " + request.url);
  response.end();
}).listen(8080);

转到:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "You requested %s", r.URL.Path)
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

1 个答案:

答案 0 :(得分:1)

你做ab -n [请求数] -c [并发请求数] [url]:[port]

ab -n 100 -c 10 http://localhost:8080/
相关问题