views:

520

answers:

3

I have a Perl script that I'm attempting to set up using Perl Threads (use threads). When I run simple tests everything works, but when I do my actual script (which has the threads running multiple SQL*Plus sessions), each SQL*Plus session runs in order (i.e., thread 1's sqlplus runs steps 1-5, then thread 2's sqlplus runs steps 6-11, etc.).

I thought I understood that threads would do concurrent processing, but something's amiss. Any ideas, or should I be doing some other Perl magic?

+2  A: 

Actually, you have no way of guaranteeing in which order threads will execute. So the behavior (if not what you expect) is not really wrong.

I suspect you have some kind of synchronization going on here. Possibly SQL*Plus only let's itself be called once? Some programs do that...

Other possiblilties:

  • thread creation and process creation (you are creating subprocesses for SQL*Plus, aren't you?) take longer than running the thread, so thread 1 is finished before thread 2 even starts

  • You are using transactions in your SQL scripts that force synchronization of database updates.

Daren Thomas
+4  A: 

A few possible explanations:

  1. Are you running this script on a multi-core processor or multi-processor machine? If you only have one CPU only one thread can use it at any time.

  2. Are there transactions or locks involved with steps 1-6 that would prevent it from being done concurrently?

  3. Are you certain you are using multiple connections to the database and not sharing a single one between threads?

Frosty
There was only one DB connection happening, which wasn't what I expected. Thanks for the idea (never thought to check that), now I have work to do...
Milner
+1  A: 

Check your database settings. You may find that it is set up in a conservative manner. That would cause even minor reads to block all access to that information.

You may also need to call threads::yield.

Brad Gilbert