Instead of creating DBI connection on the fly if it is managed from already created pool of DBI connections we can speed up the operation.

Sorry for the delay in reponding, there is a lot to say about this, and much of it I have no first hand experience of.

  1. If your intent is to talk to the database concurrently, via DBI, from multiple threads, be aware that module still suggests that using it in conjunction with threads is still not supported.

    However, there are some signs of light.

    • Some DBD drivers (used in conjunction with DBI), particularly pure-Perl DBD drivers, are known to work.

      But the onus is on the user to a) use the pure-Perl versions; b) check that the underlying, vendor-provided C-libraries used by the DBD/database in question are themselves thread-safe.

    • DBIx::Threaded may allow you to use some other DBD drivers safely?
  2. That said, all DBD drivers, pure-Perl and otherwise are safe to use with threads, if you only call then from one thread.
  3. If your are modifying the same table(s) with all your queries, including those that you are hoping to run in multiple threads, there will likely be no advantage to issuing those queries concurrently--and it may well degrade your performance.

    The reason

    The database itself will often, of necessity, serialise concurrent queries affecting the same table(s), as it will need to lock the table(s) (including foriegn key dependancy tables), until a transaction is completed or rolled back.

    The situation may be improved if the database supports and is using record (tuple) locks, but even then, if the query can affect (require updates to), one or more indexes, it may still need to serialse the queries.

The upshot is that it often makes sense to serialise your queries yourself.

Its a complex field and you would probably get better answers going to the DBI forums and describing your application requirements in more detail.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^6: How to create thread pool of ithreads by BrowserUk
in thread How to create thread pool of ithreads by elf_firein

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.