Skip to content

Commit fe2923c

Browse files
authored
Merge pull request #608 from NathanFreeman/fix_swoole_error
Fix Swoole error
2 parents 8b7bda5 + a6a01db commit fe2923c

47 files changed

Lines changed: 256 additions & 20048 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frameworks/swoole/PostgreSQL.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ class PostgreSQL
77

88
public static function init(): void
99
{
10-
$parts = parse_url(getenv('DATABASE_URL'));
10+
$dsn = getenv('DATABASE_URL');
11+
if (!$dsn) {
12+
return;
13+
}
14+
15+
$parts = parse_url($dsn);
1116
$host = $parts['host'] ?? 'localhost';
1217
$port = $parts['port'] ?? 5432;
1318
$db = ltrim($parts['path'] ?? '/benchmark', '/');

frameworks/swoole/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"pipelined",
1313
"limited-conn",
1414
"json",
15+
"json-tls",
1516
"json-comp",
1617
"upload",
1718
"static",
@@ -20,4 +21,4 @@
2021
"api-16",
2122
"async-db"
2223
]
23-
}
24+
}

frameworks/swoole/swoole.php

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535

3636
$http = new Server('0.0.0.0', 8080);
3737
$http->set([
38-
'worker_num' => swoole_cpu_num(),
39-
'enable_reuse_port' => true,
40-
'enable_coroutine' => false,
41-
'package_max_length' => 30 * 1024 * 1024,
42-
'http_compression_level' => 0
38+
'worker_num' => swoole_cpu_num(),
39+
'enable_reuse_port' => true,
40+
'enable_coroutine' => false,
41+
'package_max_length' => 30 * 1024 * 1024
4342
]);
4443

