Menu Content/Inhalt
Home arrow Perl development
Perl development
Simulate login storm PDF Print E-mail
Written by Martin   
Monday, 27 July 2009

I wanted to test whether a particular login trigger makes any difference to login times. So I came up with the following perl script:

#!/u01/app/oracle/product/10.2.0/db_1/perl/bin/perl

use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use DBI;

my $dbh;
my $serviceName = "DEV';
my $numIterations = 200;
my $start = [gettimeofday];

foreach my $i (1..$numIterations) {

$dbh = DBI->connect( "dbi:Oracle:$serviceName",
"user", "password", { RaiseError => 1, AutoCommit => 0 });

if ( $i % 50 == 0 ) {
print "$i connects done\n";
}

$dbh->disconnect if defined $dbh;
}

my $end = [gettimeofday];

my $duration = tv_interval($start, $end);

print "\n\nduration for all executions is $duration\n";

This did the trick for me. Keep in mind that you shouldn't run any code in production that you haven't tested, including this one! You might need to set environment variables (refer to my article "Make use of Oracle's perl").

On a final note the login trigger had no negative performance impact, which I could prove.

Last Updated ( Monday, 27 July 2009 )
 
Sort output for Proc::ProcessTable PDF Print E-mail
Written by Martin   
Monday, 20 April 2009

Simple way of listing the top-n processes using Proc::ProcessTable.

Generate some load:

# dd if=/dev/hda | gzip > /dev/null

Then check if we can get the top-n processes:

#!/usr/bin/perl
use strict;
use warnings;
use Proc::ProcessTable;
use Data::Dumper;
sub list_top_n_processes {
my ($topNProcesses) = @_;

$topNProcesses = 10 unless defined $topNProcesses;

my $t = new Proc::ProcessTable;

my @procArray;

foreach my $p (@{$t->table}) {
push(@procArray, {fname=>$p->fname,pct_cpu=>$p->pctcpu }) if ( $p->pctcpu > 0 );

}

my $cnt = 0;

for my $ref ( sort { $b->{pct_cpu} <=> $a->{pct_cpu} } @procArray ) {

last if $cnt == $topNProcesses;

print Dumper($ref);

$cnt++;
}
}

# main

list_top_n_processes();

And here you go!

Last Updated ( Monday, 20 April 2009 )
 
Pass a hash to a subroutine PDF Print E-mail
Written by Martin   
Friday, 30 January 2009

This is a code snippet demonstrating how you pass a hash to a function (also called "subroutine") in perl speak. Remeber that you pass scalar variables to perl functions.

package A;

...
sub f {
my %hash1 = (
tag_name => 'memory'

);

my %hash2 = (
tag_name => 'swap'
);

$someObjectReference->g(\%hash1, \%hash2);
...
}

So how do you use this now in the receiving function?

Last Updated ( Friday, 30 January 2009 )
Read more...
 
Make use of Oracle's perl PDF Print E-mail
Written by Martin   
Wednesday, 21 January 2009

It's funny how many versions of PERL you can find on your system, especially on Linux. I usually have the distribution's perl, then maybe an activestate version of the same and finally there is a perl executable installed with Oracle as well.

Now I know how to make use of the distribution's perl executables because all environment variables are already set, but what about Oracle's perl? The following sections assume a 11.1.0.7 SE ORACLE_HOME on RHEL 5.

Last Updated ( Wednesday, 21 January 2009 )
Read more...
 
Add more repositories on the command line PDF Print E-mail
Written by Martin   
Tuesday, 26 August 2008

I am a great fan of the Active State Perl distribution, especially on Windows. As you know, Windows isn't a real operating system since it doesn't come with a decent compiler so you have to resort to other means instead of a "perl Makefile.pl - make - make install". Using the precompiled perl modules really is the only way out of that.

However, you don't get all the packages from Activestate, some of them are simply missing.But don't fear - there are two other important ppm repositories that you can add to your ppm application:

  • Trouchelle
  • University of Winnipeg
Here's a sample session of my Windows command line session:
C:\temp>ppm rep add trouchelle.com http://trouchelle.com/ppm/
Downloading trouchelle.com packlist...done
Updating trouchelle.com database...done
Repo 2 added.
C:\temp>ppm rep add http://theoryx5.uwinnipeg.ca/ppms/
Downloading theoryx5.uwinnipeg.ca packlist...done
Updating theoryx5.uwinnipeg.ca database...done
Repo 3 added.
It is that easy sometimes.
Last Updated ( Wednesday, 17 September 2008 )
 
<< Start < Prev 1 2 Next > End >>

Results 1 - 9 of 12