I’ve got a tiered architecture that is based on CGI::Application. Each application has a slew of modules it may use to achieve its result. There is also a heavy reliance on a database backend (maintaining state, reporting et al). Obviously there is also a heavy reliance on CGI.

The architecture is essentially two tiers:

  1. the Interface to the browser and the business logic
  2. the interface to the backend

I’m wondering the best method of implementing this style of application. Should each module be essentially standalone? By that I mean should each backend module create its own db handle (if required), and other object instances that may be used more than once by other modules called by the "interface" tier?

Or

To conserve memory, cpu cycles, and other overhead (ala dbi instances), should I pass pre-created objects (at the upper tier) down to the bottom tier?

I guess I’m looking at a trade off here. Performance v’s maintainability.

I’m kind of leaning toward pre-creating objects and passing them around, simply because of the performance aspect. For example I’ve an application that would open and close four different DBI objects to produce a page. Creating one DBI instance with a DB handle and handing it out will obviously be quite a bit faster than creating it 4 different times.

The application is on apache, but not mod_perl (yet), so from a purely database perspective the answer is to put DBI into every module that needs it once we get to mod_perl. However for other objects (CGI and others) would it be better to precreate them and pass them about? Or to make each backend module completely self sufficient?


In reply to Performance v's Maintainability by Ryszard

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.