/[rserv]/misc/rserv_test.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /misc/rserv_test.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Tue Aug 5 09:52:40 2003 UTC revision 1.4 by dpavlin, Sun Aug 10 13:52:29 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl -w
2    
3    # original version by Nélio Alves Pereira Filho
4    # modification by Dobrica Pavlinusic
5    
6    use strict;
7  use Pg;  use Pg;
8  use Getopt::Long;  use Getopt::Long;
9  use POSIX ":sys_wait_h";  use POSIX ":sys_wait_h";
10    
11    
12  $| = 1;  $| = 1;
13  $control = 0;  my $control = 0;
14    
15    my ($numprocs,$numstmts) = (4,100);
16  $result = GetOptions("numprocs=i", "numstmts=i", "help");  my ($debug,$verbose) = (0,0);
17  if (defined($opt_help)) {  my ($help,$host,$port,$user,$password);
18      print "Usage: $0 --numprocs=number_of_processes --numstmts=number_of_statements\n";  
19      print "\n";  my $result = GetOptions(
20      exit(0);          "debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help,
21            "host=s" => \$host, "port=i" => \$port,
22            "user=s" => \$user, "password=s" => \$password,
23            "numprocs=i" => \$numprocs, "numstmts=i" => \$numstmts,
24            );
25    
26    if (defined($help) || (scalar(@ARGV) < 3)) {
27        print "Usage: $0 [options] db table column
28    Options:
29            --host=hostname --port=port
30            --user=username --password=string
31            --numprocs=4 --numstmts=100
32    ";
33        exit ((scalar(@ARGV) < 3)? 1:0);
34  }  }
35    
   
 my $numprocs = $opt_numprocs || 4;  
 my $numstmts = $opt_numstmts || 100;  
   
36  print STDERR "Running $numprocs threads, $numstmts inserts each\n";  print STDERR "Running $numprocs threads, $numstmts inserts each\n";
37    
38  my $info = "dbname=immanis host=kelly user=root";  my $db = $ARGV[0] || "master";
39  #my $info = "dbname=replicate host=alicia user=nelio";  my $table = $ARGV[1];
40    my $col = $ARGV[2];
41    
42    my $info = "dbname=$db";
43    $info = "$info host=$host" if (defined($host));
44    $info = "$info port=$port" if (defined($port));
45    $info = "$info user=$user" if (defined($user));
46    $info = "$info password=$password" if (defined($password));
47    
48  my @pids = ();  my @pids = ();
49  for ($i=0; $i < $numprocs; $i++) {  my $q;
50      if (($pid = fork()) == 0) {  
51    for (my $i=0; $i < $numprocs; $i++) {
52        my $pid = fork();
53        if (! defined($pid)) {
54            print "Can't fork...\n";
55            exit;
56        } elsif ($pid == 0) {
57          doInserts($i+1);          doInserts($i+1);
58          exit;          exit;
59      } elsif ($pid != undef) {      } elsif ($pid) {
60          push @pids, $pid;          push @pids, $pid;
61      }      }
62  }  }
63    
64  foreach $pid (@pids) {  foreach my $pid (@pids) {
65      my $x = -1;      my $x = -1;
66      do {      do {
67          sleep(1);          sleep(1);
# Line 48  foreach $pid (@pids) { Line 73  foreach $pid (@pids) {
73  #########################  #########################
74    
75  sub doInserts {  sub doInserts {
76      ($pid) = @_;      my ($pid) = @_;
77      print "<$pid> Running...\n";      print "<$pid> Running...\n";
78    
79      $conn = Pg::connectdb($info);      my $conn = Pg::connectdb($info);
80      if ($conn->status != PGRES_CONNECTION_OK) {      if ($conn->status != PGRES_CONNECTION_OK) {
81          print "<$pid> Failed opening $info\n";          print "<$pid> Failed opening $info\n";
82          print "<$pid> Abort!\n";          print "<$pid> Abort!\n";
# Line 66  sub doInserts { Line 91  sub doInserts {
91      }      }
92            
93      print "<$pid> Inserting $numstmts records...\n";      print "<$pid> Inserting $numstmts records...\n";
94      $sql = "INSERT INTO test (value) VALUES";      my $sql = "INSERT INTO $table ($col) VALUES";
95      for ($i = 0; $i < $numstmts; $i++) {      for (my $i = 0; $i < $numstmts; $i++) {
96          $time = time;          my $time = time;
97          $q = "$sql ('test_${pid}_${i}_$time')";          $q = "$sql ('test_${pid}_${i}_$time')";
98          $result = $conn->exec($q);          $result = $conn->exec($q);
99          if ($result->resultStatus ne PGRES_COMMAND_OK) {          if ($result->resultStatus ne PGRES_COMMAND_OK) {

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.26