cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

Hey peeps,

I'm pondering my next move, and started wondering aloud:

"Are SSI (server side includes) going to work out faster than creating dynamic pages?"

Until now, I've been building static pages from data to help ease the load on the server, but I now need to show different information to different users, and so I need to create small parts on most pages dynamically. Let me explain further and it might make more sense.

Let's say I'm presenting a shop web page with 5 products on, and I want different groups of users to see different prices. I can think of three solutions:

Creating all pages dynamically fills we with dread in terms of performance, but is SSI any quicker/easier on server?

And no, I can't use mod_perl - this is for an "off the shelf" solution thingy.

Any thoughts on this much appreciated.

cLive ;-)

"Time for bed, said Florence. Boing, said Zebedee"

Replies are listed 'Best First'.
Re: SSI v dynamic pages
by joealba (Hermit) on Oct 31, 2001 at 11:15 UTC
    For my own needs and my own experiences with heavy traffic sites (200k+ pageviews per day), I find SSI to be very convenient. There aren't many easier ways to coordinate the production of a complex site by numerous people. Also in some circumstances, SSI can be faster than dynamic pages. If the creation of each page involves some nasty database queries or calculations, SSI is probably a faster, better solution.

    However, if you are the only person making this site tick (or one of only a few people), then dynamically served pages may be your best bet -- especially if each web user will log in and see different information/prices. Depending on the number of different user types you have, the large number of SSI files could become a real pain to maintain. You can always use some simple HTML templating to keep the *look* of your site easily maintainable.

    Just keep your slowest scripts' runtimes under 2 seconds. Granted 2 seconds is a *long* time for any dynamic page script to run, but this time is relative to your environment. My general rule of thumb: >1 sec, you need to optimize some code. >2 seconds, you're probably doing something nasty in the code. And if you have the RAM, get really aggressive with caching on your database. That should help keep the runtimes down.

    You'll always have security issues to deal with. So, just be careful.
      All pages are currently static, but built from data. Sorry, perhaps I should have linked directly to my baby rather than assume you'd find it on my home node.

      So, maintenance isn't a problem, I was just looking at general speed.

      Thanks for your comments so far :)

      cLive ;-)

Re: SSI v dynamic pages
by moodster (Hermit) on Oct 31, 2001 at 13:46 UTC
    My experience with SSI is that it's lightning fast but pretty limited in functionality. In time you'll probably think up lots of neat functions you want to include but can't because SSI isn't really a programming language, just a method of customizing pages.

    If the number of user groups in your application is low, and the main performance hit you're worried about is the cost of data manipulation and page generation rather than the overhead of spawning a new perl process for each request, you'd probably do allright with some kind of caching scheme:

    1. A request for a customized page arrives.
    2. Your script checks the cache (on disk) if that page has already been generated for this user group. If so, it is read from file and served to the client.
    3. Otherwise, a new page is generated from scratch, saved to the cache, and served to the client.
    Of course, running under mod_perl would allow you to keep the cache in memory, but I imagine that even a simple file cache would speed up execution.

    Cheers,
    -- moodster

Re: SSI v dynamic pages
by drfrog (Deacon) on Oct 31, 2001 at 09:54 UTC

      Ummm... if you're not going to use SSI because of these security or dynamic issues,then you might as well forego just about any dynamic technology. SSI can be extremely useful for page creation and makes for a fast, easy-to-maintain website. Particularly if non-coders are going to maintain it, since the basic idea is easy to understand.

      Chris
      M-x auto-bs-mode

Re: SSI v dynamic pages
by JPaul (Hermit) on Oct 31, 2001 at 21:21 UTC
    During the year 2000 I spent a considerable amount of my time working on developing a large eCommerce platform.
    The platform involved, as one would expect, nearly every single page to be generated dynamically.

    At one point, the web designer altered the way he generated the pages and used SSI to include the side-bar into the table, to move away from frames. The result of this was that every single page served was painfully slower than before.

    I used SSI once more at a web hosting company for their main page, and again I found SSI to slow page serving quite noticeably. I ended up using a simple perl CGI script (which ended up being around 15 lines) to do the same task, and the page serving was faster to my senses.

    The eCom Apache server (1.3.19 w/mod_perl + SSL) was running on a Sun ULTRA 1 with 196MB of memory (172mHz uSPARC if my memory serves) if anyone wants to make fun out of it.

    JP,
    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Re: SSI v dynamic pages
