IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> PHP知识库 -> php-fpmworkermanswoolegolang简单性能测试 -> 正文阅读

[PHP知识库]php-fpmworkermanswoolegolang简单性能测试

测试环境:

操作系统:CentOS Linux release 7.6.1810 (Core)? 单核2G云服务器

PHP版本:PHP 7.4.21

golang版本:1.17

workerman:4.0.22(已安装event扩展)

swoole:4.7.0

测试工具:ab ,webbench

测试的脚本

测试脚本比较简单,产生1000个100-999的随机数,计算随机数的和然后输出

php

$sum = 0;
foreach(range(1,1000) as $i){
    $sum += mt_rand(100,1000);
}
echo "sum=$sum";

go

package main

import (
	"fmt"
	"math/rand"
	"net/http"
	"time"
)

func main() {

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		var sum int
		rand.Seed(time.Now().UnixNano())
		for index := 1; index <= 1000; index++ {
			sum += rand.Intn(900) + 100
		}

		w.Write([]byte(fmt.Sprintf("sum=%d", sum)))
	})

	http.ListenAndServe("127.0.0.1:8000", nil)

}

ab测试结果:

测试命令:ab -n 100000 -c 100 http://127.0.0.1:端口/

1,php-fpm

Concurrency Level:      100
Time taken for tests:   26.163 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      18900000 bytes
HTML transferred:       1000000 bytes
Requests per second:    3822.12 [#/sec] (mean)
Time per request:       26.163 [ms] (mean)
Time per request:       0.262 [ms] (mean, across all concurrent requests)
Transfer rate:          705.45 [Kbytes/sec] received

2,workerman(使用webman框架测试)

Concurrency Level:      100
Time taken for tests:   12.198 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      13100000 bytes
HTML transferred:       1000000 bytes
Requests per second:    8198.21 [#/sec] (mean)
Time per request:       12.198 [ms] (mean)
Time per request:       0.122 [ms] (mean, across all concurrent requests)
Transfer rate:          1048.79 [Kbytes/sec] received

3,swoole异步http server

Concurrency Level:      100
Time taken for tests:   11.454 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      15800000 bytes
HTML transferred:       1000000 bytes
Requests per second:    8730.33 [#/sec] (mean)
Time per request:       11.454 [ms] (mean)
Time per request:       0.115 [ms] (mean, across all concurrent requests)
Transfer rate:          1347.06 [Kbytes/sec] received

4,swoole协程http server

Concurrency Level:      100
Time taken for tests:   10.579 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      15800000 bytes
HTML transferred:       1000000 bytes
Requests per second:    9453.09 [#/sec] (mean)
Time per request:       10.579 [ms] (mean)
Time per request:       0.106 [ms] (mean, across all concurrent requests)
Transfer rate:          1458.58 [Kbytes/sec] received

5,golang http server

Concurrency Level:      100
Time taken for tests:   11.433 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      12700000 bytes
HTML transferred:       1000000 bytes
Requests per second:    8746.31 [#/sec] (mean)
Time per request:       11.433 [ms] (mean)
Time per request:       0.114 [ms] (mean, across all concurrent requests)
Transfer rate:          1084.75 [Kbytes/sec] received

rps比较:swoole协程http server >?golang http server =?swoole异步http server >?workerman > php-fpm?

webbench测试结果

测试命令:webbench -c 100 -t 30 http://127.0.0.1/

1,php-fpm

Benchmarking: GET http://127.0.0.1/test.php
100 clients, running 30 sec.

Speed=210944 pages/min, 664473 bytes/sec.
Requests: 105472 susceed, 0 failed.

2,workerman(使用webman框架测试)

Benchmarking: GET http://127.0.0.1:8787/
100 clients, running 30 sec.

Speed=466696 pages/min, 1018952 bytes/sec.
Requests: 233348 susceed, 0 failed.

3,swoole异步http server

Benchmarking: GET http://127.0.0.1:9501/
100 clients, running 30 sec.

Speed=491948 pages/min, 1295463 bytes/sec.
Requests: 245974 susceed, 0 failed.

4,swoole协程http server


Benchmarking: GET http://127.0.0.1:9502/
100 clients, running 30 sec.

Speed=542284 pages/min, 1428014 bytes/sec.
Requests: 271142 susceed, 0 failed.

5,golang http server

Benchmarking: GET http://127.0.0.1:8000/
100 clients, running 30 sec.

Speed=498384 pages/min, 1054912 bytes/sec.
Requests: 249192 susceed, 0 failed.

webbench的测试结果和ab差不多

测试代码比较简单,没有进行文件IO操作,数据库操作等,结果仅供参考,workerman这种纯php框架能有这样的性能还是不错的

  PHP知识库 最新文章
Laravel 下实现 Google 2fa 验证
UUCTF WP
DASCTF10月 web
XAMPP任意命令执行提升权限漏洞(CVE-2020-
[GYCTF2020]Easyphp
iwebsec靶场 代码执行关卡通关笔记
多个线程同步执行,多个线程依次执行,多个
php 没事记录下常用方法 (TP5.1)
php之jwt
2021-09-18
上一篇文章      下一篇文章      查看所有文章
加:2021-11-30 15:23:36  更:2021-11-30 15:24:11 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/14 14:29:25-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码