A question about efficiency

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Oakes

    #1

    A question about efficiency

    I am developing a site which will be very dynamic. Most of the displayed
    content will come from a database (MySql) via PHP.

    Some types of pages will change frequently (something like a forum page
    which is always having new content added to it) and others will only change
    once a day (a new news item gets added, etc.).

    Although I can optimise my queries and my PHP scripts, there is still the
    potential for the site to get congested, once a large number of people start
    accessing it.

    The question is how do I make sure it performs well? There are several
    options I might consider, such as:
    - don't do anything, but rely on server caching. Is PHP / Apache caching
    any good?
    - Periodically "publish" my PHP-generated pages to flat HTML pages and serve
    them up instead of the PHP.
    - Other things?

    Any thoughts?

    --
    Stephen Oakes


  • Erwin Moller

    #2
    Re: A question about efficiency

    Stephen Oakes wrote:
    [color=blue]
    > I am developing a site which will be very dynamic. Most of the displayed
    > content will come from a database (MySql) via PHP.
    >
    > Some types of pages will change frequently (something like a forum page
    > which is always having new content added to it) and others will only
    > change once a day (a new news item gets added, etc.).
    >
    > Although I can optimise my queries and my PHP scripts, there is still the
    > potential for the site to get congested, once a large number of people
    > start accessing it.
    >
    > The question is how do I make sure it performs well? There are several
    > options I might consider, such as:
    > - don't do anything, but rely on server caching. Is PHP / Apache caching
    > any good?
    > - Periodically "publish" my PHP-generated pages to flat HTML pages and
    > serve them up instead of the PHP.
    > - Other things?
    >
    > Any thoughts?
    >
    > --
    > Stephen Oakes[/color]

    Hi Stephen,

    I am unsure what you expect from the first solution.
    Is there any way Apache/PHP can cache requests that depend on
    databasecontent that changes all the time?
    I don't think so, but maybe I am wrong. (Happens daily. :P)

    You second approach is easy to implement, and easy to understand.
    I did it before, and it works realy easy.

    The approach I choosed was a little different from the one you describe, but
    similar:
    1) I identified a bunch of pieces in pages that seldom change but need a lot
    of Database-querying.
    2) All those pieces were made include-files. Nothing fancy, just a plain
    include.
    3) I programmed on relevant 'triggers' (Not database-triggers) on places
    where the includefiles were modified (mostly by an admin that changed
    something in the database). These triggers simply called a routine that
    rebuilded the included files.
    In this way you:
    - do not need a cronjob or anything like that.
    - And all your includefiles are always up to date. Immediately.

    Of course, it is up to you to decide which pieces on your site are suitable
    for this approach.

    Just my 2 cents.

    Regards,
    Erwin Moller



    Comment

    • Stephen Oakes

      #3
      Re: A question about efficiency


      "Erwin Moller" <sin_hum_rea_th i_Iam_spa_too_m uc@spa.com> wrote...[color=blue][color=green]
      >> - don't do anything, but rely on server caching. Is PHP / Apache caching
      >> any good?[/color][/color]
      [color=blue][color=green]
      >> - Periodically "publish" my PHP-generated pages to flat HTML pages and
      >> serve them up instead of the PHP.[/color][/color]
      [color=blue][color=green]
      >> - Other things?[/color][/color]
      [color=blue]
      > I am unsure what you expect from the first solution.[/color]

      Me too, that's why I asked. I don't really know enough about how
      server/mysql caching works to know whether I need do anything extra.
      [color=blue]
      > You second approach is easy to implement, and easy to understand.
      > I did it before, and it works realy easy.
      >
      > The approach I choosed was a little different from the one you describe,
      > but
      > similar:
      >...[/color]

      Yes, that's the basic approach I had in mind, although more on a per-page
      basis than part-page. That idea might help in some places.
      [color=blue]
      > Of course, it is up to you to decide which pieces on your site are
      > suitable
      > for this approach.[/color]

      Did you notice any improvements in speed?

      --
      Stephen Oakes


      Comment

      • Erwin Moller

        #4
        Re: A question about efficiency

        Stephen Oakes wrote:
        [color=blue]
        >
        > "Erwin Moller" <sin_hum_rea_th i_Iam_spa_too_m uc@spa.com> wrote...[color=green][color=darkred]
        >>> - don't do anything, but rely on server caching. Is PHP / Apache
        >>> caching any good?[/color][/color]
        >[color=green][color=darkred]
        >>> - Periodically "publish" my PHP-generated pages to flat HTML pages and
        >>> serve them up instead of the PHP.[/color][/color]
        >[color=green][color=darkred]
        >>> - Other things?[/color][/color]
        >[color=green]
        >> I am unsure what you expect from the first solution.[/color]
        >
        > Me too, that's why I asked. I don't really know enough about how
        > server/mysql caching works to know whether I need do anything extra.
        >[/color]

        So maybe there are great solutions out there that work great, we both don't
        know about.
        :-)
        [color=blue][color=green]
        >> You second approach is easy to implement, and easy to understand.
        >> I did it before, and it works realy easy.
        >>
        >> The approach I choosed was a little different from the one you describe,
        >> but
        >> similar:
        >>...[/color]
        >
        > Yes, that's the basic approach I had in mind, although more on a per-page
        > basis than part-page. That idea might help in some places.[/color]


        In my case I had a few lists (top10 like stuff) that appeared on several
        pages. So a small piece of HTML in an include made the most sense in my
        situation.
        Of course your situation might differ, and you need complete pages: but
        principle is the same, I expect.

        [color=blue]
        >[color=green]
        >> Of course, it is up to you to decide which pieces on your site are
        >> suitable
        >> for this approach.[/color]
        >
        > Did you notice any improvements in speed?[/color]

        Yes.
        Some of the queries I needed took up a lot of time (because of quite complex
        calculations needed to produce the top10 lists).

        I would like to add that the above solution is really easy to implement.
        Instead of writing the html to output, you just put it into the appropriate
        file.

        Of course the user PHP/WWW-data/nobody/whatever needs writepermission in the
        directory where you store these files. That is why I made a special
        directory for it, because I didn't want that that user had writepermission
        on all my files, so in case of a securitybreach, the damage would be
        limitted to those includefiles.

        Hope this helps you a bit.

        Regards,
        Erwin Moller
        [color=blue]
        >
        > --
        > Stephen Oakes[/color]

        Comment

        • Chung Leong

          #5
          Re: A question about efficiency

          My advise is to wait till you have a congestion problem before dealing
          with it. Unless the success of a site is somehow guaranteed, your focus
          should be on making it a success, instead of worrying about it becoming
          too successful.

          Comment

          • NC

            #6
            Re: A question about efficiency

            Stephen Oakes wrote:[color=blue]
            >
            > I am developing a site which will be very dynamic. Most of the displayed
            > content will come from a database (MySql) via PHP.
            >
            > Some types of pages will change frequently (something like a forum page
            > which is always having new content added to it) and others will only change
            > once a day (a new news item gets added, etc.).
            >
            > Although I can optimise my queries and my PHP scripts, there is still the
            > potential for the site to get congested, once a large number of people start
            > accessing it.
            >
            > The question is how do I make sure it performs well? There are several
            > options I might consider, such as:
            > - don't do anything, but rely on server caching. Is PHP / Apache caching
            > any good?
            > - Periodically "publish" my PHP-generated pages to flat HTML pages and serve
            > them up instead of the PHP.
            > - Other things?[/color]

            Consider MySQL query caching...

            Cheers,
            NC

            Comment

            • Scott Auge

              #7
              Re: A question about efficiency

              In article <1121874486.445 210.10940@g14g2 000cwa.googlegr oups.com>,
              "Chung Leong" <chernyshevsky@ hotmail.com> wrote:
              [color=blue]
              > My advise is to wait till you have a congestion problem before dealing
              > with it. Unless the success of a site is somehow guaranteed, your focus
              > should be on making it a success, instead of worrying about it becoming
              > too successful.[/color]

              This is the best advice I have read in a long long time!

              So many people focus on problems that aren't even there...

              And this kind of problem is a "good problem" to have. Hopefully when it
              happens, you will be making some money to buy the resources to fix it.

              Comment

              • Good Man

                #8
                Re: A question about efficiency

                "NC" <nc@iname.com > wrote in
                news:1121874732 .864483.219680@ g44g2000cwa.goo glegroups.com:

                [color=blue]
                > Consider MySQL query caching...[/color]


                this will make a HUGE difference for the type of application you are
                proposing.... it is not enabled out of the box, but it's easy to set up.

                http://www.databasejournal.com/featu...le.php/3110171


                Comment

                • Stephen Oakes

                  #9
                  Re: A question about efficiency


                  "Scott Auge" <scott_auge@yah oo.com> wrote...[color=blue][color=green]
                  >> My advise is to wait till you have a congestion problem before dealing
                  >> with it. Unless the success of a site is somehow guaranteed, your focus
                  >> should be on making it a success, instead of worrying about it becoming
                  >> too successful.[/color]
                  >
                  > This is the best advice I have read in a long long time![/color]

                  hmm...yeah, but not if the subsequent "dealing with it" involves an entire
                  architectural redesign.

                  Frankly I'd rather at least know what my options are before I build the
                  system.

                  Thanks to those who've replied; there've been some helpful ideas.

                  --
                  Stephen Oakes


                  Comment

                  • Alexey Kulentsov

                    #10
                    Re: A question about efficiency

                    Stephen Oakes wrote:[color=blue]
                    > I am developing a site which will be very dynamic. Most of the displayed
                    > content will come from a database (MySql) via PHP.[/color]
                    ....[color=blue]
                    > The question is how do I make sure it performs well?[/color]

                    1. All pages are generated by 404 script. First time page is generated,
                    second time it's just a static page.

                    2. When you change your data, engine must delete from disk generated
                    pages which depends on this data. For each class you need method
                    returned list of URL to delete if this object is changed.

                    3. When you develop design have in mind this approach. Separately
                    changed objects in database must be presented by separately cached
                    objects in URL space. For example in you make shop don't insert HTML
                    code with current basket info right to page with product info. It must
                    be _separate_ object: iframe, frame, included javascript file, etc... In
                    this case you can make product info page static. And it will be
                    regenerated only when product is changed.

                    Lazy way.

                    Comment

                    • R. Rajesh Jeba Anbiah

                      #11
                      Re: A question about efficiency

                      Stephen Oakes wrote:
                      <snip>[color=blue]
                      > Although I can optimise my queries and my PHP scripts, there is still the
                      > potential for the site to get congested, once a large number of people start
                      > accessing it.[/color]
                      <snip>

                      FWIW, <news:111143049 5.275366.42540@ z14g2000cwz.goo glegroups.com> (

                      )

                      --
                      <?php echo 'Just another PHP saint'; ?>
                      Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

                      Comment

                      Working...