4544
$http->on('workerStart', function (Server $server, int $workerId) {
@@ -67,13 +66,13 @@
6766

6867
if (preg_match('#^/json/(\d+)$#', $path, $matches)) {
6968
$count = min((int)$matches[1], count($dataset));
70-
$m = (int)($request->get['m'] ?? 1);
69+
$m = (int)($request->get['m'] ?? 1);
7170
if ($m === 0) $m = 1;
7271
$items = [];
7372
for ($i = 0; $i < $count; $i++) {
74-
$item = $dataset[$i];
73+
$item = $dataset[$i];
7574
$item['total'] = $item['price'] * $item['quantity'] * $m;
76-
$items[] = $item;
75+
$items[] = $item;
7776
}
7877
$response->header['Content-Type'] = 'application/json';
7978
$response->end(json_encode(['items' => $items, 'count' => $count], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
@@ -120,11 +119,40 @@
120119

121120
$port = $http->listen('0.0.0.0', 8443, SWOOLE_TCP | SWOOLE_SSL);
122121
$port->set([
123-
'open_http2_protocol' => true,
124-
'ssl_cert_file' => '/certs/server.crt',
125-
'ssl_key_file' => '/certs/server.key',
126-
'package_max_length' => 30 * 1024 * 1024,
127-
'http_compression_level' => 0,
122+
'open_http2_protocol' => true,
123+
'ssl_cert_file' => '/certs/server.crt',
124+
'ssl_key_file' => '/certs/server.key',
125+
'package_max_length' => 30 * 1024 * 1024
128126
]);
129127

128+
$port2 = $http->listen('0.0.0.0', 8081, SWOOLE_TCP | SWOOLE_SSL);
129+
$port2->set([
130+
'ssl_cert_file' => '/certs/server.crt',
131+
'ssl_key_file' => '/certs/server.key',
132+
'package_max_length' => 30 * 1024 * 1024,
133+
'http_compression' => false,
134+
'open_http_protocol' => true,
135+
]);
136+
$port2->on('request', function (Request $request, Response $response) use ($dataset) {
137+
$path = $request->server['request_uri'];
138+
if (preg_match('#^/json/(\d+)$#', $path, $matches)) {
139+
$count = min((int)$matches[1], count($dataset));
140+
$m = (int)($request->get['m'] ?? 1);
141+
if ($m === 0) $m = 1;
142+
$items = [];
143+
for ($i = 0; $i < $count; $i++) {
144+
$item = $dataset[$i];
145+
$item['total'] = $item['price'] * $item['quantity'] * $m;
146+
$items[] = $item;
147+
}
148+
$response->header['Content-Type'] = 'application/json';
149+
$response->end(json_encode(['items' => $items, 'count' => $count], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
150+
return;
151+
}
152+
153+
$response->status(404);
154+
$response->header['Content-Type'] = 'text/plain';
155+
$response->end('404 Not Found');
156+
});
157+
130158
$http->start();

site/data/api-16-1024.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -903,28 +903,28 @@
903903
{
904904
"framework": "Swoole",
905905
"language": "PHP",
906-
"rps": 131689,
907-
"avg_latency": "5.99ms",
908-
"p99_latency": "42.90ms",
909-
"cpu": "1757.8%",
910-
"memory": "258.8MiB",
906+
"rps": 133274,
907+
"avg_latency": "5.95ms",
908+
"p99_latency": "46.20ms",
909+
"cpu": "1759.5%",
910+
"memory": "261MiB",
911911
"connections": 1024,
912912
"threads": 64,
913913
"duration": "5s",
914914
"pipeline": 1,
915-
"bandwidth": "668.41MB/s",
916-
"input_bw": "7.41MB/s",
917-
"reconnects": 395033,
918-
"status_2xx": 1975335,
915+
"bandwidth": "676.57MB/s",
916+
"input_bw": "7.50MB/s",
917+
"reconnects": 399781,
918+
"status_2xx": 1999119,
919919
"status_3xx": 0,
920920
"status_4xx": 0,
921921
"status_5xx": 0,
922-
"tpl_baseline": 740859,
923-
"tpl_json": 741149,
922+
"tpl_baseline": 749605,
923+
"tpl_json": 750086,
924924
"tpl_db": 0,
925925
"tpl_upload": 0,
926926
"tpl_static": 0,
927-
"tpl_async_db": 493323
927+
"tpl_async_db": 499424
928928
},
929929
{
930930
"framework": "uvicorn",

site/data/api-4-256.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -903,28 +903,28 @@
903903
{
904904
"framework": "Swoole",
905905
"language": "PHP",
906-
"rps": 46045,
907-
"avg_latency": "4.12ms",
908-
"p99_latency": "27.50ms",
909-
"cpu": "406.4%",
910-
"memory": "214.7MiB",
906+
"rps": 46212,
907+
"avg_latency": "3.99ms",
908+
"p99_latency": "27.40ms",
909+
"cpu": "403.4%",
910+
"memory": "228MiB",
911911
"connections": 256,
912912
"threads": 64,
913913
"duration": "5s",
914914
"pipeline": 1,
915-
"bandwidth": "233.65MB/s",
916-
"input_bw": "2.59MB/s",
917-
"reconnects": 138121,
918-
"status_2xx": 690680,
915+
"bandwidth": "234.55MB/s",
916+
"input_bw": "2.60MB/s",
917+
"reconnects": 138616,
918+
"status_2xx": 693190,
919919
"status_3xx": 0,
920920
"status_4xx": 0,
921921
"status_5xx": 0,
922-
"tpl_baseline": 259149,
923-
"tpl_json": 258945,
922+
"tpl_baseline": 260027,
923+
"tpl_json": 260030,
924924
"tpl_db": 0,
925925
"tpl_upload": 0,
926926
"tpl_static": 0,
927-
"tpl_async_db": 172586
927+
"tpl_async_db": 173133
928928
},
929929
{
930930
"framework": "uvicorn",

site/data/async-db-1024.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -713,19 +713,19 @@
713713
{
714714
"framework": "Swoole",
715715
"language": "PHP",
716-
"rps": 243187,
717-
"avg_latency": "3.66ms",
718-
"p99_latency": "17.70ms",
719-
"cpu": "4269.3%",
720-
"memory": "270.9MiB",
716+
"rps": 237024,
717+
"avg_latency": "3.67ms",
718+
"p99_latency": "26.30ms",
719+
"cpu": "4403.6%",
720+
"memory": "243MiB",
721721
"connections": 1024,
722722
"threads": 64,
723723
"duration": "5s",
724724
"pipeline": 1,
725-
"bandwidth": "940.11MB/s",
726-
"input_bw": "16.23MB/s",
727-
"reconnects": 96968,
728-
"status_2xx": 2431871,
725+
"bandwidth": "916.39MB/s",
726+
"input_bw": "15.82MB/s",
727+
"reconnects": 94672,
728+
"status_2xx": 2370240,
729729
"status_3xx": 0,
730730
"status_4xx": 0,
731731
"status_5xx": 0

site/data/baseline-4096.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,19 +1008,19 @@
10081008
{
10091009
"framework": "Swoole",
10101010
"language": "PHP",
1011-
"rps": 2034436,
1012-
"avg_latency": "2.01ms",
1013-
"p99_latency": "8.16ms",
1014-
"cpu": "6532.1%",
1015-
"memory": "211.5MiB",
1011+
"rps": 2086943,
1012+
"avg_latency": "1.96ms",
1013+
"p99_latency": "10.00ms",
1014+
"cpu": "6531.3%",
1015+
"memory": "202MiB",
10161016
"connections": 4096,
10171017
"threads": 64,
10181018
"duration": "5s",
10191019
"pipeline": 1,
1020-
"bandwidth": "300.65MB/s",
1021-
"input_bw": "157.16MB/s",
1020+
"bandwidth": "308.41MB/s",
1021+
"input_bw": "161.21MB/s",
10221022
"reconnects": 0,
1023-
"status_2xx": 10172183,
1023+
"status_2xx": 10434717,
10241024
"status_3xx": 0,
10251025
"status_4xx": 0,
10261026
"status_5xx": 0

site/data/baseline-512.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,19 +1008,19 @@
10081008
{
10091009
"framework": "Swoole",
10101010
"language": "PHP",
1011-
"rps": 2035856,
1012-
"avg_latency": "250us",
1013-
"p99_latency": "3.31ms",
1014-
"cpu": "6714.5%",
1015-
"memory": "201.6MiB",
1011+
"rps": 2027259,
1012+
"avg_latency": "252us",
1013+
"p99_latency": "3.38ms",
1014+
"cpu": "6732.9%",
1015+
"memory": "194MiB",
10161016
"connections": 512,
10171017
"threads": 64,
10181018
"duration": "5s",
10191019
"pipeline": 1,
1020-
"bandwidth": "300.86MB/s",
1021-
"input_bw": "157.27MB/s",
1020+
"bandwidth": "299.60MB/s",
1021+
"input_bw": "156.60MB/s",
10221022
"reconnects": 0,
1023-
"status_2xx": 10179282,
1023+
"status_2xx": 10136298,
10241024
"status_3xx": 0,
10251025
"status_4xx": 0,
10261026
"status_5xx": 0

site/data/baseline-h2-1024.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,18 @@
376376
{
377377
"framework": "Swoole",
378378
"language": "PHP",
379-
"rps": 1254047,
380-
"avg_latency": "74.92ms",
381-
"p99_latency": "74.92ms",
382-
"cpu": "5187.5%",
383-
"memory": "259.3MiB",
379+
"rps": 1599781,
380+
"avg_latency": "59.09ms",
381+
"p99_latency": "59.09ms",
382+
"cpu": "6687.6%",
383+
"memory": "257MiB",
384384
"connections": 1024,
385385
"threads": 64,
386386
"duration": "5s",
387387
"pipeline": 1,
388-
"bandwidth": "32.33MB/s",
389-
"input_bw": "",
388+
"bandwidth": "41.81MB/s",
390389
"reconnects": 0,
391-
"status_2xx": 6270311,
390+
"status_2xx": 8110893,
392391
"status_3xx": 0,
393392
"status_4xx": 0,
394393
"status_5xx": 0

site/data/baseline-h2-256.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,18 @@
376376
{
377377
"framework": "Swoole",
378378
"language": "PHP",
379-
"rps": 1328208,
380-
"avg_latency": "20.74ms",
381-
"p99_latency": "20.74ms",
382-
"cpu": "5428.1%",
383-
"memory": "201.4MiB",
379+
"rps": 1602268,
380+
"avg_latency": "16.65ms",
381+
"p99_latency": "16.65ms",
382+
"cpu": "6719.2%",
383+
"memory": "206MiB",
384384
"connections": 256,
385385
"threads": 64,
386386
"duration": "5s",
387387
"pipeline": 1,
388-
"bandwidth": "34.21MB/s",
389-
"input_bw": "",
388+
"bandwidth": "41.51MB/s",
390389
"reconnects": 0,
391-
"status_2xx": 6641111,
390+
"status_2xx": 8059411,
392391
"status_3xx": 0,
393392
"status_4xx": 0,
394393
"status_5xx": 0

0 commit comments

Comments
 (0)