Link | Stress_URL |
Author | Ke Carlton |
Category | Technical |
Version | 8.5.x |
License | Public Domain |
Posted | 17 Aug 2007 |
Updated | 17 Aug 2007 |
More by this author... |
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.
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.
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+='