PHP7.3+Swoole4.4 / Go1.13 / MixPHP2.2 / Beego1.12 性能對比

好幾年沒有做過性能對比了,因為越來越覺得性能并沒有那么的重要(相對于生態(tài)),今天有時間簡單測試一下,因為 Mix v2.1 開始就全部切換為單進(jìn)程協(xié)程模式晶丘,因此本次主要測試的是 Co\Http\Server ,測試結(jié)果在最后面。

環(huán)境

  • CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
  • CPU(s): 12
  • Mem: 15G
  • Linux version 3.10.0-957.10.1.el7.x86_64

PHP 7.3.12 + Swoole 4.4.14

代碼中使用的單進(jìn)程 Co\Http\Server 浅浮,因此需要利用端口復(fù)用 (需要 Linux >= 3.10)沫浆,開啟 12 個進(jìn)程

  • 代碼
<?php 

\Swoole\Process::daemon();

$scheduler = new \Swoole\Coroutine\Scheduler;
$scheduler->set([
    'hook_flags' => SWOOLE_HOOK_ALL,
]);
$scheduler->add(function () {

    $server = new \Swoole\Coroutine\Http\Server('0.0.0.0', 8888, false, true);
    $server->handle('/', function($request, $response){
        $response->end('hello, world!');
    });
    $server->start();

});
$scheduler->start();
  • 開啟的進(jìn)程
[nobody@tmp]$ ps -ef | grep test.php
nobody    1917     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    1923     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    1929     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    1934     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2154     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2166     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2173     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2181     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2187     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2194     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2200     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
nobody    2205     1  0 20:22 ?        00:00:02 /usr/local/php-7.3.12/bin/php test.php
  • 測試:多跑幾次,基本穩(wěn)定在 127441.95 左右滚秩。
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8888/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            8888

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.785 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      16600000 bytes
HTML transferred:       1300000 bytes
Requests per second:    127441.95 [#/sec] (mean)
Time per request:       7.847 [ms] (mean)
Time per request:       0.008 [ms] (mean, across all concurrent requests)
Transfer rate:          20659.53 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.4      0      47
Processing:     2    7   0.5      7      47
Waiting:        0    7   0.4      7      14
Total:          2    8   2.6      7      58

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      7
  75%      7
  80%      7
  90%      8
  95%      8
  98%      8
  99%     18
 100%     58 (longest request)

Go 1.13.4

Golang 默認(rèn)使用全部 CPU 線程专执,因此只需開啟一個進(jìn)程即可。

  • 代碼
package main

import (
    "fmt"
    "net/http"
)

func main() {

    http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
        writer.Write([]byte("hello, world!"))
    })
    err := http.ListenAndServe(":9999", nil)
    if err != nil{
        fmt.Println(err)
    }

}
  • 開啟的進(jìn)程
