Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4618 dpurdie 1
########################################################################
5709 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
4618 dpurdie 3
#
4
# Module name   : jats_rm_play24.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : Experiment with invoking direct insertion into Release Manager
10
#                 This work really well
11
#                 Aggregate insertion statements to impove performance
12
#                 50,000 insertions in 90 seconds under windows
13
#                                      180 seconds under Linux (I am surprised)
14
#
15
#                 The size of the aggregation buffer is a key factor
16
#                 If its too big the process slows down
17
#                 Size: 30000 Windows: 90, Linux 180
18
#                 Size: 10000 Windows: 59, Linux 56
19
#                 Size:  5000 Windows: 82, Linux 53
20
#                 
21
#
22
#......................................................................#
23
 
24
require 5.006_001;
25
use strict;
26
use warnings;
27
use JatsError;
28
use JatsSystem;
29
use Getopt::Long;
30
use Pod::Usage;                             # required for help support
31
use JatsRmApi;
32
 
33
use DBI;
34
 
35
my $VERSION = "1.2.3";                      # Update this
36
my $opt_verbose = 1;
37
my $opt_help = 0;
38
my $opt_manual;
39
my $RM_DB;
40
 
41
my $m_sqlBase = "INSERT ALL";
42
my $m_sqlTail = " SELECT 1 FROM DUAL";
43
my $m_sqlMid = "";
44
 
45
#-------------------------------------------------------------------------------
46
# Function        : Main Entry
47
#
48
# Description     :
49
#
50
# Inputs          :
51
#
52
# Returns         :
53
#
54
my $result = GetOptions (
55
                "help+"         => \$opt_help,          # flag, multiple use allowed
56
                "manual"        => \$opt_manual,        # flag
57
                "verbose+"      => \$opt_verbose,       # flag
58
                );
59
 
60
#
61
#   Process help and manual options
62
#
63
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
64
pod2usage(-verbose => 1)  if ($opt_help == 2 );
65
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
66
 
67
 
68
ErrorConfig( 'name'    =>'PLAY27' );
69
 
70
#$ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaora07:1521:RELMANU1';
71
#$ENV{GBE_RM_USERNAME} = 'release_manager'; 
72
#$ENV{GBE_RM_PASSWORD} = 'release_manager';
73
 
74
$ENV{GBE_RM_USERNAME} = 'build_user[release_manager]'; 
75
$ENV{GBE_RM_PASSWORD} = 'frog123';
76
 
77
initInsert();
78
my $ii = 0;
79
for ($ii = 0; $ii < 50000; $ii++)
80
{
81
    directInject($ii);
82
}
83
runInsert();
84
exit;
85
 
86
 
87
#-------------------------------------------------------------------------------
88
# Function        : directInject 
89
#
90
# Description     : Create a partial SQL statement to do the insert
91
#
92
# Inputs          : $index          - Uniq number to differentiate the records
93
#
94
# Returns         : 
95
#
96
 
97
sub directInject
98
{
99
    my ($index) = @_;
100
 
101
    my $entry = " INTO release_manager.release_components ( pv_id, file_name, file_path, byte_size, crc_cksum, crc_modcrc ) " .
102
                " VALUES ( 1, 'fred', 'david".$index."/fred', 199, '12345', '67890')";
103
    $m_sqlMid .= $entry;
104
 
105
    # The size of the aggregation is key to performance
106
    # Too big is as bad as too small
107
    if (length($m_sqlMid) > 10000)
108
    {
109
        runInsert();
110
    }
111
}
112
 
113
#-------------------------------------------------------------------------------
114
# Function        : runInsert 
115
#
116
# Description     : Insert entries using the partial SQL statement 
117
#                   Must be called when the partial SQL buffer get large
118
#                   as well as at the end to fluch any outstanding inserts
119
#
120
# Inputs          : 
121
#
122
# Returns         : 
123
#
124
sub runInsert
125
{
126
    my $foundDetails = 0;
127
    my (@row);
128
 
129
    print("Index: $ii\n");
130
    if (length($m_sqlMid) > 0)
131
    {
132
 
133
        #
134
        #   Connect to the Database - once
135
        #
136
        connectRM(\$RM_DB, 0) unless $RM_DB;
137
 
138
        #
139
        #   Create the full Query
140
        #
141
        my $m_sqlstr = $m_sqlBase . $m_sqlMid . $m_sqlTail;
142
        my $sth = $RM_DB->prepare($m_sqlstr);
143
        if ( defined($sth) )
144
        {
145
            if ( $sth->execute() )
146
            {
147
#           print "--- Execute\n";
148
#           if ( $sth->rows )
149
#           {
150
#               print "--- Execute ROWS\n";
151
#               while ( @row = $sth->fetchrow_array )
152
#               {
153
#                   print "Data: @row\n";
154
#               }
155
#           }
156
#           print "--- Finish\n";
157
                $sth->finish();
158
            }
159
            else
160
            {
161
                Error("Execute failure: $m_sqlstr", $sth->errstr() );
162
            }
163
        }
164
        else
165
        {
166
            Error("Prepare failure" );
167
        }
168
    }
169
    $m_sqlMid = ""; 
170
}
171
 
172
#-------------------------------------------------------------------------------
173
# Function        : initInsert 
174
#
175
# Description     : Delete all entries with the PV_ID that I'm about to use
176
#
177
# Inputs          : 
178
#
179
# Returns         : 
180
#
181
 
182
sub initInsert
183
{
184
    my $foundDetails = 0;
185
    my (@row);
186
 
187
 
188
    #
189
    #   Connect to the Database - once
190
    #
191
    connectRM(\$RM_DB, 0) unless $RM_DB;
192
 
193
    #
194
    #   Create the full Query
195
    #
196
    my $m_sqlstr = "delete from release_components where pv_id=1";
197
    my $sth = $RM_DB->prepare($m_sqlstr);
198
    if ( defined($sth) )
199
    {
200
        if ( $sth->execute() )
201
        {
202
#           print "--- Execute\n";
203
#           if ( $sth->rows )
204
#           {
205
#               print "--- Execute ROWS\n";
206
#               while ( @row = $sth->fetchrow_array )
207
#               {
208
#                   print "Data: @row\n";
209
#               }
210
#           }
211
#           print "--- Finish\n";
212
            $sth->finish();
213
        }
214
        else
215
        {
216
            Error("Execute failure: $m_sqlstr", $sth->errstr() );
217
        }
218
    }
219
    else
220
    {
221
        Error("Prepare failure" );
222
    }
223
    $m_sqlMid = ""; 
224
}
225