Skip to content
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

🪶 在 C++ 中,有提供了Socket sendfile的方法(zerocopy),可以不通过CPU去调度资源,避免重复拷贝两次DMZ(或者更多) #5330

Open
tianxiu2b2t opened this issue May 19, 2024 · 15 comments

Comments

@tianxiu2b2t
Copy link

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error.
    发送文件时候会使内存升高,没有关闭的现状

  2. What did you expect to see?
    假死,内存溢出

  3. What did you see instead?
    修复正确关闭流文件或者是Socket

  4. What version of Swoole are you using (show your php --ri swoole)?
    最新

  5. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
    最新

@NathanFreeman
Copy link
Member

你用的是httpserver还是tcpserver

@tianxiu2b2t
Copy link
Author

http基于TCP的,理论上支持

@NathanFreeman
Copy link
Member

你是压测的过程中发现假死的吗,可以的话提供一下复现代码和压测命令

@tianxiu2b2t
Copy link
Author

我只能提供文件数量和大小,压测命令我暂时没有,但可以提供数据

@tianxiu2b2t
Copy link
Author

五分钟QPS:13570
文件数量:124k
大小:125G
最大文件大小:100MB左右
最小文件:64b或者是0b

@NathanFreeman
Copy link
Member

你是用Swoole\Http\Response::end还是Swoole\Http\Response::sendfile方法发送文件

@tianxiu2b2t
Copy link
Author

只有sendfile,没有end

@NathanFreeman
Copy link
Member

<?php
$http = new Swoole\Http\Server('127.0.0.1', 9501, SWOOLE_PROCESS);

$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', 'application/octet-stream');
    $response->header('Content-Disposition', 'attachment; filename=recvfile.txt');
    $response->sendfile('/home/sendfile.txt');
});

$http->start();

传输文件是100M的,wrk -c20000 -t4 -d120s http://127.0.0.1:9501/ 压测命令

你的服务器环境是怎么样的,代码是我这样的写法吗

@NathanFreeman
Copy link
Member

NathanFreeman commented May 19, 2024

php -m查看一下扩展列表,php --ri swoole查看一下swoole信息

@tianxiu2b2t
Copy link
Author

服务器环境:4h8g,php占用6g
php -m zstd拓展,swoole是最新版本的

@tianxiu2b2t
Copy link
Author

另外,是Swoole\Coroutine\Http\Server

@NathanFreeman
Copy link
Member

有内存泄漏,我看看是哪里的问题

@tianxiu2b2t
Copy link
Author

我怀疑是客户端正确关闭后,没有自动释放,导致有引用计数不能为0的情况
可以看看是否客户端关闭没有通知response关闭?

@tianxiu2b2t
Copy link
Author

因为连接数导致内存上涨和没有正确释放等问题

@NathanFreeman
Copy link
Member

NathanFreeman commented May 20, 2024

我测试了一下,这个应该不是内存泄漏,更有可能是因为php的内存管理机制会将小的内存块保留起来不还给操作系统。
使用Swoole\Timer::tick设置合适的时间间隔调用gc_mem_caches()强制php归还内存给操作系统试试看。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants