php-fpm和swoole 最新性能对比

php-fpm框架和swoole框架性能对比

环境
对比框架
对比维度
   1:单次计算能力
   2:并发下计算能力
   3:操作数据库
测试结果
    easyswoole
    laravel
    golang
测试结果
    easyswoole
   laravel
    golang
    测试结果
结论
   计算能力解释型语言和编译型的差距还是挺大的,对mysql读写easyswoole和golang差不倒是不多。laravel差距就挺大的了

环境

deepin15.11、php7.2.9、nginx1.16.1、mysql5.7、ab2.3

对比框架

FPM框架:laravel6	,swoole框架:easyswoole3、golang1.14.2

对比维度

1:单次计算能力

php-cli

<?php
$stime = microtime(true);
for ($a=1;$a<=1000;$a++){
    for ($b=1;$b<=1000;$b++){
        for ($c=1;$c<=1000;$c++){
            if ($a == $b && $b==$c){

            }
        }
    }
}
$etime = microtime(true);
$ret = bcsub($etime,$stime,4);
var_dump($ret);

golang

func main() {
	start :=time.Now()
	for a:=1; a<=1000 ; a++ {
		for b:=1; b<=1000;b++  {
			for c:=1;c<=1000 ;c++  {
				if a== b&& b==c  {
					//fmt.Println(a*c*c)
				}
			}
		}
	}
	end := time.Now().Sub(start)
	fmt.Println(end)
}

执行结果:

  • php-cli:13.5324 s
  • golang:314.06603ms
2:并发下计算能力
  • ab -c 100 -n 10000 执行计算,循环1000000次
  • easyswoole:Time taken for tests: 47.550 seconds
  • golang:Time taken for tests: 1.337 seconds
3:操作数据库
		//easyswoole
 		$model = new UserModel();
        $model->name = "easyswoole".mt_rand(1,99999999);
        $model->create_at = date('Y-m-d H:i:s');
        $model->update_at = date('Y-m-d H:i:s');
        $model->save();
		//laravel
		$model = new User();
        $model->name = "laravel".mt_rand(1,99999999);
        $model->save();
        return $model->id;

每次100条请求,共请求一万次
ab -n 10000 -c 100
测试结果
easyswoole

Server Software:        nginx
Server Hostname:        easyswoole3.wlz.me
Server Port:            80

Document Path:          /user/index
Document Length:        0 bytes

