加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl 压力测试脚本

发布时间:2020-12-16 00:25:36 所属栏目:大数据 来源:网络整理
导读:收到一个接收get请求的压力测试的需求, require LWP::UserAgent;##LWP是perl的http请求模块 use strict; use POSIX qw(strftime);##输出时间 use threads; ##threads~~~ my $addr = "http://192.168.244.128/"; my @threads; ? ?? sub ? getDRqureyURL() ??
收到一个接收get请求的压力测试的需求,
require LWP::UserAgent;##LWP是perl的http请求模块
use strict;
use POSIX qw(strftime);##输出时间
use threads; ##threads~~~
my $addr = "http://192.168.244.128/";
my @threads;
? ??
sub ? getDRqureyURL() ??
{?
my ($l,$DRqureyURL,$phoneNumber)=@_;##获取所有参数
my$ua= LWP::UserAgent->new;
$ua->timeout(1);##设置timeout时间,通常是10+,这里是测试
$ua->env_proxy;##获得环境变量
my$response=$ua->get($DRqureyURL);##get
if($response->is_success){
print$response->decoded_content;# or whatever :P
}
else{
die$response->status_line;
}
print $l.' '.$phoneNumber.' '.strftime("%Y-%m-%d %H:%M:%Sn",localtime(time));
}
my $j;?
my $i;
open (TEST,"phonenumber.txt");
my $line ;
for ($j = 0;$j < 2;$j++)
{
$i=0;
while($i<20) ??
{
$line = <TEST>;
? ? if (!$line)
? ? {
print "end of file,reopen.";##最后一行为空
open (TEST,"phonenumber.txt");
$line = <TEST>;
}
chop($line );##排除换行符
$threads[$i] ?= ? threads->new(&;getDRqureyURL,? $i,? $addr,? $line); ?
$i++;
}
foreach my $thread (@threads) {
$thread->join();##回收thread
}
}
close (TEST);##关闭test句柄

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读