Lasso Soft Inc. > Home

[Stress_URL]

LinkStress_URL
AuthorKe Carlton
CategoryTechnical
Version8.5.x
LicensePublic Domain
Posted17 Aug 2007
Updated17 Aug 2007
More by this author...

Description

Quick basic multi-threaded stress testing tag. It captures the URL and params posted to the current Lasso page  and spawns mulitple asynchronous threads  via include_url, it then times and displays each of the results.

Sample Usage

Simply drop the below code on any page to test it's multithreaded performance
(including form result pages etc...).

	[Stress_URL: -threadCount = 16]

Optional Parameters

-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.

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

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]*?\\',-ignoreCase)->join('');
	local:'body'	= '';	

	#header+='

Stress_URL


'; iterate:#threads,local('thread'); if:#thread->type=='pair' && !local_defined('outputnone'); #body += '
' string_findregexp( #thread->first, -find='(?<=)[\\s\\S]*?(?=)', -ignoreCase )->join('') '
'; /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(', ')+')')'
'; else; #header+='Thread #'(loop_count<10?'0')loop_count' - timed out
'; /if; /iterate; #body+=''; #header += '

'#threads->size' Thread'(#threads->size > 1?'s')': '; // Extract Averages if: local_defined('avgRegExp'); protect; handle_error; #header+=''error_currenterror'
'; /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

'; content_body = #header + '
' + #body; abort; /define_tag;

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft