Compare commits

..
Author SHA1 Message Date
Chirag Aggarwal 4b72f7ca2d fix issues in opensrs adapter 2025-09-25 16:39:57 +05:30
3 changed files with 21 additions and 24 deletions
+4 -9
View File
@@ -48,7 +48,6 @@ $http = new Server(
$payloadSize = 12 * (1024 * 1024); // 12MB - adding slight buffer for headers and other data that might be sent with the payload - update later with valid testing
$totalWorkers = intval(System::getEnv('_APP_CPU_NUM', swoole_cpu_num())) * intval(System::getEnv('_APP_WORKER_PER_CORE', 6));
$nextWorker = new \Swoole\Atomic\Long(0); // lockfree counter for roundrobin idleworker selection
/**
* Assigns HTTP requests to worker threads by analyzing its payload/content.
@@ -68,14 +67,12 @@ $nextWorker = new \Swoole\Atomic\Long(0); // lockfree counter for roundrob
function dispatch(Server $server, int $fd, int $type, $data = null): int
{
$resolveWorkerId = function (Server $server, $data = null) {
global $totalWorkers, $domains, $nextWorker;
$start = $nextWorker->add(1) % $totalWorkers; // ringbuffer start index
global $totalWorkers, $domains;
// If data is not set we can send request to any worker
// first we try to pick idle worker, if not we randomly pick a worker
if ($data === null) {
for ($offset = 0; $offset < $totalWorkers; $offset++) {
$i = ($start + $offset) % $totalWorkers;
for ($i = 0; $i < $totalWorkers; $i++) {
if ($server->getWorkerStatus($i) === SWOOLE_WORKER_IDLE) {
return $i;
}
@@ -111,8 +108,7 @@ function dispatch(Server $server, int $fd, int $type, $data = null): int
if ($risky) {
// If risky request, only consider risky workers
for ($offset = 0; $offset < ($totalWorkers - $riskyWorkers); $offset++) {
$j = ($start + $riskyWorkers + $offset) % $totalWorkers;
for ($j = $riskyWorkers; $j < $totalWorkers; $j++) {
/** Reference https://openswoole.com/docs/modules/swoole-server-getWorkerStatus#description */
if ($server->getWorkerStatus($j) === SWOOLE_WORKER_IDLE) {
// If idle worker found, give to him
@@ -128,8 +124,7 @@ function dispatch(Server $server, int $fd, int $type, $data = null): int
// If safe request, give to any idle worker
// Its fine to pick risky worker here, because it's idle. Idle is never actually risky
for ($offset = 0; $offset < $totalWorkers; $offset++) {
$i = ($start + $offset) % $totalWorkers;
for ($i = 0; $i < $totalWorkers; $i++) {
if ($server->getWorkerStatus($i) === SWOOLE_WORKER_IDLE) {
return $i;
}
+1 -1
View File
@@ -54,7 +54,7 @@
"utopia-php/config": "0.2.*",
"utopia-php/database": "1.*",
"utopia-php/detector": "0.1.*",
"utopia-php/domains": "0.8.*",
"utopia-php/domains": "dev-fix-opensrs-issues",
"utopia-php/dns": "0.3.*",
"utopia-php/dsn": "0.2.1",
"utopia-php/framework": "0.33.*",
Generated
+16 -14
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7553e976312b0423cc31544abb91caec",
"content-hash": "e4f4c6c853c774c989c09eb8c2b30e70",
"packages": [
{
"name": "adhocore/jwt",
@@ -3792,16 +3792,16 @@
},
{
"name": "utopia-php/domains",
"version": "0.8.0",
"version": "dev-fix-opensrs-issues",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/domains.git",
"reference": "650463d2a1525273eb03223c48da9fb1a768bbf7"
"reference": "9984a2d5c86098e56741e3506800aa220e8bc3c8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/domains/zipball/650463d2a1525273eb03223c48da9fb1a768bbf7",
"reference": "650463d2a1525273eb03223c48da9fb1a768bbf7",
"url": "https://api.github.com/repos/utopia-php/domains/zipball/9984a2d5c86098e56741e3506800aa220e8bc3c8",
"reference": "9984a2d5c86098e56741e3506800aa220e8bc3c8",
"shasum": ""
},
"require": {
@@ -3847,9 +3847,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/domains/issues",
"source": "https://github.com/utopia-php/domains/tree/0.8.0"
"source": "https://github.com/utopia-php/domains/tree/fix-opensrs-issues"
},
"time": "2025-05-16T10:03:59+00:00"
"time": "2025-09-25T11:08:25+00:00"
},
{
"name": "utopia-php/dsn",
@@ -3939,16 +3939,16 @@
},
{
"name": "utopia-php/framework",
"version": "0.33.28",
"version": "0.33.27",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/http.git",
"reference": "5aaa94d406577b0059ad28c78022606890dc6de0"
"reference": "d9d10a895e85c8c7675220347cc6109db9d3bd37"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/http/zipball/5aaa94d406577b0059ad28c78022606890dc6de0",
"reference": "5aaa94d406577b0059ad28c78022606890dc6de0",
"url": "https://api.github.com/repos/utopia-php/http/zipball/d9d10a895e85c8c7675220347cc6109db9d3bd37",
"reference": "d9d10a895e85c8c7675220347cc6109db9d3bd37",
"shasum": ""
},
"require": {
@@ -3980,9 +3980,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/http/issues",
"source": "https://github.com/utopia-php/http/tree/0.33.28"
"source": "https://github.com/utopia-php/http/tree/0.33.27"
},
"time": "2025-09-25T10:44:24+00:00"
"time": "2025-09-07T18:40:53+00:00"
},
{
"name": "utopia-php/image",
@@ -8518,7 +8518,9 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"stability-flags": {
"utopia-php/domains": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {