/[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

Contents of /misc/rserv_test.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sun Aug 10 13:52:29 2003 UTC (20 years, 8 months ago) by dpavlin
Branch: MAIN
CVS Tags: before_onlytables, before_multmaster, r_0_3, HEAD
Changes since 1.3: +2 -1 lines
File MIME type: text/plain
QA test scripts and schema

1 #!/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;
8 use Getopt::Long;
9 use POSIX ":sys_wait_h";
10
11
12 $| = 1;
13 my $control = 0;
14
15 my ($numprocs,$numstmts) = (4,100);
16 my ($debug,$verbose) = (0,0);
17 my ($help,$host,$port,$user,$password);
18
19 my $result = GetOptions(
20 "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
36 print STDERR "Running $numprocs threads, $numstmts inserts each\n";
37
38 my $db = $ARGV[0] || "master";
39 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 = ();
49 my $q;
50
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);
58 exit;
59 } elsif ($pid) {
60 push @pids, $pid;
61 }
62 }
63
64 foreach my $pid (@pids) {
65 my $x = -1;
66 do {
67 sleep(1);
68 $x = waitpid($pid, 0);
69 } until $x == $pid;
70 }
71
72
73 #########################
74
75 sub doInserts {
76 my ($pid) = @_;
77 print "<$pid> Running...\n";
78
79 my $conn = Pg::connectdb($info);
80 if ($conn->status != PGRES_CONNECTION_OK) {
81 print "<$pid> Failed opening $info\n";
82 print "<$pid> Abort!\n";
83 last;
84 }
85
86 $result = $conn->exec("BEGIN");
87 if ($result->resultStatus ne PGRES_COMMAND_OK) {
88 print "<$pid> Error in query '$q': ". $conn->errorMessage."\n";
89 print "<$pid> Abort!\n";
90 last;
91 }
92
93 print "<$pid> Inserting $numstmts records...\n";
94 my $sql = "INSERT INTO $table ($col) VALUES";
95 for (my $i = 0; $i < $numstmts; $i++) {
96 my $time = time;
97 $q = "$sql ('test_${pid}_${i}_$time')";
98 $result = $conn->exec($q);
99 if ($result->resultStatus ne PGRES_COMMAND_OK) {
100 print "<$pid> Error in query '$q': ". $conn->errorMessage."\n";
101 $conn->exec("ROLLBACK");
102 print "<$pid> Abort!\n";
103 last;
104 }
105 }
106 print "<$pid> done!\n";
107
108 $result = $conn->exec("COMMIT");
109 if ($result->resultStatus ne PGRES_COMMAND_OK) {
110 print "<$pid> Error in query '$q': ". $conn->errorMessage."\n";
111 $conn->exec("ROLLBACK");
112 print "<$pid> Abort!\n";
113 last;
114 }
115
116 print "<$pid> Finished.\n";
117 $control++;
118 }

  ViewVC Help
Powered by ViewVC 1.1.26