'aceptable' loading time/CPU load

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

    #1

    'aceptable' loading time/CPU load

    Hi,

    I have a fairly complicated script that seems to load fairly fast. But
    that's because it is on my local server in the office and not on the main
    one, (and I am the only one on it).

    So I would like to run some tests, for example how long the pages take to
    load on average and what load it place on the server.
    Currently the pages load very fast indeed, but I suspect it is because I am
    the only one on the server and php/MySQL are not working that hard...

    Are there any ways to check that the script is within 'acceptable' limits?

    Simon


  • Senator Jay Billington Bulworth

    #2
    Re: 'aceptable' loading time/CPU load

    "simon" <spambucket@myo ddweb.com> wrote in
    news:36m2vnF534 g9sU1@individua l.net:
    [color=blue]
    > Hi,
    >
    > I have a fairly complicated script that seems to load fairly fast. But
    > that's because it is on my local server in the office and not on the
    > main one, (and I am the only one on it).
    >
    > So I would like to run some tests, for example how long the pages take
    > to load on average and what load it place on the server.
    > Currently the pages load very fast indeed, but I suspect it is because
    > I am the only one on the server and php/MySQL are not working that
    > hard...
    >
    > Are there any ways to check that the script is within 'acceptable'
    > limits?[/color]

    I think you might be pleasantly surprised when you move the script from
    your local server to a production server; then again, for many years my
    local server was a Pentium 75.. :) You can time the execution of your
    script like this:

    <?php
    function getmicrotime(){
    list($usec, $sec) = explode(' ', microtime());
    return ((float)$usec + (float)$sec);
    }

    $start = getmicrotime();

    //
    //Insert all of your code here.
    //

    $finish = getmicrotime();
    $latency = sprintf("%.2f", $finish - $start);
    echo "<hr>This script took $latency seconds to execute.";
    ?>

    The result is not perfectly accurate, but it's close enough, down to the
    tenth of a second or so. If you're not satisfied with the run time, you
    could break it down further, calculating a separate $start, $finish, and
    $latency for various code blocks to isolate the bottleneck.

    As for CPU load, just run a `top` session in a shell (assuming you're on
    a unix server), hit the S key, hit the 1 key, hit Enter. top will refresh
    once per second and you can see if there's a load spike when your script
    executes. Note that top itself will generally cause load to go up.

    hth




    --

    Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
    --------------------------|---------------------------------
    <http://www.phplabs.com/> | PHP scripts, webmaster resources

    Comment

    • simon

      #3
      Re: 'aceptable' loading time/CPU load

      >>[color=blue][color=green]
      >> Are there any ways to check that the script is within 'acceptable'
      >> limits?[/color]
      >
      > I think you might be pleasantly surprised when you move the script from
      > your local server to a production server; then again, for many years my
      > local server was a Pentium 75.. :) You can time the execution of your
      > script like this:
      >[/color]

      Hi,

      Thanks for the code, but I guess what I was asking is 'how long is too
      long'?.
      Currently my code takes 0.30s to 0.42s to produce a page, (again on the
      local server with no one else working on it).

      Is that too much?

      Is there an app 'out there' that would put some load on my server? I don't
      feel like writing a once off app to do that for me.

      Simon


      Comment

      • Ramius

        #4
        Re: 'aceptable' loading time/CPU load

        It is impossible to give a straight answer to, "how much processing
        load is 'too much'?". It all depends on your situation.

        You might find the following info helpful to determine your current
        limits, but you will have to analyze for yourself whether or not that
        limit is within an acceptable range for your application.



        http://perl.apache.org/docs/1.0/guide/performance.html - This one is
        geared toward perl/CGI development, but it still has some useful info
        that will apply for PHP.

        Comment

        • Senator Jay Billington Bulworth

          #5
          Re: 'aceptable' loading time/CPU load

          "simon" <spambucket@myo ddweb.com> wrote in
          news:36ot6oF54s osvU1@individua l.net:
          [color=blue][color=green][color=darkred]
          >>>
          >>> Are there any ways to check that the script is within 'acceptable'
          >>> limits?[/color]
          >>
          >> I think you might be pleasantly surprised when you move the script
          >> from your local server to a production server; then again, for many
          >> years my local server was a Pentium 75.. :) You can time the
          >> execution of your script like this:
          >>[/color]
          >
          > Hi,
          >
          > Thanks for the code, but I guess what I was asking is 'how long is too
          > long'?.
          > Currently my code takes 0.30s to 0.42s to produce a page, (again on
          > the local server with no one else working on it).
          >
          > Is that too much?
          >
          > Is there an app 'out there' that would put some load on my server? I
          > don't feel like writing a once off app to do that for me.
          >
          > Simon[/color]

          "Too long" is very subjective. If your script is adding 5 plus 4, 0.30
          seconds is slow to average. If your script is computing the human genome,
          0.42 seconds is NSA fast. As I presume you're doing something more
          realistic, I'll say that half a second is nothing. Less than half a
          second is less than nothing.

          At that rate, it will take your server more time to send the document to
          your visitor over the wire than to execute the code. Unless you're
          expecting to be the next Google, Amazon, or Yahoo, you should be just
          fine. Try it on the production server and see how long it takes there,
          with other processes happening. Runtime will probably be the same, if not
          better.

          As for putting load on your server, if you're using Apache, try the "ab"
          Apache Benchmark tool. If you compile Apache yourself, I believe it's
          built by default, check out the "bin" directory under your Apache
          install, and look for "ab." If it's there, run it with no arguments to
          see its help. It's rather versatile and is good at loading one URL over
          and over and over hundreds of times in a row.

          hth

          --

          Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
          --------------------------|---------------------------------
          <http://www.phplabs.com/> | PHP scripts, webmaster resources

          Comment

          Working...