The performance of swoole is higher than that of golang?

Code of swoole

<?php
$http = new swoole_http_server("127.0.0.1", 9501);

$http->on("start", function ($server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$http->on("request", function ($request, $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$http->start();

Code of golang

package main
import (
    "io"
    "net/http"
)
func main() {
    http.HandleFunc("/", handle)
    http.ListenAndServe("0.0.0.0:10056", nil)
}
func handle(rw http.ResponseWriter, r *http.Request) {
    rw.Header().Set("Content-Type", "text/html")
    io.WriteString(rw, "<h3>http server</h3>")
}

are all tested on my machine

ab-n 30000-c 100 "http://127.0.0.1:10056/"

swoole results

Server Software:        swoole-http-server
Server Hostname:        127.0.0.1
Server Port:            9501

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   1.910 seconds
Complete requests:      30000
Failed requests:        0
Total transferred:      4830000 bytes
HTML transferred:       360000 bytes
Requests per second:    15708.78 [-sharp/sec] (mean)
Time per request:       6.366 [ms] (mean)
Time per request:       0.064 [ms] (mean, across all concurrent requests)
Transfer rate:          2469.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   0.5      3       8
Processing:     1    4   0.9      3      18
Waiting:        0    3   0.9      2      16
Total:          2    6   0.9      6      21
WARNING: The median and mean for the processing time are not within a normal deviation
        These results are probably not that reliable.
WARNING: The median and mean for the waiting time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      6
  75%      7
  80%      7
  90%      7
  95%      7
  98%      8
  99%      9
 100%     21 (longest request)

golang results

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            10056

Document Path:          /
Document Length:        20 bytes

Concurrency Level:      100
Time taken for tests:   4.364 seconds
Complete requests:      30000
Failed requests:        0
Total transferred:      3630000 bytes
HTML transferred:       600000 bytes
Requests per second:    6873.89 [-sharp/sec] (mean)
Time per request:       14.548 [ms] (mean)
Time per request:       0.145 [ms] (mean, across all concurrent requests)
Transfer rate:          812.25 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    6   4.6      5      54
Processing:     0    9   5.8      7      63
Waiting:        0    7   4.4      6      50
Total:          0   14   8.7     12     101

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     14
  75%     15
  80%     16
  90%     20
  95%     28
  98%     47
  99%     59
 100%    101 (longest request)
Oct.09,2021

swoole runs in cooperation, go runs in series, are you embarrassed?


https://wiki.swoole.com/wiki/.

IO Model
go language uses single-threaded eventloop to handle IO events, multithreading implements cooperative scheduling, executes user-level code
swoole uses multithreaded eventloop to handle IO events, and multi-process executes user-level php code
Go is single-threaded to handle IO events and cannot utilize multiple cores, and its throughput is slightly weaker than swoole
in actual TCP/UDP dense IO stress tests, swoole performs better than go

copy and paste is a bit watery.
this is determined by language characteristics. We can't evaluate whether the performance is good or not. Each has its own advantages.


look at the version. Forget what the article saw. High concurrency under go 1.9 will cause lock contention, and the scope of locks is too large. Subsequent versions refine the scope of locks


this kind of test is unscientific. This is not called performance testing.
your handler only has a simple output page, and there is no actual processing logic. Try the same complex computing logic. Db operation, which one is faster?
this test can only show that go is not as good as swoole on I answer O scheduling


Swoole is a multithreaded event polling IO. Golang is a thread event polling. In theory, Swoole can accept more connections at the same time.

however, Swoole is the PHP code that executes, executes user code through the Worker process, executes asynchronous logic through the Task process, and communicates through pipes or message queues.

in fact, the execution efficiency is much lower than that of golang. Especially a lot of unoptimized PHP code. Coupled with the fact that interprocess communication is not necessarily faster than locked channel.

Menu