search
HomeBackend DevelopmentPHP7Introducing PHP7+Swoole/Nginx/Golang performance comparison

Introducing PHP7+Swoole/Nginx/Golang performance comparison

Recommended (free): PHP7

QPS comparison

Use the apache bench tool to perform stress testing on Nginx static pages, Golang Http programs, and PHP7 Swoole Http programs. In the benchmark test of 1 million concurrent HTTP requests on the same machine, the QPS comparison is as follows:

##SoftwareQPSSoftware versionNginx164489.92nginx/1.4.6 (Ubuntu)Golang166838.68go version go1.5.2 linux/amd64PHP7 Swoole287104.12 swoole-1.7.22-alpha##Nginx-1.9.9
245058.70 nginx/1.9.9
Note: In the test of Nginx-1.9.9, access_log has been turned off and open_file_cache is enabled to cache static files into memory

More detailed test details
  • Historical test data: Performance comparison of Nginx/Golang/Swoole/Node.js
Test environment

CPU: Intel® Core™ i5-4590 CPU @ 3.30GHz × 4
  • Memory: 16G
  • Disk: 128G SSD
  • Operating system: Ubuntu14.04 ( Linux 3.16.0-55-generic)
Stress testing tool

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

VHOST configuration

server {
    listen 80 default_server;
    root /data/webroot;
    index index.html;
}

Test page

<h1 id="Hello-World">Hello World!</h1>

Number of processes

Nginx has opened 4 Worker processes

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

Test Code

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 has the

OpCache

accelerator enabled. PHP version

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

Test code

$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();

Related free learning recommendations:

php programming(video)

The above is the detailed content of Introducing PHP7+Swoole/Nginx/Golang performance comparison. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment