Here's a simple script that executes some SQL as often as possible. I've used it to e.g. measure the overhead of Java stored procedures in Sybase and stuff like that, but I think any SQL statement should work as long as it doesn't return billions and billions of rows. Check out the
DBD::Oracle docs on how to form the connect string.
Start as many instances if you need to simulate many connections.
#!/usr/bin/perl -w
$|++;
use strict;
use Time::HiRes qw/time/;
use DBI;
use DBD::Sybase;
my ($dbi, $user, $pass, $sql, $logEvery) = @ARGV or die(q{
Syntax:
call_sp connect_string user password sql
Example:
call_sp dbi:Sybase:server=DEV_DB_01_DS;database=test_performance sa PA
+SSWORD "exec jpl_test"
});
$logEvery ||= 200;
my $dbh = DBI->connect(
$dbi,
$user,
$pass,
{ RaiseError => 1, PrintError => 0 }
);
my $sth = $dbh->prepare($sql);
my @aOldAverage;
my $maxOldAverage = 10;
my $no = 0;
my $timeLatest = time();
while(1) {
if($no++ > $logEvery) {
my $timeNow = time();
my $timeDuration = $timeNow - $timeLatest;
my $freq = sprintf("%0.2d", $no / ($timeDuration || 1));
$timeLatest = $timeNow;
$no = 0;
push(@aOldAverage, $freq);
if(@aOldAverage > $maxOldAverage) {
shift(@aOldAverage);
}
my $oldCount = @aOldAverage;
my $sum = 0;
$sum += $_ for(@aOldAverage);
my $avg = sprintf("%0.2d", $sum / $oldCount);
print localtime() . ": $freq / sec ($avg/sec for the last $old
+Count readings)\n";
}
eval { $sth->execute(); };
if($@) {
warn("$@\n");
$sth = $dbh->prepare($sql);
next;
}
$sth->fetchall_arrayref;
$sth->finish;
}
__END__
If you need more complex behaviour, you may need to develop a robot (bot) user that simulates typical behaviour with a proper mix of idle time, selects, inserts, etc. If most of the time is spent idle, look into POE (or something like that) to run hundreds or thousands of users in a single process. Start more processes until the machine can't handle any more, then add extra machines.
/J
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.