我正在尝试运行 10.000 个进程来创建星号电话帐户。 这是为了对我们的 Asterisk 服务器进行压力测试。
我用 php 调用了一个 exec() 函数来创建一个 Linux 命令。
nohup /usr/src/pjproject-2.3/pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu --id=sip:%s@13.113.163.3 --registrar=sip:127.0.0.1:25060 --realm=* --username=%s --password=123456 --local-port=%s --null-audio --no-vad --max-calls=32 --no-tcp >>/dev/null 2>>/dev/null & $(echo -ne \'\r\')"
一切都很完美,脚本也完全符合我的预期。 但是下一个问题也来了;创建 10.000 个帐户后,进程突然全部被杀死。
这是为什么?
nohup 函数不就是让进程保持事件状态吗? 调用 nohup 函数后,我还调用了 disown 函数。
谢谢你的帮助
[编辑] 我也用功能屏幕尝试了这个项目,屏幕功能很有魅力,但问题是 cpu 使用率。要创建 10.000 个屏幕,会使 Linux 服务器发疯,这就是我选择 nohup 的原因。
完整的php代码:
<?php
# count
$count_screens = 0;
# port count start
$port_count = 30000;
# register accounts number
$ext_number = 1000;
# amount of times you want this loop to go
$min_accounts = 0;
$max_accounts = 1000;
Class shell {
const CREATE_SESSION = 'screen -dmS stress[%s]';
const RUN_PJSUA = 'screen -S stress[%s] -p 0 -rX stuff "nohup /usr/src/pjproject-2.3/pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu --id=sip:%s@13.113.163.3 --registrar=sip:127.0.0.1:25060 --realm=* --username=%s --password=123456 --local-port=%s --null-audio --no-vad --max-calls=32 --no-tcp >>/dev/null 2>>/dev/null &"';
const DISOWN_PJSUA = 'screen -S stress[%s] -p 0 -rX stuff "disown -l $(echo -ne \'\r\')"';
public function openShell($count_screens) {
# creating a new screen to make the second call
$command = sprintf(static:: CREATE_SESSION, $count_screens);
$string = exec($command);
return var_dump($string);
}
public function runPJSUA($count_screens, $ext_number, $ext_number, $port_count) {
# register a new pjsua client
$command = sprintf(static:: RUN_PJSUA, $count_screens, $ext_number, $ext_number, $port_count);
$string = exec($command);
usleep(20000);
return var_dump($string);
}
public function disownPJSUA($count_screens) {
# register a new pjsua client
$command = sprintf(static:: DISOWN_PJSUA, $count_screens);
$string = exec($command);
return var_dump($string);
}
}
while ($min_accounts < $max_accounts) {
$shell = new shell();
if ($count_screens == '0') {
$count_screens++;
echo $shell->openShell($count_screens);
} else {
$count_screens = 1;
}
$port_count++;
$ext_number++;
$min_accounts++;
echo $shell->runPJSUA($count_screens, $ext_number, $ext_number, $port_count);
echo $shell->disownPJSUA($count_screens);
}
?>
最佳答案
Pjsua 是比较重的应用程序,运行 10000 个实例肯定太重了,不适合这种测试。当您为 32 个调用配置它时,即使端口用完也会成为问题(每个调用保留两个端口加上 SIP 端口)。如果您想继续使用 pjsua,您至少可以通过为单个 pjsua 实例配置多个帐户来优化测试。它可能受命令行长度的限制,但每个实例大约 30 个帐户可能有效。
关于php - nohup 进程不断关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50524652/