AB压测原生php语言、原生php语言+opcache缓存、原生go语言、go语言的gin框架

VMware CentOS7虚拟机 1核cpu 2G内存 20G硬盘

已知go环境和php环境在同一虚拟机中,功能是输出"hello world",以下压测结果是使用go和php分别打印"hello world"

php和go使用了nginx做为web服务器

go、php 部署在192.168.182.196

ab 部署在192.168.182.138

// php 语言脚本
<?php
echo "hello world -- php";

// go 语言原生脚本
package main

import (
    "fmt"
    "log"
    "net/http"
)

// w表示response对象,返回给客户端的内容都在对象里处理
// r表示客户端请求对象,包含了请求头,请求参数等等
func index(w http.ResponseWriter, r *http.Request) {
    // 往w里写入内容,就会在浏览器里输出
    fmt.Fprintf(w, "Hello golang http!")
}
 
func main() {
    // 设置路由,如果访问/,则调用index方法
    http.HandleFunc("/index", index)
 
    // 启动web服务,监听9090端口
    err := http.ListenAndServe(":8000", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

// go 语言gin框架
package main
import (
    "net/http"
    "github.com/gin-gonic/gin"
)
func main() {
    // 1.创建路由
   r := gin.Default()
   // 2.绑定路由规则,执行的函数
   // gin.Context,封装了request和response
   r.GET("/index", func(c *gin.Context) {
      c.String(http.StatusOK, "hello World -- go")
   })
   // 3.监听端口,默认在8000
   // Run("里面不指定端口号默认为8000") 
   r.Run(":8000")
}

ab -n 100000 -c 100 -t 2 http://p.com/index.php

wangjing@ubuntu:~$ ab -n 500000 -c 1000 -t 2 http://g.com/index

        Concurrency Level:      1000------------------------------go原生

        Time taken for tests:   2.040 seconds

        Complete requests:      5474

        Failed requests:        0

        Total transferred:      944710 bytes

        HTML transferred:       100620 bytes

        Requests per second:    2682.95 [#/sec] (mean)

        Time per request:       372.725 [ms] (mean)

        Time per request:       0.373 [ms] (mean, across all concurrent requests)

        Transfer rate:          452.17 [Kbytes/sec] received

                Concurrency Level:      1000------------------------------php opcache

                Time taken for tests:   2.013 seconds

                Complete requests:      5234

                Failed requests:        0

                Total transferred:      1051783 bytes

                HTML transferred:       96102 bytes

                Requests per second:    2600.21 [#/sec] (mean)

                Time per request:       384.584 [ms] (mean)

                Time per request:       0.385 [ms] (mean, across all concurrent requests)

                Transfer rate:          510.27 [Kbytes/sec] received

wangjing@ubuntu:~$ ab -n 500000 -c 1000 -t 2 http://g.com/index

        Concurrency Level:      1000------------------------------go原生

        Time taken for tests:   2.040 seconds

        Complete requests:      5474

        Failed requests:        0

        Total transferred:      944710 bytes

        HTML transferred:       100620 bytes

        Requests per second:    2682.95 [#/sec] (mean)

        Time per request:       372.725 [ms] (mean)

        Time per request:       0.373 [ms] (mean, across all concurrent requests)

        Transfer rate:          452.17 [Kbytes/sec] received

                Concurrency Level:      1000------------------------------php opcache

                Time taken for tests:   2.013 seconds

                Complete requests:      5234

                Failed requests:        0

                Total transferred:      1051783 bytes

                HTML transferred:       96102 bytes

                Requests per second:    2600.21 [#/sec] (mean)

                Time per request:       384.584 [ms] (mean)

                Time per request:       0.385 [ms] (mean, across all concurrent requests)

                Transfer rate:          510.27 [Kbytes/sec] received

wangjing@ubuntu:~$ ab -n 10000 -c 100 -t 2 http://p.com/index.php

        Concurrency Level:      100------------------------------php no opcache 

        Time taken for tests:   2.000 seconds

        Complete requests:      5637

        Failed requests:        0

        Total transferred:      1110489 bytes

        HTML transferred:       101466 bytes

        Requests per second:    2818.34 [#/sec] (mean)

        Time per request:       35.482 [ms] (mean)

        Time per request:       0.355 [ms] (mean, across all concurrent requests)

        Transfer rate:          542.20 [Kbytes/sec] received

                Concurrency Level:      100------------------------------php opcache

                Time taken for tests:   2.000 seconds

                Complete requests:      6161

                Failed requests:        0

                Total transferred:      1213717 bytes

                HTML transferred:       110898 bytes

                Requests per second:    3080.24 [#/sec] (mean)

                Time per request:       32.465 [ms] (mean)

                Time per request:       0.325 [ms] (mean, across all concurrent requests)

                Transfer rate:          592.59 [Kbytes/sec] received

                        wangjing@ubuntu:~$ ab -n 10000 -c 100 -t 2 http://g.com/index -------------------------------go gin框架

                        Concurrency Level:      100

                        Time taken for tests:   2.001 seconds

                        Complete requests:      6657

                        Failed requests:        0

                        Total transferred:      1119552 bytes

                        HTML transferred:       113288 bytes

                        Requests per second:    3326.19 [#/sec] (mean)

                        Time per request:       30.064 [ms] (mean)

                        Time per request:       0.301 [ms] (mean, across all concurrent requests)

                        Transfer rate:          546.28 [Kbytes/sec] received

                                Concurrency Level:      100------------------------------go原生

                                Time taken for tests:   2.001 seconds

                                Complete requests:      7423

                                Failed requests:        0

                                Total transferred:      1254487 bytes

                                HTML transferred:       133614 bytes

                                Requests per second:    3709.76 [#/sec] (mean)

                                Time per request:       26.956 [ms] (mean)

                                Time per request:       0.270 [ms] (mean, across all concurrent requests)

                                Transfer rate:          612.25 [Kbytes/sec] received

wangjing@ubuntu:~$ ab -n 100000 -c 100 -t 2 http://p.com/index.php

        Concurrency Level:      100------------------------------php no opcache

        Time taken for tests:   2.000 seconds

        Complete requests:      5553

        Failed requests:        0

        Total transferred:      1094532 bytes

        HTML transferred:       100008 bytes

        Requests per second:    2776.40 [#/sec] (mean)

        Time per request:       36.018 [ms] (mean)

        Time per request:       0.360 [ms] (mean, across all concurrent requests)

        Transfer rate:          534.42 [Kbytes/sec] received

                Concurrency Level:      100------------------------------php opcache

                Time taken for tests:   2.002 seconds

                Complete requests:      6060

                Failed requests:        0

                Total transferred:      1194608 bytes

                HTML transferred:       109152 bytes

                Requests per second:    3027.63 [#/sec] (mean)

                Time per request:       33.029 [ms] (mean)

                Time per request:       0.330 [ms] (mean, across all concurrent requests)

                Transfer rate:          582.85 [Kbytes/sec] received

                        wangjing@ubuntu:~$ ab -n 100000 -c 100 -t 2 http://g.com/index ------------------------------go gin框架

                        Concurrency Level:      100

                        Time taken for tests:   2.000 seconds

                        Complete requests:      6492

                        Failed requests:        0

                        Total transferred:      1090656 bytes

                        HTML transferred:       110364 bytes

                        Requests per second:    3245.72 [#/sec] (mean)

                        Time per request:       30.810 [ms] (mean)

                        Time per request:       0.308 [ms] (mean, across all concurrent requests)

                        Transfer rate:          532.50 [Kbytes/sec] received

                                Concurrency Level:      100------------------------------go 原生

                                Time taken for tests:   2.000 seconds

                                Complete requests:      7420

                                Failed requests:        0

                                Total transferred:      1254318 bytes

                                HTML transferred:       133596 bytes

                                Requests per second:    3709.88 [#/sec] (mean)

                                Time per request:       26.955 [ms] (mean)

                                Time per request:       0.270 [ms] (mean, across all concurrent requests)

                                Transfer rate:          612.44 [Kbytes/sec] received

wangjing@ubuntu:~$ ab -n 10000 -c 1000 -t 2 http://p.com/index.ph

        Concurrency Level:      1000------------------------------php no opcache

        Time taken for tests:   2.000 seconds

        Complete requests:      3475

        Failed requests:        0

        Total transferred:      684772 bytes

        HTML transferred:       62568 bytes

        Requests per second:    1737.47 [#/sec] (mean)

        Time per request:       575.549 [ms] (mean)

        Time per request:       0.576 [ms] (mean, across all concurrent requests)

        Transfer rate:          334.36 [Kbytes/sec] received

                Concurrency Level:      1000------------------------------php opcache

                Time taken for tests:   2.013 seconds

                Complete requests:      5118

                Failed requests:        0

                Total transferred:      1031689 bytes

                HTML transferred:       94266 bytes

                Requests per second:    2542.00 [#/sec] (mean)

                Time per request:       393.391 [ms] (mean)

                Time per request:       0.393 [ms] (mean, across all concurrent requests)

                Transfer rate:          500.41 [Kbytes/sec] received

                        wangjing@ubuntu:~$ ab -n 10000 -c 1000 -t 2 http://g.com/index ------------------------------go gin框架

                        Concurrency Level:      1000

                        Time taken for tests:   2.004 seconds

                        Complete requests:      5777

                        Failed requests:        0

                        Total transferred:      981456 bytes

                        HTML transferred:       99314 bytes

                        Requests per second:    2883.22 [#/sec] (mean)

                        Time per request:       346.834 [ms] (mean)

                        Time per request:       0.347 [ms] (mean, across all concurrent requests)

                        Transfer rate:          478.35 [Kbytes/sec] received

                                Concurrency Level:      1000------------------------------go 原生

                                Time taken for tests:   2.003 seconds

                                Complete requests:      7081

                                Failed requests:        0

                                Total transferred:      1196689 bytes

                                HTML transferred:       127458 bytes

                                Requests per second:    3534.93 [#/sec] (mean)

                                Time per request:       282.891 [ms] (mean)

                                Time per request:       0.283 [ms] (mean, across all concurrent requests)

                                Transfer rate:          583.40 [Kbytes/sec] received


(完)