期望脚本中的性能瓶颈

时间:2013-07-26 23:04:43

标签: performance shell sed expect

我试图找出我的脚本中的一点,这会减慢我的整个过程。我正在使用expect脚本发送sed命令来搜索和替换文件中的一行。这需要2到20秒才能完成,而不应该持续超过一秒钟。我两个期望在两个终端中并行编写脚本。第一个文件launchmpj.exp启动一个需要几秒钟才能启动的qsub作业。第二个文件launchneuron.exp等待qsub作业启动并继续执行脚本。当qsub作业启动时,launchmpj.exp发送一个命令,允许第二个文件launchneuron.exp知道qsub作业已启动并停止等待。

这是launchmpj.exp

#!/usr/bin/expect -f
set timeout -1
spawn ssh $::env(username)@server
expect "$ " 
send "qsub -I -q berger -A lc_tb -l nodes=\$nbnodes -l walltime=24:00:00 -d .\r"
expect "$ "
send "cp \$PBS_NODEFILE node`sed -n '1p' nodequeue`\r"
expect "$ "
send "sed -i '/wait=on/ s//wait=off/' `sed -n '1p' qsubwaitqueue`\r"
expect "$ "
send "cd $::env(MPJ_HOME)/bin\r"
expect "$ "
send "sh $::env(MPJLAUNCH)\r"
expect "Process 6 ended"

这是第二个文件launchneuron.exp

#!/usr/bin/expect -f
set timeout -1
spawn ssh $::env(username)@server
expect "$ " 
send "set qsubwait = qsub`sed -n '\$p' queue`.sh\r"
expect "$ "
send "sh \$qsubwait\r"
expect "$ " 
send "set nodefile = node`sed -n '1p' nodequeue`\r"
expect "$ "
send "ssh `sed -n '2'p \$nodefile`\r"
expect "$ "
send "cd $::env(NEURON_HOME)\r"
expect "$ " 
send "nrniv -python $::env(NEURONPY)\r"
expect "$ "

作为整个过程的一部分,我在下面的文件中运行sed替换。仅sed的执行速度非常快,这意味着它不是上述脚本的瓶颈。但是,当从expect脚本完成时,就需要很长时间。

sed -i '/wait=on/ s//wait=off/' qsubwait.sh

档案qsubwait.sh

wait=on
echo "Waiting for qsub to start."
while [ $wait = on ]; do
eval `sed -n '1'p qsubwait.sh`
echo `sed -n '1'p qsubwait.sh`
done

1 个答案:

答案 0 :(得分:0)

你是否达到了预期的超时值?使用exp_internal 1运行您的期望脚本,以查看期望等待的内容。

相关问题