http://qs321.pair.com?node_id=405922


in reply to Parallel::ForkManager, DBI using memory

It might be a DBI memory management issue, but I'd suspect right off the bat the DB connections you're constantly making and destroying. Is there a reason you can't share one $dbh for all children? (I think this is possible with Parallel::ForkManager.)
  • Comment on Re: Parallel::ForkManager, DBI using memory

Replies are listed 'Best First'.
Re^2: Parallel::ForkManager, DBI using memory
by 2ge (Scribe) on Nov 07, 2004 at 21:22 UTC
    Hi The Mad Hatter,

    ofcourse I tried that before I post my question. If you try, you get similar error:

    DBD::mysql::db prepare_cached failed: handle 2 is owned by thread 274094 not current thread 6fad024 (handles can't be shared between threads and your driver may need a CLONE method added) at...

    any suggestions ?
      Ah, okay. I had an inkling DBI might not like it.
Re^2: Parallel::ForkManager, DBI using memory
by iblech (Friar) on Nov 08, 2004 at 18:18 UTC
    Is there a reason you can't share one $dbh for all children? (I think this is possible with Parallel::ForkManager.)

    No, it is not possible.

    Reason: Think of two childs, both want to make a query:

    # Child 1:
    SELECT * FROM foobar WHERE baz = 3

    # Child 2:
    SELECT grzbaka FROM baz WHERE foo = 5

    Now, both send their queries at the same time. The db server might receive:

    SELECT * FROSELECT grzbaka FROM baM foobar WHERE baz = 3z WHERE foo = 5

    Of course, reality is more complex, this example is just meant as a simple explanation why one db connection used by many childs don't work (as expected).

    BTW, if you do cooperative multitasking, like POE does, everything is ok -- there is only one process which sends data to the db server.