Concurrency Level:      100
Time taken for tests:   1.774 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1340000 bytes
HTML transferred:       0 bytes
Requests per second:    5637.87 [#/sec] (mean)
Time per request:       17.737 [ms] (mean)
Time per request:       0.177 [ms] (mean, across all concurrent requests)
Transfer rate:          737.77 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.5      1       3
Processing:     8   17   5.1     16      73
Waiting:        8   16   5.1     15      72
Total:          8   18   5.1     17      73

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     17
  75%     18
  80%     18
  90%     19
  95%     22
  98%     35
  99%     42
 100%     73 (longest request)

laravel

Server Software:        nginx
Server Hostname:        la6.wlz.me
Server Port:            80

Document Path:          /test/abtest1
Document Length:        5 bytes

Concurrency Level:      100
Time taken for tests:   149.231 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      9106338 bytes
HTML transferred:       50000 bytes
Requests per second:    67.01 [#/sec] (mean)
Time per request:       1492.314 [ms] (mean)
Time per request:       14.923 [ms] (mean, across all concurrent requests)
Transfer rate:          59.59 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       3
Processing:    66 1485 574.9   1423    7027
Waiting:       63 1485 574.9   1423    7027
Total:         66 1485 574.9   1423    7027

Percentage of the requests served within a certain time (ms)
  50%   1423
  66%   1471
  75%   1503
  80%   1524
  90%   1585
  95%   1656
  98%   2056
  99%   5498
 100%   7027 (longest request)

golang

func save(w http.ResponseWriter, r *http.Request)  {
	defer r.Body.Close()
	mysql_sqx.InsertRow()
	w.Write([]byte("ok"))
}

// 插入数据
func InsertRow() {
	sqlStr := "insert into w_users(name, created_at,updated_at) values (?,?,?)"
	ret, err := db.Exec(sqlStr, "wlz11", "2020-04-09 11:51:59","2020-04-09 11:51:59")
	if err != nil {
		fmt.Printf("insert failed, err:%v\n", err)
		return
	}
	theID, err := ret.LastInsertId() // 新插入数据的id
	if err != nil {
		fmt.Printf("get lastinsert ID failed, err:%v\n", err)
		return
	}
	fmt.Printf("insert success, the id is %d.\n", theID)
}

```bash

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            9090

Document Path:          /save
Document Length:        2 bytes

Concurrency Level:      100
Time taken for tests:   1.687 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1180000 bytes
HTML transferred:       20000 bytes
Requests per second:    5925.95 [#/sec] (mean)
Time per request:       16.875 [ms] (mean)
Time per request:       0.169 [ms] (mean, across all concurrent requests)
Transfer rate:          682.87 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.4      1       3
Processing:     5   16   2.0     16      34
Waiting:        5   16   2.0     15      34
Total:          7   17   2.0     16      35

Percentage of the requests served within a certain time (ms)
  50%     16
  66%     17
  75%     17
  80%     18
  90%     18
  95%     19
  98%     23
  99%     25
 100%     35 (longest request)
读数据

取100条数据

	//easyswoole
	$data = UserModel::create()->where("id >=30000")->limit(100)->all();
    $this->response()->write(json_encode($data));
	//laravel
 	return DB::table('users')
            ->where('id', '>=',30000)
            ->limit(100)
            ->get();

每次100条请求,共请求一万次
ab -n 10000 -c 100

测试结果

easyswoole

Server Software:        nginx
Server Hostname:        easyswoole3.wlz.me
Server Port:            80

Document Path:          /user/index
Document Length:        10807 bytes

Concurrency Level:      100
Time taken for tests:   3.898 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      109680000 bytes
HTML transferred:       108070000 bytes
Requests per second:    2565.20 [#/sec] (mean)
Time per request:       38.983 [ms] (mean)
Time per request:       0.390 [ms] (mean, across all concurrent requests)
Transfer rate:          27475.72 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       7
Processing:     5   39  12.6     36     192
Waiting:        2   38  12.6     35     187
Total:          5   39  12.6     36     192

Percentage of the requests served within a certain time (ms)
  50%     36
  66%     39
  75%     41
  80%     43
  90%     55
  95%     64
  98%     75
  99%     82
 100%    192 (longest request)

laravel

Server Software:        nginx
Server Hostname:        la6.wlz.me
Server Port:            80

Document Path:          /test/abtest1
Document Length:        10807 bytes

Concurrency Level:      100
Time taken for tests:   148.857 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      117046492 bytes
HTML transferred:       108070000 bytes
Requests per second:    67.18 [#/sec] (mean)
Time per request:       1488.570 [ms] (mean)
Time per request:       14.886 [ms] (mean, across all concurrent requests)
Transfer rate:          767.87 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       5
Processing:    67 1480 799.2   1380    8338
Waiting:       60 1480 799.2   1380    8338
Total:         67 1480 799.2   1380    8338

Percentage of the requests served within a certain time (ms)
  50%   1380
  66%   1426
  75%   1456
  80%   1477
  90%   1542
  95%   1615
  98%   1935
  99%   7050
 100%   8338 (longest request)

golang

每次100条请求,共请求一万次
ab -n 10000 -c 100


func main() {
	http.HandleFunc("/find",findAll)
	http.HandleFunc("/",index)
	http.ListenAndServe("127.0.0.1:9090",nil)
}
func findAll(w http.ResponseWriter, r *http.Request)  {
	defer r.Body.Close()
	userList,err := mysql_sqx.FindAll()
	if err != nil {
		fmt.Printf("query failed, err:%v\n", err)
	}
	userListStr,_ := json.Marshal(userList)
	w.Write([]byte(userListStr))
}

func FindAll() ([]WUser, error) {
	sqlStr := "select * from w_users where id>? limit ?"
	userList := make([]WUser,0,2)
	err := db.Select(&userList, sqlStr,30000,100)
	if err != nil {
		return nil, nil
	}
	return userList,err
}

测试结果

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            9090

Document Path:          /find
Document Length:        10604 bytes

Concurrency Level:      100
Time taken for tests:   1.408 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      107010000 bytes
HTML transferred:       106040000 bytes
Requests per second:    7100.29 [#/sec] (mean)
Time per request:       14.084 [ms] (mean)
Time per request:       0.141 [ms] (mean, across all concurrent requests)
Transfer rate:          74199.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       3
Processing:     1   14   8.0     13      62
Waiting:        0   13   8.0     12      62
Total:          1   14   8.0     13      63

Percentage of the requests served within a certain time (ms)
  50%     13
  66%     16
  75%     19
  80%     20
  90%     25
  95%     29
  98%     33
  99%     37
 100%     63 (longest request)
结论

1. 计算能力测试

– 请求1次,循环计算100亿次
easyswoole耗时:13.5324秒
golang耗时    :0.314秒

– 并发数100,请求量1万次,单次计算内容循环100万次
easyswoole:Time taken for tests: 47.550 seconds
golang    :Time taken for tests: 1.337 seconds

2. 操作数据库

插入数据耗时:
golang    :1.687秒
easyswoole: 1.774秒
laravel   :149.231 秒
读数据耗时:
golang    :1.408秒
easyswoole: 3.898 秒
laravel   :148.857

计算能力解释型语言和编译型的差距还是挺大的,对mysql读写easyswoole和golang差不倒是不多。laravel差距就挺大的了

———————————————————————————————————————————
原文链接

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值