-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] stream_select
memory leak
#209
Comments
I have not observed any memory leaks or file descriptor leaks. The memory pool mechanism in PHP only supports one-way expansion. It does not support contraction, so the memory usage will stay at its peak and eventually stabilize at a specific value. Afterward, memory usage is no longer directly related to the number of requests made. Furthermore, based on my local testing results, the memory usage and file descriptor count show consistent results whether the Swow extension is enabled or disabled. Can you provide your test data for further investigation of the issue? |
I using swow from https://github.com/hyperf/box
and my RAM keeps increasing. This won't happen on native php, Is the problem in https://github.com/hyperf/box? do you have any ideas? |
You can use the following method to check the number of file descriptors for the corresponding process to determine if there is indeed a leak. If the issue does exist, I am more inclined to believe it is a compatibility issue with the React code (or differences in operating systems), as Swow is not specifically designed for frameworks like React. Hyperf Box is more suitable for building Hyperf projects, and for high-performance, I would recommend using Hyperf. Using both Box and React, you won't be able to gain any benefits from Box.
|
with the |
Could you use |
|
a simpler test case to reproduce this bug: <?php
$socket = stream_socket_server("tcp://localhost:8000", $errno, $errstr);
if (!$socket) {
die("Error: $errno - $errstr");
}
$clients = array($socket);
while (true) {
$read = $clients;
$write = $except = null;
if (stream_select($read, $write, $except, null) === false) {
break;
}
if (in_array($socket, $read)) {
$newClient = stream_socket_accept($socket);
if ($newClient) {
$clients[] = $newClient;
echo "New client connected\n";
}
unset($read[array_search($socket, $read)]);
}
foreach ($read as $client) {
$data = fread($client, 1024);
if ($data === false) {
$key = array_search($client, $clients);
fclose($client);
unset($clients[$key]);
} elseif ($data === '') {
$key = array_search($client, $clients);
fclose($client);
unset($clients[$key]);
echo "Client disconnected\n";
} else {
$response = "HTTP/1.1 200 OK\r\n";
$response .= "Content-Type: text/plain\r\n";
$response .= "Content-Length: 12\r\n\r\n";
$response .= "Hello, world";
fwrite($client, $response);
}
}
}
fclose($socket); |
Describe the bug / 问题描述
Test with
react/http
packageTest with
wrk -t4 -c400 -d10s http://127.0.0.1:8080
memory keeps increasing in 3 runs this command. The file descriptors don't seem to be closed.Expected behavior / 正确的行为
No leaks
Outputs / 程序输出
Runtime Environment / 运行环境
The text was updated successfully, but these errors were encountered: