简体   繁体   English

Perl 期望生成限制

[英]Perl Expect spawn limit

For performance issue and duration optimization, i want to know who limits my number of SSH connections.对于性能问题和持续时间优化,我想知道谁限制了我的 SSH 连接数。

A BASH script is calling X perl scripts. BASH 脚本正在调用 X perl 脚本。 Each perl scripts spawn a new SSH connection towards a different IP.每个 perl 脚本都会生成一个指向不同 IP 的新 SSH 连接。

So, this is how it works :所以,这就是它的工作原理:

max_proc_ssh=400

while read codesite ip operateur hostname
do 
    (sleep 3; /usr/bin/perl $DIR/RTR-sshscript.pl $codesite $ip $operateur $hostname) &
        ((current_proc_ssh++))
    if [ $current_proc_ssh -eq $max_proc_ssh ]; then
        printf "Pausing with $max_proc_ssh processes...\n"
        current_proc_ssh=0
        wait
    fi
done<<<"$temp_info"

And each RTR-sshscript.pl spawns a new Expect with a SSH connection and send a lot of commands, the duration is about 3minutes并且每个 RTR-sshscript.pl 生成一个新的 Expect 和一个 SSH 连接并发送很多命令,持续时间大约为 3 分钟

$exp->spawn("ssh -o ConnectTimeout=$connectTimeout $user\@$ip") or die ("unable to spawn \n");

So, with max_proc_ssh=200 i have no issue.所以, max_proc_ssh=200我没有问题。 Scripts are going well.脚本进展顺利。 But when i'm going with max_proc_ssh=400 , the Expect module cannot handle it.但是当我使用 max_proc_ssh=400 时,Expect 模块无法处理它。 It sometimes tells me **unable to spawn** I would say that, from the 400 expected, only 350 really starts, something like that.有时它会告诉我**unable to spawn**我会说,从预期的 400 次开始,只有 350 次真正开始,类似这样。

What is wrong with this ?这有什么问题? i am trying to define a sublimit to avoid launching 400 expects at the same time, something like :我正在尝试定义一个子限制以避免同时启动 400 个期望,例如:

max_proc_ssh=400
max_sublimit_ssh=200

while read codesite ip operateur hostname
do 
    (sleep 3; /usr/bin/perl $DIR/RTR-sshscript.pl $codesite $ip $operateur $hostname) &
    ((current_proc_ssh++))
    ((current_sublimit_ssh++))
    if [ $current_sublimit_ssh -eq $max_sublimit_ssh ]; then
        printf "Pausing sublimit SSH reached..."
        sleep 3
        current_sublimit_ssh=0
    fi
    if [ $current_proc_ssh -eq $max_proc_ssh ]; then
        printf "Pausing with $max_proc_ssh processes...\n"
        current_proc_ssh=0
        current_sublimit_ssh=0
        wait
    fi
done<<<"$temp_info"

This would allow SSH to launch 200 Expect, then waits 3 secondes before launching 200 again.这将允许 SSH 启动 200 Expect,然后在再次启动 200 之前等待 3 秒。 And then, wait for all 400 to finish before starting again.然后,等待所有 400 完成后再重新开始。

EDIT : As described in the comment section, i added "$!"编辑:如评论部分所述,我添加了“$!” to the error message and then i have this :到错误消息,然后我有这个:

./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable
./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable
./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable
./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable
./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable
./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable
./../../../scripts/mynet/RTR-scan-snmp.sh: fork: retry: Resource temporarily unavailable

What does that mean ?这意味着什么 ? I am overwhelming the fork limit ?我压倒了分叉限制? How can I increase it ?我怎样才能增加它? By modifying the sysctl.conf file ?通过修改 sysctl.conf 文件?

When searching a little by myself, they say check what当我自己搜索时,他们说检查什么

sysctl fs.file-nr

is saying But when i start the script, it doesn't go higher than this :是说但是当我启动脚本时,它不会比这更高:

 sysctl fs.file-nr
fs.file-nr = 27904      0       793776

the ulimit for my user is 4096 But when the script starts, the counter goes way higher than this :我的用户的 ulimit 是4096但是当脚本启动时,计数器比这个高得多:

 sudo lsof -u restools 2>/dev/null | wc -l
25258

It appears that it's not a process limitation, but the opened-file limitation.看来这不是进程限制,而是打开文件限制。

Adding these line :添加这些行:

restools         soft    nproc           2048
restools         soft    nofile          2048

to /etc/security/limits.conf file solved the issue !/etc/security/limits.conf文件解决了这个问题! The first line limits the number of active process to 2048 And the second, the number of opened files to 2048 Both of them was previously 1024第一行将活动进程数限制为 2048 第二行将打开文件数限制为 2048 之前都是 1024

Tested, and approved经过测试和批准

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM