[Bio] / Sprout / AttrTime.pl Repository:
ViewVC logotype

Annotation of /Sprout/AttrTime.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     =head1 Attribute Time Test
4 :    
5 :     This simple script tests the performance on the attribute server in
6 :     multiple-PEG queries. Each test takes a PEG set and computes
7 :     the mean time required to run the attribute request by running
8 :     multiple trials. The user can specify a single test, multiple
9 :     tests with different sizes, or multiple tests with a single size.
10 :    
11 :     The currently-supported command-line options are as follows.
12 :    
13 :     =over 4
14 :    
15 :     =item user
16 :    
17 :     Name suffix to be used for log files. If omitted, the PID is used.
18 :    
19 :     =item trace
20 :    
21 :     Numeric trace level. A higher trace level causes more messages to appear. The
22 :     default trace level is 2. Tracing will be directly to the standard output
23 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
24 :     where I<User> is the value of the B<user> option above.
25 :    
26 :     =item sql
27 :    
28 :     If specified, turns on tracing of SQL activity.
29 :    
30 :     =item background
31 :    
32 :     Save the standard and error output to files. The files will be created
33 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
34 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
35 :     B<user> option above.
36 :    
37 :     =item h
38 :    
39 :     Display this command's parameters and options.
40 :    
41 :     =item phone
42 :    
43 :     Phone number to message when the script is complete.
44 :    
45 :     =item count
46 :    
47 :     Number of pegs to test. The default is 100.
48 :    
49 :     =item trials
50 :    
51 :     Number of trials. The default is 50.
52 :    
53 :     =item tests
54 :    
55 :     Number of separate PEG sets to test.
56 :    
57 :     =item increment
58 :    
59 :     Number of PEGs to add for each test. If this is 0, every test will be for the
60 :     same number of PEGs.
61 :    
62 :     =back
63 :    
64 :     =cut
65 :    
66 :     use strict;
67 :     use Tracer;
68 :     use Cwd;
69 :     use File::Copy;
70 :     use File::Path;
71 :     use FIG;
72 :     use Time::HiRes qw(time);
73 :    
74 :     # Get the command-line options and parameters.
75 :     my ($options, @parameters) = StandardSetup([qw(FIG) ],
76 :     {
77 :     trace => [2, "tracing level"],
78 :     count => [100, "number of PEGs per trial"],
79 :     trials => [50, "number of trials"],
80 :     tests => [1, "number of PEG sets to test"],
81 :     increment => [100, "number of PEGs to add between tests"],
82 :     phone => ["", "phone number (international format) to call when load finishes"],
83 :     },
84 :     "",
85 :     @ARGV);
86 :     # Set a variable to contain return type information.
87 :     my $rtype;
88 :     # Insure we catch errors.
89 :     eval {
90 :     # Get a FIG object.
91 :     my $fig = FIG->new();
92 :     # Do one test at a time.
93 :     for (my $test = 1; $test <= $options->{tests}; $test++) {
94 :     # Compute the number of PEGs for this test.
95 :     my $pegCount = $options->{count} + $options->{increment}*($test - 1);
96 :     Trace("Preparing test $test for $pegCount PEGs.") if T(3);
97 :     # Now get the genomes.
98 :     my %genomes = map { $_ => 1 } $fig->genomes();
99 :     # This gives us the genomes in a mixed-up order.
100 :     my @genomeList = keys %genomes;
101 :     # Compute the number of PEGs per genome. We allow for the possibility of some genomes
102 :     # not having enough, so it's not a straight division.
103 :     my $pegsPerGenome = int(4 * $pegCount / scalar(@genomeList));
104 :     $pegsPerGenome = 10 if $pegsPerGenome < 10;
105 :     # Now we accumulate the PEGs in a hash.
106 :     my %pegs = ();
107 :     Trace("Accumulating PEGs at a rate of $pegsPerGenome per genome.") if T(2);
108 :     # Loop until we have enough PEGs.
109 :     while (scalar(keys %pegs) < $pegCount && scalar(@genomeList)) {
110 :     # Get a genome.
111 :     my $genome = pop @genomeList;
112 :     Trace("Pulling PEGs from $genome.") if T(3);
113 :     # Get some of its pegs in subsystems.
114 :     my @newPegs = $fig->assigned_pegs_in_subsystems($genome);
115 :     for (my $i = 0; $i <= $#newPegs && $i <= $pegsPerGenome; $i++) {
116 :     $pegs{$newPegs[$i]} = 1;
117 :     }
118 :     }
119 :     # Get the PEGs into a list and reduce it to the correct size.
120 :     my @keyList = keys %pegs;
121 :     while (scalar(@keyList) > $pegCount) {
122 :     pop @keyList;
123 :     }
124 :     my $count = scalar(@keyList);
125 :     Trace("$count PEGs accumulated.") if T(2);
126 :     # Now we have our pegs. Try the retrieval and time it.
127 :     my $seconds = 0;
128 :     for (my $i = 0; $i < $options->{trials}; $i++) {
129 :     my @attrs;
130 :     my $now = time();
131 :     @attrs = $fig->get_attributes(\@keyList, "evidence_code");
132 :     $seconds += time() - $now;
133 :     }
134 :     my $actualTime = $seconds / $options->{trials};
135 :     Trace("$count pegs processed in $actualTime seconds.") if T(2);
136 :     }
137 :     Trace("Tests complete.") if T(2);
138 :     };
139 :     if ($@) {
140 :     Trace("Script failed with error: $@") if T(0);
141 :     $rtype = "error";
142 :     } else {
143 :     Trace("Script complete.") if T(2);
144 :     $rtype = "no error";
145 :     }
146 :     if ($options->{phone}) {
147 :     my $msgID = Tracer::SendSMS($options->{phone}, "Attribute Time Test terminated with $rtype.");
148 :     if ($msgID) {
149 :     Trace("Phone message sent with ID $msgID.") if T(2);
150 :     } else {
151 :     Trace("Phone message not sent.") if T(2);
152 :     }
153 :     }
154 :    
155 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3