by perrin (Chancellor) on Oct 31, 2001 at 22:21 UTC
    SSI is a dynamic page technology. It's an Apache module, written in C, called mod_include. It is slower than serving static pages, but still quite fast.

    mod_perl is also a dynamic page technology. It is also fast, and the Apache::SSI module which implements SSI in perl for mod_perl is just as fast as mod_include.

    CGI is another dynamic page technology. It's slow. It has to fork perl and compile your code every time the page is run. It is much slower than SSI.

    I don't see how you can do customized pages for each group using SSI, unless you can somehow get the name of the group into an environment variable, maybe using mod_rewrite. You aleady said you can't use mod_perl. That means you're stuck with CGI.

    To combat the slowness of CGI, you can pre-generate most of the page. Have the main page and the different prices all generated ahead of time. In your CGI, just look at the user information (you'll need to use cookies or URLs with persistent data in them) and decide which price to show them. Use a simple templating tool like CGI::FastTemplate to stitch the main page HTML together with the appropriate price.

      Perrin wrote:
      I don't see how you can do customized pages for each group using SSI, unless you can somehow get the name of the group into an environment variable

      If members of the "group" log in, then it is not too difficult. For example:

      <!--#if expr="${REMOTE_USER} = fancygroup"--> We LOVE you! <!--#elif expr="${REMOTE_USER} = blahgroup"--> Well, okay... <!--#else--> Go away, loser <!--#endif-->

      Any "CGI" environment variable is available like REMOTE_USER. So I think you can get away with using SSI in a lot of cases (though I'd prefer HTML::Mason ;)

Re: SSI v dynamic pages
by dws (Chancellor) on Nov 01, 2001 at 01:25 UTC
    When talking about SSI, it helps to distinguish between using #include, which doesn't spawn additional processes, and #exec, which does. The performance difference is significant. (This sounds kind of "well, duh!", but some web servers don't support #exec.)

    If all you're doing is including new fragments at page assembly time, mod_perl and SSI should be equivalent. A lot of systems rely on "dynamically" assemblying from static content that is periodically regenerated. Things get tricker when the content has be assembled on the spot.

    If you would be using SSI #exec to prepare dynamic content at page assembly time, then mod_perl is going to be faster (by virtue of not having to start a new processes).

    If you're not able to use mod_perl, then you need to start counting process starts to predict whether SSI or CGI will be faster. In the case of including static content, SSI is going to win, since #include doesn't involve starting any new processes. Beyond that, and all other factors being equal*, then it comes down to counting process starts. A CGI that can assemble content without having to fork subprocesses is liable to beat out an SSI that assembles content using 2 or more #exec's.


    * Other factors include maintainability of separate scripts, separation of static and dynamic content, ability of a designer to edit HTML (vs. forcing them to become programmers), etc.

Re: SSI v dynamic pages
by cLive ;-) (Prior) on Nov 01, 2001 at 01:25 UTC
    Thanks for all your replies. Rather than answering each individually, I've posted this and /msg'd relevant people:

    drfrog - i don't think there would be many more issues than existing situation - ie, clients have no reason to piss around (it wouldn't be to their advantage)

    joealba - thanks, great input - technically, I will be the only one in *most* cases. I think, for now, static page sets will make more sense, but as certain features get added, I'll need to rethink this.

    moodster - I was thinking of using SSI to call scripts, so no real limitations on content. Perhaps the question should have been amended to "...build multiple static page sets or use CGI..'

    mischief - It's perl in the sense that I'm using Perl to generate the pages,whatever method's used. I could have built 3 sets of scripts to test each of the three scenarios and benchmarked them, but since I know there are a lot of e-commerce/developer types here, I thought I'd ask around first. A bit like asking, "What's the best way to send an e-mail?" That's not a Perl question, but if you've ever done it in Perl, you'll understand what the question is asking :)

    JPaul - Thank You! Just the sort of feedback I was looking for. Very useful.

    perrin - sorry, should have expanded - SSI calls perl scripts, state maintained using a cookie.

    --

    I think for now, continuing to create template based static pages will be the way to go (also means less work for me), but for the long term, I'll need to probably go the whole hog to a dynamic template driven system that benchmarks a page when designed so the shop owner can be warned if it contains too much custom content.

    Oh joy, how I love the SME* market :)

    Thanks again all for your comments.

    cLive ;-)

    * - Small/Medium sized Enterprises

Re: SSI v dynamic pages
by mischief (Hermit) on Oct 31, 2001 at 20:54 UTC
    Uhm. Maybe I'm going to get --ed for this or something, 'cos other people have answered your question and don't seem to mind, but in what way are you seeking any kind of Perl wisdom here? Am I missing something? (And how did this node get frontpaged?)