1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
define_tag:'Stress_URL',
-optional = 'url',
-optional = 'postparams',
-optional = 'delay',
-optional = 'username',
-optional = 'password',
-optional = 'avgRegExp';
/*
// Tag to Stress any Lasso page
//
// Simply drop the below code on any page to test it multithreaded.
// (including form result pages etc...)
//
// [Stress_URL: -threadCount = 16]
//
// -threadCount: amount of threads to spawn (<=128 depending on machine)
// -avgRegExp: allows you to specify a regular expression to extract
// and average values from the included pages.
//
// -delay: inserts a inline delay between each thread (milliseconds)
// -jitter: max random async delay between each thread (milliseconds)
// -outputnone: don't include pages in output.
//
// *Warning* this tag is limited by Lasso's include_url tag
// for full load testing I would recommend one of the many
// stand alone tools available. This tag is useful for quick
// and dirty load testing during development.
//
// *Warning #2* you can overload Lasso with this tag, use with
// caution - ideally on a development machine.
/
// Please post changes / comments to www.tagswap.net/Stress_URL
//
// Copyright K Carlton 2007
//
*/
client_postParams >> 'isThread' ? return;
lasso_executiontimelimit:0;
// Async Tag
define_tag: 'include_thread',
-required = 'url',
-optional = 'username',
-optional = 'password',
-required = 'postparams', -copy,
-required = 'thread',
-required = 'counter',
-optional = 'jitter',
-async;
handle_error;
local('thread') = pair('error'=error_currenterror);
/handle_error;
local:'params' = array;
local('username')->type != 'null' ? #params->insert( '-username' = local('username'));
local('password')->type != 'null' ? #params->insert( '-password' = local('password'));
#params-> insert(local('url'));
#postParams-> insert('isThread' = 'true');
#params-> insert('-POSTParams'= #postParams);
local('jitter') > 0 ? sleep:math_random(-lower=0,-upper=#jitter);
local:'timer' = _date_msec;
local:'result' = \include_url->run(-params=#params)->exportstring('utf-8');
local:'time' = string(math_round(decimal(math_mult((_date_msec - #timer),0.001)),0.01))->padLeading(5,'0')&;
#thread = pair(#result=#time+' seconds, 'date->format('%H:%M:%S')' (finished #'(#counter<9?'0')#counter++')');
/define_tag;
!local_defined('url') ? local:'url' = client_url;
!local_defined('threadCount') ? local:'threadCount' = 4;
!local_defined('postparams') ? local:'postparams' = client_postParams;
local:'threads' = string('~'*#threadCount)->split('');
local:'timer' =_date_msec;
local:'counter' = 0;
// Trigger Async Threads
iterate:#threads,local('thread');
sleep:integer(local('delay'));
include_thread: -url = #url,
-username = local('username'),
-password = local('password'),
-postparams = #postparams,
-thread = @#thread,
-counter = @#counter,
-jitter = integer(local('jitter'));
/iterate;
// Wait For Threads
while:#threads >> '~';
sleep:100;
loop_count > 6000 ? loop_abort;
/while;
// Extract HTML
local:'header' = string_findregexp(#threads->first->first,-find='[\\s\\S]*?\\<body\\>',-ignoreCase)->join('');
local:'body' = '';
#header+='<h1>Stress_URL</h1><BR>';
iterate:#threads,local('thread');
if:#thread->type=='pair' && !local_defined('outputnone');
#body += '<div style="width:50%;float:left;">'
string_findregexp( #thread->first,
-find='(?<=<body>)[\\s\\S]*?(?=</body>)',
-ignoreCase
)->join('')
'</div>';
/if;
if:#thread != '~';
#header+='Thread #'(loop_count<10?'0')loop_count' - '#thread->second;
#header+=(local_defined('avgRegExp') ? ' (Score: '+string_findregexp(#thread->first,-find=#avgRegExp)->join(', ')+')')'<br>';
else;
#header+='Thread #'(loop_count<10?'0')loop_count' - timed out<br>';
/if;
/iterate;
#body+='</body></html>';
#header += '<br><h3>'#threads->size' Thread'(#threads->size > 1?'s')': ';
// Extract Averages
if: local_defined('avgRegExp');
protect;
handle_error;
#header+='<b style="color:#F00">'error_currenterror'</b><br>';
/handle_error;
local:'average' = 0.00;
local:'averages'= string_findregexp(#body,-find=#avgRegExp);
iterate:#averages,local('avg');
#average+=decimal(#avg);
/iterate;
local:'average' = math_round(math_div(#average,#threads->size),1);
local:'seconds' = math_round(decimal(math_mult((_date_msec - #timer),0.001)),0.1);
#header += #average' Avg Score, ';
/protect;
/if;
#header += #seconds' seconds total</h3>';
content_body = #header + '<hr>' + #body;
abort;
/define_tag;
|