搜尋
首頁後端開發PHP7介紹PHP7+Swoole/Nginx/Golang性能對比

介紹PHP7+Swoole/Nginx/Golang性能對比

推薦(免費):PHP7

QPS比較

使用apache bench工具對Nginx靜態頁、Golang Http程式、PHP7 Swoole Http程式進行壓力測試。在同一台機器上,進行並發100共100萬次Http請求的基準測試中,QPS對比如下:

##軟體QPS軟體版本Nginx#164489.92nginx/1.4.6 (Ubuntu)#Golang166838.68go version go1.5.2 linux/amd64PHP7 Swoole287104.12PHP7 Swoole287104.12#PHP7 Swoole287104.12 swoole-1.7.22-alphaNginx-1.9.9
245058.70

nginx/1.9.9
  • 註:Nginx-1.9.9的測試中,已關閉access_log,啟用open_file_cache快取靜態檔案到記憶體

#更詳細的測試細節

    歷史測試資料:Nginx/Golang/Swoole/Node.js的效能比較
  • 測試環境
  • CPU:Intel® Core™ i5-4590 CPU @ 3.30GHz × 4

記憶體:16G磁碟:128G SSD

#作業系統:Ubuntu14.04 ( Linux 3.16.0-55-generic)

壓力測試工具

ab -c 100 -n 1000000 -k http://127.0.0.1: 8080/

VHOST配置

server {
    listen 80 default_server;
    root /data/webroot;
    index index.html;
}
測試頁面
<h1 id="Hello-World">Hello World!</h1>
進程數

Nginx開啟了4個Worker進程

htf@htf-All-Series:~/soft/php-7.0.0$ ps aux|grep nginx
root      1221  0.0  0.0  86300  3304 ?        Ss   12月07   0:00 nginx: master process /usr/sbin/nginx
www-data  1222  0.0  0.0  87316  5440 ?        S    12月07   0:44 nginx: worker process
www-data  1223  0.0  0.0  87184  5388 ?        S    12月07   0:36 nginx: worker process
www-data  1224  0.0  0.0  87000  5520 ?        S    12月07   0:40 nginx: worker process
www-data  1225  0.0  0.0  87524  5516 ?        S    12月07   0:45 nginx: worker process
Golang

測試程式碼

package main

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

func main() {
    runtime.GOMAXPROCS(runtime.NumCPU() - 1)

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Header().Add("Last-Modified", "Thu, 18 Jun 2015 10:24:27 GMT")
        w.Header().Add("Accept-Ranges", "bytes")
        w.Header().Add("E-Tag", "55829c5b-17")
        w.Header().Add("Server", "golang-http-server")
        w.Write([]byte("<h1 id="nHello-world-n">\nHello world!\n</h1>\n"))
    })

    log.Printf("Go http Server listen on :8080")
    log.Fatal(http.ListenAndServe(":8080", nil))
}

PHP7 Swoole

PHP7已啟用
OpCache

加速器。 PHP版本

htf@htf-All-Series:~/soft/php-7.0.0$ php -v
PHP 7.0.0 (cli) (built: Dec 10 2015 14:36:26) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
測試程式碼
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);

$http->set([
    &#39;worker_num&#39; => 4,
]);

$http->on(&#39;request&#39;, function ($request, swoole_http_response $response) {
    $response->header(&#39;Last-Modified&#39;, &#39;Thu, 18 Jun 2015 10:24:27 GMT&#39;);
    $response->header(&#39;E-Tag&#39;, &#39;55829c5b-17&#39;);
    $response->header(&#39;Accept-Ranges&#39;, &#39;bytes&#39;);    
    $response->end("<h1 id="nHello-nbsp-Swoole-n">\nHello Swoole.\n</h1>");
});

$http->start();
#相關免費學習推薦:

php程式設計#### #####(影片)############

以上是介紹PHP7+Swoole/Nginx/Golang性能對比的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:CSDN。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具