fx has asked for the wisdom of the Perl Monks concerning the following question:
After my last post regarding threading with Perl against Oracle 9i I decided to go ahead and perform some testing. My system runs Perl 5.8.2 with ithreads compiled using GCC under Solaris 8 for SPARC.
My first test was to have each thread create its own connection the database:
#!/opt/perl-5.8.2/bin/perl use threads; use DBI; @threads; printf "Starting thread "; for ($i = 0; $i < 50; $i++) { printf "$i "; $threads[$i] = new threads(\&do_db); } printf "\n"; printf "Joining thread "; for ($i = 0; $i < 50; $i++) { printf "$i "; $thread = $threads[$i]; $thread->join; } printf "\n"; sub do_db { my $dbh = DBI->connect("dbi:Oracle:host=localhost;sid=testdb1" +, "user1", "pass1") || die $!; }
Watching the Oracle instances, I could see separate connections to the database being created as expected. All the threads are created but then the program dumps core. This may be something to do with the way I'm joining the threads at the end but that's not the big issue...
I then tried using, as the DBD::Oracle 1.14 documentation describes, the ora_dbh_share connection attribute which means that calls to DBI->connect do not necessarily return a reference to a unique database connection:
#!/opt/perl-5.8.2/bin/perl use threads; use DBI; our $orashr : shared = '' ; @threads; printf "Starting thread "; for ($i = 0; $i < 50; $i++) { printf "$i "; $threads[$i] = new threads(\&do_db); } printf "\n"; printf "Joining thread "; for ($i = 0; $i < 50; $i++) { printf "$i "; $thread = $threads[$i]; $thread->join; } printf "\n"; sub do_db { my $dbh = DBI->connect("dbi:Oracle:host=localhost;sid=testdb1" +, "user1", "pass1", { ora_dbh_share => \$orashr} ) || die $!; }
This only gets as far as creating 2-5 threads before dumping core so this can't be anything to do with how I am calling ->join as it's not even getting to that point.
The DBD::Oracle 1.14 documentation implies that threading is safe. It mentions that you need at least Perl 5.8.0 but I fulfil that requirement. The DBI 1.39 documentation mentions the use of ithreads in Perl 5.7 and later and even though it mentions that some database APIs are not thread safe, DBD::Oracle 1.14 claims that its ok.
Can anyone shed any light on what is happening here? The application I am developing is updating or deleting 30,000 records in a database of 6,000,000 or so on a daily basis (read: 6,000,000 in the main table which supplies a foreign key to 5 other tables each containing between 100,000 and 9,000,000 records). The SQL itself is rather slow acting due to the sheer size of the tables and a single threaded application blocks until the SQL is complete. I would like to fire off many SQL statements at once and as the box is a 4 x 750Mhz SPARC with 8Gb physical RAM I should be able to hit it fairly hard.
All comments welcomed.
== fx, Infinity Is Colourless
|
|---|