web框架并发3--go stdlib

2019-01-22  本文已影响0人  流亡民头

go 版本:go version go1.6 linux/amd64

一、代码:

package main

import (

    "net/http"

)

func say(w http.ResponseWriter, r *http.Request) {

    w.Write([]byte("hello world"))

}

func main() {

    http.HandleFunc(`/`, say)

    http.ListenAndServe(":9996", nil)

}

二、测试结果

1. webbench -c 1 -t 10 http://127.0.0.1:9996/

Speed=246096 pages/min, 525004 bytes/sec.

Requests: 41016 susceed, 0 failed.

2. webbench -c 10 -t 10 http://127.0.0.1:9996/

Speed=1841970 pages/min, 3929523 bytes/sec.

Requests: 306995 susceed, 0 failed.

3.webbench -c 20 -t 10 http://127.0.0.1:9996/

Speed=2071686 pages/min, 4419609 bytes/sec.

Requests: 345281 susceed, 0 failed.

并发 34528qps, 已经使用了所有的逻辑核(多进程)。

三、升级了go版本到1.10.7,测试结果

1. webbench -c 1 -t 10 http://127.0.0.1:9996/

Speed=613074 pages/min, 1307891 bytes/sec.

Requests: 102179 susceed, 0 failed.

2.webbench -c 10 -t 10 http://127.0.0.1:9996/

Speed=2409978 pages/min, 5141299 bytes/sec.

Requests: 401663 susceed, 0 failed.

并发有较大的提升

上一篇下一篇

猜你喜欢

热点阅读