From 376bcd83e610f56daf39133149700dfedc705236 Mon Sep 17 00:00:00 2001 From: ramonn Date: Mon, 8 Jun 2009 18:36:12 +0000 Subject: [PATCH] 2009-06-08 Ramon Novoa * util/pandora_xml_stress.pl: Let the user specify the maximum number of threads. * util/pandora_xml_stress.README: Updated the documentation. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1739 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 ++ pandora_server/util/pandora_xml_stress.README | 9 ++ pandora_server/util/pandora_xml_stress.pl | 103 ++++++++++-------- 3 files changed, 75 insertions(+), 44 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 29aacc66ff..31c0f218c8 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-06-08 Ramon Novoa + + * util/pandora_xml_stress.pl: Let the user specify the maximum number + of threads. + + * util/pandora_xml_stress.README: Updated the documentation. + 2009-06-08 Sancho Leren * Header updates. diff --git a/pandora_server/util/pandora_xml_stress.README b/pandora_server/util/pandora_xml_stress.README index 45affa25a6..1bc872644c 100644 --- a/pandora_server/util/pandora_xml_stress.README +++ b/pandora_server/util/pandora_xml_stress.README @@ -18,6 +18,9 @@ Run the script like this: Sample configuration file ========================= +# Maximum number of threads, by default 10. +max_threads 10 + # File containing a list of agent names (one per line). agent_file agent_names.txt @@ -52,6 +55,12 @@ time_to 2009-06-05 00:00:00 # race conditions when auto-creating the agent, by default 2. startup_delay 2 +# Address of the Tentacle server where XML files will be sent (optional). +# server_ip 192.168.50.1 + +# Port of the Tentacle server, by default 41121. +# server_port 41121 + # Module definitions. Similar to pandora_agent.conf. module_begin diff --git a/pandora_server/util/pandora_xml_stress.pl b/pandora_server/util/pandora_xml_stress.pl index 625ce0e226..c58892ab42 100755 --- a/pandora_server/util/pandora_xml_stress.pl +++ b/pandora_server/util/pandora_xml_stress.pl @@ -24,7 +24,7 @@ use threads::shared; use Time::Local; use Time::HiRes qw(gettimeofday); -use POSIX qw (strftime); +use POSIX qw (strftime ceil); # Global variables used for statistics my $Agents :shared = 0; @@ -78,8 +78,8 @@ sub load_config ($\%\@) { ################################################################################ # Generate XML files. ################################################################################ -sub generate_xml_files ($$$) { - my ($agent_name, $conf, $modules) = @_; +sub generate_xml_files ($$$$$) { + my ($agents, $start, $step, $conf, $modules) = @_; # Read agent configuration my $interval = get_conf_token ($conf, 'interval', '300'); @@ -103,51 +103,57 @@ sub generate_xml_files ($$$) { # Generate data files my $utimestamp = $utimestamp_from; - while ($utimestamp < $utimestamp_to) { + while ($utimestamp <= $utimestamp_to) { + for (my $i = $start; $i < $start + $step; $i++) { - # XML header - my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); - my $xml_data = "\n"; - $xml_data .= "\n"; - foreach my $module (@{$modules}) { + # Get the name of the agent + last unless defined ($agents->[$i]); + my $agent_name = $agents->[$i]; - # Skip unnamed modules - my $module_name = get_conf_token ($module, 'module_name', ''); - next if ($module_name eq ''); + # XML header + my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); + my $xml_data = "\n"; + $xml_data .= "\n"; + foreach my $module (@{$modules}) { - # Read module configuration - my $module_type = get_conf_token ($module, 'module_type', 'generic_data'); - my $module_description = get_conf_token ($module, 'module_description', ''); - my $module_min = get_conf_token ($module, 'module_min', '0'); - my $module_max = get_conf_token ($module, 'module_max', '255'); - my $module_variation = get_conf_token ($module, 'module_variation', '100'); - my $module_data = get_conf_token ($module, 'module_data', ''); + # Skip unnamed modules + my $module_name = get_conf_token ($module, 'module_name', ''); + next if ($module_name eq ''); - # Generate module data - $xml_data .= "\t\n"; - $xml_data .= "\t\t$module_name\n"; - $xml_data .= "\t\t$module_description\n"; - $xml_data .= "\t\t$module_type\n"; - my $rnd_data = generate_random_data ($module_type, $module_data, $module_min, $module_max, $module_variation); - $module->{'module_data'} = $rnd_data; - $xml_data .= "\t\t$rnd_data\n"; - $xml_data .= "\t\n"; - } + # Read module configuration + my $module_type = get_conf_token ($module, 'module_type', 'generic_data'); + my $module_description = get_conf_token ($module, 'module_description', ''); + my $module_min = get_conf_token ($module, 'module_min', '0'); + my $module_max = get_conf_token ($module, 'module_max', '255'); + my $module_variation = get_conf_token ($module, 'module_variation', '100'); + my $module_data = get_conf_token ($module, 'module_data', ''); - $xml_data .= "\n"; + # Generate module data + $xml_data .= "\t\n"; + $xml_data .= "\t\t$module_name\n"; + $xml_data .= "\t\t$module_description\n"; + $xml_data .= "\t\t$module_type\n"; + my $rnd_data = generate_random_data ($module_type, $module_data, $module_min, $module_max, $module_variation); + $module->{'module_data'} = $rnd_data; + $xml_data .= "\t\t$rnd_data\n"; + $xml_data .= "\t\n"; + } - # Fix the temporal path - my $last_char = chop ($temporal); - $temporal .= $last_char if ($last_char ne '/'); + $xml_data .= "\n"; - # Save the XML data file - my $xml_file = $temporal . '/' . $agent_name . $utimestamp . '.data'; - open (FILE, ">", $xml_file) || die ("[error] Could not write to '$xml_file': $!.\n\n"); - print FILE $xml_data; - close (FILE); + # Fix the temporal path + my $last_char = chop ($temporal); + $temporal .= $last_char if ($last_char ne '/'); - copy_xml_file ($conf, $xml_file); - $XMLFiles++; + # Save the XML data file + my $xml_file = $temporal . '/' . $agent_name . '_' . $utimestamp . '.data'; + open (FILE, ">", $xml_file) || die ("[error] Could not write to '$xml_file': $!.\n\n"); + print FILE $xml_data; + close (FILE); + + copy_xml_file ($conf, $xml_file); + $XMLFiles++; + } # First run, let the server create the new agent before sending more data if ($utimestamp == $utimestamp_from) { @@ -252,16 +258,25 @@ load_config ($ARGV[0], %conf, @modules); die ("[error] No agent file specified in configuration file.\n\n") unless defined ($conf{'agent_file'}); open (FILE, "<", $conf{'agent_file'}) || die ("[error] Could not open agent configuration file '" . $conf{'agent_file'} . "': $!.\n\n"); -my $t0 = gettimeofday (); - -# Launch a thread for each agent +# Read agent names +my @agents; while (my $agent_name = ) { chomp ($agent_name); - threads->create (\&generate_xml_files, $agent_name, \%conf, \@modules); + push (@agents, $agent_name); $Agents++; } close (FILE); +# Get the maximum number of threads and the number of agents per thread +my $max_threads = get_conf_token (\%conf, 'max_threads', '10'); +$max_threads = 10 unless ($max_threads > 0); +my $step = ceil ($Agents / $max_threads); + +my $t0 = gettimeofday (); +for (my $i = 0; $i < $Agents; $i += $step) { + threads->create (\&generate_xml_files, \@agents, $i, $step, \%conf, \@modules); +} + # Log some information for the user my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime ()); my $time_from = get_conf_token (\%conf, 'time_from', $time_now);