Reducing load for LAMP app?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gilles Ganault

    #1

    Reducing load for LAMP app?

    Hello,

    I'm no LAMP expert, and a friend of mine is running a site which is a
    bit overloaded. Before upgrading, he'd like to make sure there's no
    easy way to improve efficiency.

    A couple of things:
    - MySQL : as much as possible, he keeps query results in RAM, but
    apparently, each is session-specific, which means that results can't
    be shared with other users.
    Is there something that can be done in that area, ie. keep the maximum
    amount of MySQL data in RAM, to avoid users (both logged-on and
    guests) hitting the single MySQL server again and again?

    - His hoster says that Apache server is under significant load. At
    this point, I don't have more details, but generally speaking, what
    are the well-know ways to optimize PHP apps?

    Thank you.
  • _q_u_a_m_i_s's

    #2
    Re: Reducing load for LAMP app?

    On Jan 4, 10:34 am, Gilles Ganault <nos...@nospam. comwrote:
    Hello,
    >
    I'm no LAMP expert, and a friend of mine is running a site which is a
    bit overloaded. Before upgrading, he'd like to make sure there's no
    easy way to improve efficiency.
    >
    A couple of things:
    - MySQL : as much as possible, he keeps query results in RAM, but
    apparently, each is session-specific, which means that results can't
    be shared with other users.
    Is there something that can be done in that area, ie. keep the maximum
    amount of MySQL data in RAM, to avoid users (both logged-on and
    guests) hitting the single MySQL server again and again?
    Are you sure keeping data in ram is a good solution? MySQL cache
    dosen`t help?
    >
    - His hoster says that Apache server is under significant load. At
    this point, I don't have more details, but generally speaking, what
    are the well-know ways to optimize PHP apps?
    >
    Thank you.
    For an easy test try to install a PHP accelerator (i`ve testesd
    eaccelerator http://eaccelerator.net/ ). It can do a pretty good job.
    And another thing , try to make sure that the server is overloaded
    procesing stuff and not because of a bad caching mechanism (google for
    browser-caching). As a rule of thumb , do not use php-generated
    images, or other dinamically generated content if it`s not really
    needed.


    There is no easy way to optimize PHP,as with any other language you
    have to know exactly what goes wrong with your scripts. You can use
    xdebug (as a profiler) to see what functions eat a lot of resources.
    You can monitor the server and see why he is slowing down like
    that(need more ram, more cpu`s...more hdd?).

    Comment

    • Gilles Ganault

      #3
      Re: Reducing load for LAMP app?

      On Fri, 4 Jan 2008 02:23:20 -0800 (PST), "_q_u_a_m_i_s's "
      <quamis@gmail.c omwrote:
      >Are you sure keeping data in ram is a good solution? MySQL cache
      >dosen`t help?
      By RAM, I meant keeping stuff in memory vs. reading them from the HD,
      even though it's not necessary since data didn't change.
      >For an easy test try to install a PHP accelerator
      I'll check it out.
      >There is no easy way to optimize PHP,as with any other language you
      >have to know exactly what goes wrong with your scripts.
      That's the problem he has: If I had to investigate where things can be
      optimized in Linux + Apache + PHP + MySQL, what tool should I use?

      Thanks

      Comment

      • The Natural Philosopher

        #4
        Re: Reducing load for LAMP app?

        _q_u_a_m_i_s's wrote:
        On Jan 4, 10:34 am, Gilles Ganault <nos...@nospam. comwrote:
        >Hello,
        >>
        >I'm no LAMP expert, and a friend of mine is running a site which is a
        >bit overloaded. Before upgrading, he'd like to make sure there's no
        >easy way to improve efficiency.
        >>
        >A couple of things:
        >- MySQL : as much as possible, he keeps query results in RAM, but
        >apparently, each is session-specific, which means that results can't
        >be shared with other users.
        >Is there something that can be done in that area, ie. keep the maximum
        >amount of MySQL data in RAM, to avoid users (both logged-on and
        >guests) hitting the single MySQL server again and again?
        >
        Are you sure keeping data in ram is a good solution? MySQL cache
        dosen`t help?
        >
        Its all held in ram by disk caching anyway.

        Probably :-)

        If you are running queries against the same sets of tables time and
        again, those tables will be cached by the OS.

        If the computer runs out of free RAM tho, expect a sudden and huge
        downturn in performance.

        That something for the machine owner to fix tho.

        The other thing that sometimes screw up dB apps is searches on
        un-indexed fields. Adding indexes can often help a lot, as can
        optimising the way nested select statements are done.

        The key is that the earliest you can reduce the amount of data, if
        possible searching on indexed fields first..
        >- His hoster says that Apache server is under significant load. At
        >this point, I don't have more details, but generally speaking, what
        >are the well-know ways to optimize PHP apps?
        >>
        >Thank you.
        >
        For an easy test try to install a PHP accelerator (i`ve testesd
        eaccelerator http://eaccelerator.net/ ). It can do a pretty good job.
        And another thing , try to make sure that the server is overloaded
        procesing stuff and not because of a bad caching mechanism (google for
        browser-caching). As a rule of thumb , do not use php-generated
        images, or other dinamically generated content if it`s not really
        needed.
        >
        Its a hard call to know what is slow without access to the machine. It
        may be I/O bound due to low RAM and too many disk access, process bound
        - too many processes for the RAM avaialable - or simply CPU bound having
        to do too much computation. My experience suggests that mostly you don't
        need huge CPU power in a *server*, but a fast disk or better, several
        disks, and huge amounts of RAM are the key. As is a fast network..only
        in some of the nastier SQL queries does CPU power get an issue, and
        those are generally fixed by rewriting te query or indexing.

        Any on the fly graphics computation will of course screw the CPU, but
        most people don't do that..its more likely the images are just being
        retrieved, not generated...
        >
        There is no easy way to optimize PHP,as with any other language you
        have to know exactly what goes wrong with your scripts. You can use
        xdebug (as a profiler) to see what functions eat a lot of resources.
        You can monitor the server and see why he is slowing down like
        that(need more ram, more cpu`s...more hdd?).
        That's an interesting point..can PHP easily get at things like CPU
        utilisation, memory resoure allocation and the like? so one could build
        a web page to peer into the server?

        I wouldn't mind one of those here..


        Comment

        • Rik Wasmus

          #5
          Re: Reducing load for LAMP app?

          On Fri, 04 Jan 2008 09:34:20 +0100, Gilles Ganault <nospam@nospam. com>
          wrote:
          Hello,
          >
          I'm no LAMP expert, and a friend of mine is running a site which is a
          bit overloaded. Before upgrading, he'd like to make sure there's no
          easy way to improve efficiency.
          >
          A couple of things:
          - MySQL : as much as possible, he keeps query results in RAM, but
          apparently, each is session-specific, which means that results can't
          be shared with other users.
          Is there something that can be done in that area, ie. keep the maximum
          amount of MySQL data in RAM, to avoid users (both logged-on and
          guests) hitting the single MySQL server again and again?
          AFAIK, more RAM is not always a good thing for MySQL. I've known setups
          where actually reducing RAM usage/cache sizes sped it up tremendously.
          It's somewhat out of my expertise though. Consult the MySQL manual, and
          possibly ask for advise in comp.databases. mysql.
          --
          Rik Wasmus

          Comment

          • Jerry Stuckle

            #6
            Re: Reducing load for LAMP app?

            Gilles Ganault wrote:
            Hello,
            >
            I'm no LAMP expert, and a friend of mine is running a site which is a
            bit overloaded. Before upgrading, he'd like to make sure there's no
            easy way to improve efficiency.
            >
            A couple of things:
            - MySQL : as much as possible, he keeps query results in RAM, but
            apparently, each is session-specific, which means that results can't
            be shared with other users.
            Is there something that can be done in that area, ie. keep the maximum
            amount of MySQL data in RAM, to avoid users (both logged-on and
            guests) hitting the single MySQL server again and again?
            >
            Try comp.databases. mysql - where the MySQL experts hang out. They can
            give you more details, but generally the caches are more efficient at
            this than user apps.
            - His hoster says that Apache server is under significant load. At
            this point, I don't have more details, but generally speaking, what
            are the well-know ways to optimize PHP apps?
            >
            Before you can optimize, you need to find where the bottlenecks are.
            Otherwise you're going to waste a lot of time "fixing" things which
            aren't broken.
            Thank you.
            >


            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • faulkes

              #7
              Re: Reducing load for LAMP app?

              On Jan 4, 3:34 am, Gilles Ganault <nos...@nospam. comwrote:
              Hello,
              >
              I'm no LAMP expert, and a friend of mine is running a site which is a
              bit overloaded. Before upgrading, he'd like to make sure there's no
              easy way to improve efficiency.
              >
              A couple of things:
              - MySQL : as much as possible, he keeps query results in RAM, but
              apparently, each is session-specific, which means that results can't
              be shared with other users.
              Is there something that can be done in that area, ie. keep the maximum
              amount of MySQL data in RAM, to avoid users (both logged-on and
              guests) hitting the single MySQL server again and again?
              >
              - His hoster says that Apache server is under significant load. At
              this point, I don't have more details, but generally speaking, what
              are the well-know ways to optimize PHP apps?
              >
              Thank you.
              I will agree with the statement made in the post that 'before you can
              optimize, you need to know where you are optimizing'.

              1. Eaccel (or any pre-compiler) will certainly help if the bottleneck
              is PHP (to a point.)
              2. Use the XDebug package & Kcachegrind (or wincachegrind) to look at
              what the code is doing and if it can be optimized.
              3. Depending on site needs, considering caching options such as
              memcached.

              Read the IBM series of articles on tuning/performance for LAMP



              faulkes

              Comment

              • Jeremy

                #8
                Re: Reducing load for LAMP app?

                Gilles Ganault wrote:
                Hello,
                >
                I'm no LAMP expert, and a friend of mine is running a site which is a
                bit overloaded. Before upgrading, he'd like to make sure there's no
                easy way to improve efficiency.
                >
                A couple of things:
                - MySQL : as much as possible, he keeps query results in RAM, but
                apparently, each is session-specific, which means that results can't
                be shared with other users.
                Is there something that can be done in that area, ie. keep the maximum
                amount of MySQL data in RAM, to avoid users (both logged-on and
                guests) hitting the single MySQL server again and again?
                >
                - His hoster says that Apache server is under significant load. At
                this point, I don't have more details, but generally speaking, what
                are the well-know ways to optimize PHP apps?
                >
                Thank you.
                memcached: http://memcached.sf.net (for caching dynamic data in memory)
                apc: http://us2.php.net/apc (caches script bytecode to reduce
                compilation overhead)

                These two modules will help enormously. I guarantee it. Using apc is
                pretty much transparent, but memcached will require modifying your
                database abstraction layer using the memcached functions
                (http://php.net/manual/en/ref.memcache.php).

                Also try connection pooling using PHP's persistent connections. These
                make life harder for you, but eliminate a lot of connection/tear-down
                overhead with the database. You need to be able to configure your own
                apache and mysql for this to really work.
                (http://php.net/manual/en/features.pe...onnections.php)

                Jeremy

                Comment

                • Richard

                  #9
                  Re: Reducing load for LAMP app?


                  "Gilles Ganault" <nospam@nospam. comwrote in message
                  news:iqrrn3dmfh l974du205pnfm9o np53gsbn6@4ax.c om...
                  Hello,
                  >
                  I'm no LAMP expert, and a friend of mine is running a site which is
                  a
                  bit overloaded. Before upgrading, he'd like to make sure there's no
                  easy way to improve efficiency.
                  >
                  A couple of things:
                  - MySQL : as much as possible, he keeps query results in RAM, but
                  apparently, each is session-specific, which means that results can't
                  be shared with other users.
                  Is there something that can be done in that area, ie. keep the
                  maximum
                  amount of MySQL data in RAM, to avoid users (both logged-on and
                  guests) hitting the single MySQL server again and again?
                  >
                  - His hoster says that Apache server is under significant load. At
                  this point, I don't have more details, but generally speaking, what
                  are the well-know ways to optimize PHP apps?
                  >
                  Thank you.
                  Why (or how) are the queries "session-specific"?
                  No way to get rid of that?

                  Richard.


                  Comment

                  • Richard

                    #10
                    Re: Reducing load for LAMP app?


                    "Richard" <root@localhost wrote in message
                    news:477ee389$0 $91156$dbd43001 @news.euronet.n l...
                    >
                    "Gilles Ganault" <nospam@nospam. comwrote in message
                    news:iqrrn3dmfh l974du205pnfm9o np53gsbn6@4ax.c om...
                    >Hello,
                    >>
                    >I'm no LAMP expert, and a friend of mine is running a site which is
                    >a
                    >bit overloaded. Before upgrading, he'd like to make sure there's no
                    >easy way to improve efficiency.
                    >>
                    >A couple of things:
                    >- MySQL : as much as possible, he keeps query results in RAM, but
                    >apparently, each is session-specific, which means that results
                    >can't
                    >be shared with other users.
                    >Is there something that can be done in that area, ie. keep the
                    >maximum
                    >amount of MySQL data in RAM, to avoid users (both logged-on and
                    >guests) hitting the single MySQL server again and again?
                    >>
                    >- His hoster says that Apache server is under significant load. At
                    >this point, I don't have more details, but generally speaking, what
                    >are the well-know ways to optimize PHP apps?
                    >>
                    >Thank you.
                    >
                    Why (or how) are the queries "session-specific"?
                    No way to get rid of that?
                    >
                    Richard.
                    >
                    Oh and BTW:
                    >- MySQL : as much as possible, he keeps query results in RAM
                    It seems like a waste of memory to keep the results in RAM when you
                    know they will not be of any use to you afterwards. Immediately free
                    the mem for the next results sounds better to me.

                    Richard.


                    Comment

                    • Jerry Stuckle

                      #11
                      Re: Reducing load for LAMP app?

                      Jeremy wrote:
                      Gilles Ganault wrote:
                      >Hello,
                      >>
                      >I'm no LAMP expert, and a friend of mine is running a site which is a
                      >bit overloaded. Before upgrading, he'd like to make sure there's no
                      >easy way to improve efficiency.
                      >>
                      >A couple of things:
                      >- MySQL : as much as possible, he keeps query results in RAM, but
                      >apparently, each is session-specific, which means that results can't
                      >be shared with other users.
                      >Is there something that can be done in that area, ie. keep the maximum
                      >amount of MySQL data in RAM, to avoid users (both logged-on and
                      >guests) hitting the single MySQL server again and again?
                      >>
                      >- His hoster says that Apache server is under significant load. At
                      >this point, I don't have more details, but generally speaking, what
                      >are the well-know ways to optimize PHP apps?
                      >>
                      >Thank you.
                      >
                      memcached: http://memcached.sf.net (for caching dynamic data in memory)
                      apc: http://us2.php.net/apc (caches script bytecode to reduce
                      compilation overhead)
                      >
                      These two modules will help enormously. I guarantee it. Using apc is
                      pretty much transparent, but memcached will require modifying your
                      database abstraction layer using the memcached functions
                      (http://php.net/manual/en/ref.memcache.php).
                      >
                      Not necessarily. MySQL and the OS both cache data - and generally do a
                      better job at a lower cost than using memcached.

                      apc *could* help. But it might not, either. It all depends on where
                      the bottleneck it.
                      Also try connection pooling using PHP's persistent connections. These
                      make life harder for you, but eliminate a lot of connection/tear-down
                      overhead with the database. You need to be able to configure your own
                      apache and mysql for this to really work.
                      (http://php.net/manual/en/features.pe...onnections.php)
                      >
                      WRONG, WRONG, WRONG! This INCREASES resource usage on the server. With
                      persistent connections, you must have the maximum number of connections
                      *ever* required allocated *all of the time* - even if no one is using
                      your server.

                      MySQL persistent connections should not be used except in extreme cases
                      - like when you're running 100+ connections per second.
                      Jeremy
                      >
                      The FIRST thing to do when having performance problems is to identify
                      the cause of the performance problem. You're making suggestions without
                      having any idea where the hold up is. In at least two cases, your
                      suggestions could actually HURT performance. And the third case may or
                      may not help. If, for instance, the majority of the resource usage is
                      spent in long MySQL queries, apc will have little effect.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Reducing load for LAMP app?

                        Richard wrote:
                        "Gilles Ganault" <nospam@nospam. comwrote in message
                        news:iqrrn3dmfh l974du205pnfm9o np53gsbn6@4ax.c om...
                        >Hello,
                        >>
                        >I'm no LAMP expert, and a friend of mine is running a site which is
                        >a
                        >bit overloaded. Before upgrading, he'd like to make sure there's no
                        >easy way to improve efficiency.
                        >>
                        >A couple of things:
                        >- MySQL : as much as possible, he keeps query results in RAM, but
                        >apparently, each is session-specific, which means that results can't
                        >be shared with other users.
                        >Is there something that can be done in that area, ie. keep the
                        >maximum
                        >amount of MySQL data in RAM, to avoid users (both logged-on and
                        >guests) hitting the single MySQL server again and again?
                        >>
                        >- His hoster says that Apache server is under significant load. At
                        >this point, I don't have more details, but generally speaking, what
                        >are the well-know ways to optimize PHP apps?
                        >>
                        >Thank you.
                        >
                        Why (or how) are the queries "session-specific"?
                        No way to get rid of that?
                        >
                        Richard.
                        >
                        >
                        >
                        Maybe he's storing it in the $_SESSION variable - which isn't actually
                        written to memory - but to disk. And is very slow for large amounts of
                        data.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • Gilles Ganault

                          #13
                          Re: Reducing load for LAMP app?

                          On Sat, 5 Jan 2008 02:55:24 +0100, "Richard" <root@localhost wrote:
                          >Why (or how) are the queries "session-specific"?
                          >No way to get rid of that?
                          I don't know what it means, really. I don't have enough experience
                          with PHP and MySQL to know the details.

                          Generally speaking, is there a way to share query results among all
                          viewers using the site, and if yes, what's the right way to do this?

                          Thanks for all the suggestions guys. It's very helpful.

                          Comment

                          • Richard

                            #14
                            Re: Reducing load for LAMP app?


                            "Gilles Ganault" <nospam@nospam. comwrote in message
                            news:krevn3p8ui ej0uuapro8r4tj5 s1dgvoi66@4ax.c om...
                            On Sat, 5 Jan 2008 02:55:24 +0100, "Richard" <root@localhost wrote:
                            >>Why (or how) are the queries "session-specific"?
                            >>No way to get rid of that?
                            >
                            I don't know what it means, really. I don't have enough experience
                            with PHP and MySQL to know the details.
                            >
                            Generally speaking, is there a way to share query results among all
                            viewers using the site, and if yes, what's the right way to do this?
                            >
                            Thanks for all the suggestions guys. It's very helpful.
                            MySQL has a query cache. Check the manual or the site.
                            The queries have to be identical for it to work, so thats why I was
                            asking about the sessions.

                            Maybe just do a generic query and handle the session specific things
                            in PHP afterwards?

                            R.


                            Comment

                            • Gilles Ganault

                              #15
                              Re: Reducing load for LAMP app?

                              On Sat, 5 Jan 2008 18:29:50 +0100, "Richard" <root@localhost wrote:
                              >MySQL has a query cache. Check the manual or the site.
                              On my way.
                              >The queries have to be identical for it to work, so thats why I was
                              >asking about the sessions. Maybe just do a generic query and
                              handle the session specific things in PHP afterwards?
                              I'll check how queries are used in the pages, and see if it can be
                              done. Thanks.

                              Comment

                              Working...