ホームページ  >  記事  >  バックエンド開発  >  PHP7+Swoole/Nginx/Golang のパフォーマンス比較のご紹介

PHP7+Swoole/Nginx/Golang のパフォーマンス比較のご紹介

coldplay.xixi
coldplay.xixi転載
2021-02-18 17:59:503084ブラウズ

PHP7+Swoole/Nginx/Golang のパフォーマンス比較のご紹介

推奨 (無料): PHP7

QPS の比較

Apache ベンチ ツールを使用して、Nginx 静的ページ、Golang Http プログラム、および PHP7 Swoole Http プログラムに対してストレス テストを実行します。同じマシン上で 100 万の同時 HTTP リクエストのベンチマーク テストを行った場合、QPS の比較は次のようになります。

SoftwareQPSソフトウェア バージョン##NginxGolangPHP7 Swoole##Nginx-1.9.9245058.70nginx/1.9.9#注: Nginx-1.9.9 のテストでは、access_log がオフになり、静的ファイルをメモリにキャッシュするために open_file_cache が有効になりました。 # より詳細なテストの詳細
164489.92 nginx/1.4.6 (Ubuntu)
166838.68 go バージョン go1.5.2 linux/amd64
287104.12 swoole-1.7.22-alpha
過去のテスト データ: 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;
}

テスト ページ

4a249f0d628e2318394fd9b75b4636b1Hello World!473f0a7621bec819994bb5020d29372a
プロセス数

Nginx は 4 つのワーカー プロセスをオープンしました

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("4a249f0d628e2318394fd9b75b4636b1\nHello world!\n473f0a7621bec819994bb5020d29372a\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([
    'worker_num' => 4,
]);

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

$http->start();

関連する無料学習の推奨事項:

php プログラミング

# #####(ビデオ)############

以上がPHP7+Swoole/Nginx/Golang のパフォーマンス比較のご紹介の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はcsdn.netで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。