Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The DBI module has a prepare_cached() method that is used heavily in some applications (in particular with Oracle), to streamline the client code. You can just call prepare_cached() with a query and if a statement handle with this query already exists it will be returned without the overhead of actually preparing the statement again.
This is great - but it doesn't work with Sybase, because of the limitation of one active statement handle per connection.

I ran into this problem last week - a fairly large Sybase database is being converted to Oracle, and the conversion script had a lot of prepare_cached() calls for two pretty simple queries which often return no rows. But this script is run in parallel (40 to 50 parallel sessions), and the total number of items to be converted is around 3-4 million or so.

What happened here is that the database server (running on a 12 processor E4500) started showing serious locking contention issues for the production code that is still running during the conversion. Hitting the server this hard with prepare() calls that include placeholders (which is more work than just executing a simple SQL statement) was causing excessive CPU usage, and the locking needed for the reqular processing was just taking a little longer to clear, causing everything to back up.

The solution: write two very small stored procedures, and call these instead. Now the server could handle 30-40 instances of the conversion script in addition to the normal work without noticing any difference.

To get back to prepare_cached() - I really understand its need, and I can see that an application would want to use it, but Sybase's support of placeholders is (maybe) somewhat limited in this respect. I'll try to find a way to cache statements effectively, but this may not be easy (and each cached statement means an open connection to the database), but in the meantime if you find yourself using prepare_cached() with Sybase consider writing a small stored procedure instead - it will be much faster.

Michael


In reply to DBI prepare_cached and DBD::Sybase by mpeppler

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found