1. 程式人生 > >nginx lua與go的ab壓力測試hello world

nginx lua與go的ab壓力測試hello world

測試機器 4核8G伺服器 ab執行在內網另外一臺伺服器上面 

nginx lua程式碼    4個worker程序

server {
    listen 80;
    server_name 10.10.155.58;
    root /app/www/10.10.155.58;
    access_log /app/nginx/logs/10.10.155.58.log;
    error_log /app/nginx/logs/10.10.155.58_error.log;
    index index.html;

    location / {
        content_by_lua '
                ngx.say("hello world")
            ';   
    }

}

測試結果

go程式碼

package main

import (
    "io"
    "log"
    "net/http"
    "sync"
)
var m *sync.RWMutex

func HelloServer(w http.ResponseWriter, req *http.Request) {
    m.RLock()
    io.WriteString(w, "hello world\n")
    m.RUnlock()
}

func main() {
    m = new(sync.RWMutex)
    http.HandleFunc("/", HelloServer)

    err := http.ListenAndServe(":8080", nil)

    if err != nil {
        log.Fatal("ListenAndServer: ", err.Error())
    }
}