[nobody@~]$ ps -ef | grep gotest
nobody    4409  1859  0 20:25 pts/31   00:00:06 ./gotest_linux
  • 測試:多跑幾次叔遂,基本穩(wěn)定在 121575.23 左右他炊,比 Swoole 稍微差點,但非常接近已艰,PHP 是動態(tài)語言借助 Swoole 做到這個性能確實是非橙夸張了。
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9999/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        127.0.0.1
Server Port:            9999

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.823 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      15400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    121575.23 [#/sec] (mean)
Time per request:       8.225 [ms] (mean)
Time per request:       0.008 [ms] (mean, across all concurrent requests)
Transfer rate:          18283.77 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.4      0      46
Processing:     2    8   1.1      7      46
Waiting:        0    8   1.1      7      30
Total:          2    8   2.7      7      56

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      8
  75%      9
  80%      9
  90%      9
  95%      9
  98%     10
  99%     18
 100%     56 (longest request)

MixPHP V2.2

接下來我們看一下跑在 PHP7.3 + Swoole4.4 下的 Mix V2.2 能跑多少哩掺。

  • 開啟的進(jìn)程
[nobody@tmp]$ ps -ef | grep mix.php
nobody   24783     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24801     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24821     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24839     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24856     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24873     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24891     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24908     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24927     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24946     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24963     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24981     1  0 20:51 ?        00:00:00 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
  • 測試:多跑幾次凿叠,基本穩(wěn)定在 110050.47 左右,比原生 Swoole 降低了 13.6%嚼吞,整個框架的代碼只降低了這個比例盒件,還是蠻可以的。
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9501/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            9501

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.909 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      18100000 bytes
HTML transferred:       1300000 bytes
Requests per second:    110050.47 [#/sec] (mean)
Time per request:       9.087 [ms] (mean)
Time per request:       0.009 [ms] (mean, across all concurrent requests)
Transfer rate:          19452.28 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.5      0      45
Processing:     2    9   1.6      9      46
Waiting:        0    9   1.6      9      25
Total:          2    9   3.2      9      58

Percentage of the requests served within a certain time (ms)
  50%      9
  66%      9
  75%      9
  80%      9
  90%      9
  95%     10
  98%     17
  99%     23
 100%     58 (longest request)

我嘗試減少進(jìn)程測試:

  • 當(dāng)減少到 5 個進(jìn)程時達(dá)到最高性能
[nobody@tmp]$ ps -ef | grep mix.php
nobody   24946     1  0 20:51 ?        00:00:15 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24963     1  0 20:51 ?        00:00:15 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   24981     1  0 20:51 ?        00:00:15 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   27471     1 22 21:35 ?        00:00:05 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   27522     1 18 21:35 ?        00:00:03 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
  • 測試:多跑幾次舱禽,基本穩(wěn)定在 114070.87 左右炒刁,比 12 個進(jìn)程的時候還高一點,證明再多開進(jìn)程已經(jīng)無法提升性能了誊稚,12 線程的 CPU 為何會這樣呢翔始?
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9501/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            9501

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.877 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      18100000 bytes
HTML transferred:       1300000 bytes
Requests per second:    114070.87 [#/sec] (mean)
Time per request:       8.766 [ms] (mean)
Time per request:       0.009 [ms] (mean, across all concurrent requests)
Transfer rate:          20162.92 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.0      0      33
Processing:     0    8   3.0      8      33
Waiting:        0    8   3.0      8      24
Total:          0    9   3.7      8      43

Percentage of the requests served within a certain time (ms)
  50%      8
  66%      9
  75%     10
  80%     11
  90%     12
  95%     13
  98%     18
  99%     21
 100%     43 (longest request)

Beego V1.12.1

  • 代碼:
package main

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

func main() {

    http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
        writer.Write([]byte("hello, world!"))
    })
    err := http.ListenAndServe(":9999", nil)
    if err != nil{
        fmt.Println(err)
    }

}
  • 測試:多跑幾次,基本穩(wěn)定在 107428.35 左右里伯,與 Mix 非常接近城瞎。
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8989/index
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        beegoServer:1.12.1
Server Hostname:        127.0.0.1
Server Port:            8989

Document Path:          /index
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.931 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      18200000 bytes
HTML transferred:       1300000 bytes
Requests per second:    107428.35 [#/sec] (mean)
Time per request:       9.309 [ms] (mean)
Time per request:       0.009 [ms] (mean, across all concurrent requests)
Transfer rate:          19093.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.4      0      45
Processing:     0    9   2.4      9      52
Waiting:        0    9   2.4      9      52
Total:          0    9   3.4      9      57

Percentage of the requests served within a certain time (ms)
  50%      9
  66%      9
  75%      9
  80%      9
  90%      9
  95%     15
  98%     19
  99%     24
 100%     57 (longest request)

PHP 7.3.12 + Swoole 4.4.14 二次測試

上面減少到 5 個進(jìn)程依然可以達(dá)到 12 進(jìn)程的性能,我猜測可能是 ab -c 1000 只能達(dá)到 12w 左右的并發(fā)疾瓮,也就是說沒有打滿脖镀,需要降低使用的線程數(shù)來測試,我們采用 2 個線程重新測試一下狼电。

  • 先把測試進(jìn)程減少到 2 個
[nobody@tmp]$ ps -ef | grep test.php
nobody    2200     1  0 7月22 ?       00:00:16 /usr/local/php-7.3.12/bin/php test.php
nobody    9600     1  0 10:30 ?        00:00:00 /usr/local/php-7.3.12/bin/php test.php
  • 測試:多跑幾次蜒灰,基本穩(wěn)定在 136426.58 左右
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8888/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            8888

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.733 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      16600000 bytes
HTML transferred:       1300000 bytes
Requests per second:    136426.58 [#/sec] (mean)
Time per request:       7.330 [ms] (mean)
Time per request:       0.007 [ms] (mean, across all concurrent requests)
Transfer rate:          22116.03 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.2      0      43
Processing:     2    7   1.7      6      43
Waiting:        0    7   1.7      6      19
Total:          2    7   2.9      6      53

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      6
  75%      6
  80%      7
  90%      8
  95%     10
  98%     16
  99%     18
 100%     53 (longest request)

Go 1.13.4 二次測試

  • 代碼:修改為 2 個線程
package main

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

func main() {

    runtime.GOMAXPROCS(2) // 限制使用線程數(shù)

    http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
        writer.Write([]byte("hello, world!"))
    })
    err := http.ListenAndServe(":9999", nil)
    if err != nil{
        fmt.Println(err)
    }

}

測試:多跑幾次,基本穩(wěn)定在 106834.75 左右肩碟,比 Swoole 性能低了 21.7%卷员,證明 Swoole 確實性能是高于 Go 的 net 庫。

[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9999/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:
Server Hostname:        127.0.0.1
Server Port:            9999

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   0.936 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      15400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    106834.75 [#/sec] (mean)
Time per request:       9.360 [ms] (mean)
Time per request:       0.009 [ms] (mean, across all concurrent requests)
Transfer rate:          16066.95 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.5      0      21
Processing:     0    9   1.9      9      21
Waiting:        0    9   1.9      9      17
Total:          0    9   2.3      9      30

Percentage of the requests served within a certain time (ms)
  50%      9
  66%      9
  75%     10
  80%     10
  90%     11
  95%     12
  98%     13
  99%     17
 100%     30 (longest request)

MixPHP V2.2 二次測試

  • 先把測試進(jìn)程減少到 2 個
[nobody@tmp]$ ps -ef | grep mix.php
nobody    7482     1  2 10:27 ?        00:00:05 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
nobody   27522     1  0 7月22 ?       00:00:35 /usr/local/php-7.3.12/bin/php mix/bin/mix.php web -r -d
  • 測試:多跑幾次腾务,基本穩(wěn)定在 53856.21 左右,果然削饵,按這個數(shù)據(jù)分析岩瘦,之前 12 進(jìn)程測試的數(shù)據(jù)不合理未巫,因為 ab -c 1000 沒有將 CPU 性能打滿。
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:9501/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            9501

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   1.857 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      18100000 bytes
HTML transferred:       1300000 bytes
Requests per second:    53856.21 [#/sec] (mean)
Time per request:       18.568 [ms] (mean)
Time per request:       0.019 [ms] (mean, across all concurrent requests)
Transfer rate:          9519.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.3      0      45
Processing:     0   18   5.5     17      46
Waiting:        0   18   5.5     17      38
Total:          0   18   5.6     17      55

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     18
  75%     19
  80%     20
  90%     25
  95%     29
  98%     32
  99%     33
 100%     55 (longest request)

Beego V1.12.1

  • 代碼:同樣我們限制使用 2 個線程
package main

import (
    "github.com/astaxie/beego"
    _ "hello/routers"
    "runtime"
)

type IndexController struct {
    beego.Controller
}

func (c *IndexController) Index() {
    c.Ctx.Output.Body([]byte("hello, world!"))
}

func main() {

    runtime.GOMAXPROCS(2) // 限制使用線程數(shù)

    beego.Router("/index", &IndexController{},"*:Index")

    beego.Run()

}
  • 測試:多跑幾次启昧,基本穩(wěn)定在 54547.49 左右叙凡,與 Mix 非常接近。
[nobody@~]$ ab -n 100000 -c 1000 -k http://127.0.0.1:8989/index
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        beegoServer:1.12.1
Server Hostname:        127.0.0.1
Server Port:            8989

Document Path:          /index
Document Length:        13 bytes

Concurrency Level:      1000
Time taken for tests:   1.833 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      18200000 bytes
HTML transferred:       1300000 bytes
Requests per second:    54547.49 [#/sec] (mean)
Time per request:       18.333 [ms] (mean)
Time per request:       0.018 [ms] (mean, across all concurrent requests)
Transfer rate:          9694.96 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.9      0      31
Processing:     0   18   6.3     19      40
Waiting:        0   18   6.3     19      40
Total:          0   18   6.3     19      41

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     21
  75%     22
  80%     22
  90%     24
  95%     25
  98%     28
  99%     31
 100%     41 (longest request)

總結(jié)一下

  • 第一次測試:由于 ab -c 1000 測試的性能沒有把 CPU 打滿密末,導(dǎo)致測試結(jié)果不公正握爷,應(yīng)該很多人會忽略這個問題,認(rèn)為自己的框架性能很高严里,其實是沒有打滿新啼。
語言/框架 進(jìn)/線程數(shù) 數(shù)值
PHP 7.3.12 + Swoole 4.4.14 12 127441.95
Go 1.13.4 1 <12線程> 121575.23
PHP 7.3.12 + Swoole 4.4.14 + MixPHP 2.2 12 110050.47
Go 1.13.4 + Beego 1.12.1 12 107428.35
  • 第二次測試:采用 2 線程測試比較公正,能打滿 CPU 刹碾,這樣出來的結(jié)果才是真實結(jié)果燥撞,Swoole 比 Go 性能高 21.7% (畢竟是 C 寫的),Mix 比 Swoole 原生降低了 60.5% 的性能迷帜,而 Mix 大概是 Go 原生一半的性能物舒,與 Beego 性能齊平。
語言/框架 進(jìn)/線程數(shù) 數(shù)值
PHP 7.3.12 + Swoole 4.4.14 2 136426.58
Go 1.13.4 1 <2線程> 106834.75
PHP 7.3.12 + Swoole 4.4.14 + MixPHP 2.2 2 53856.21
Go 1.13.4 + Beego 1.12.1 2 54547.49
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末戏锹,一起剝皮案震驚了整個濱河市冠胯,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌锦针,老刑警劉巖荠察,帶你破解...
    沈念sama閱讀 222,378評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異伞插,居然都是意外死亡割粮,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評論 3 399
  • 文/潘曉璐 我一進(jìn)店門媚污,熙熙樓的掌柜王于貴愁眉苦臉地迎上來舀瓢,“玉大人,你說我怎么就攤上這事耗美【┧瑁” “怎么了?”我有些...
    開封第一講書人閱讀 168,983評論 0 362
  • 文/不壞的土叔 我叫張陵商架,是天一觀的道長堰怨。 經(jīng)常有香客問我,道長蛇摸,這世上最難降的妖魔是什么备图? 我笑而不...
    開封第一講書人閱讀 59,938評論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上揽涮,老公的妹妹穿的比我還像新娘抠藕。我一直安慰自己,他們只是感情好蒋困,可當(dāng)我...
    茶點故事閱讀 68,955評論 6 398
  • 文/花漫 我一把揭開白布盾似。 她就那樣靜靜地躺著,像睡著了一般雪标。 火紅的嫁衣襯著肌膚如雪零院。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,549評論 1 312
  • 那天村刨,我揣著相機與錄音告抄,去河邊找鬼。 笑死烹困,一個胖子當(dāng)著我的面吹牛玄妈,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播髓梅,決...
    沈念sama閱讀 41,063評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼拟蜻,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了枯饿?” 一聲冷哼從身側(cè)響起酝锅,我...
    開封第一講書人閱讀 39,991評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎奢方,沒想到半個月后搔扁,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,522評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡蟋字,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,604評論 3 342
  • 正文 我和宋清朗相戀三年稿蹲,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片鹊奖。...
    茶點故事閱讀 40,742評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡苛聘,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出忠聚,到底是詐尸還是另有隱情设哗,我是刑警寧澤,帶...
    沈念sama閱讀 36,413評論 5 351
  • 正文 年R本政府宣布两蟀,位于F島的核電站网梢,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏赂毯。R本人自食惡果不足惜战虏,卻給世界環(huán)境...
    茶點故事閱讀 42,094評論 3 335
  • 文/蒙蒙 一拣宰、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧活烙,春花似錦徐裸、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,572評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽骑祟。三九已至回懦,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間次企,已是汗流浹背怯晕。 一陣腳步聲響...
    開封第一講書人閱讀 33,671評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留缸棵,地道東北人舟茶。 一個月前我還...
    沈念sama閱讀 49,159評論 3 378
  • 正文 我出身青樓,卻偏偏與公主長得像堵第,于是被迫代替她去往敵國和親吧凉。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,747評論 2 361