All about Php & Mysql  optimization / benchmark

Ali Kayahan
Ali Kayahan used Ask the Experts™
on
Hi Experts ;

   I built an ebay clone with ZendFrameWork & MYSQL that will work under heavy load . I serve this website from a cloud vps that has ;

Cpu : 6Ghz Dedicated (Can increase up to 10.2 Ghz)
Ram : 3760Mb (Can increase up to 6392Mb)

Web Server : Apache 2.x

My current topology without any optimization is simple ; i have a vps for web server and a vps for database server.

What i ask for ; what are your topologies , optimization techniques and benchmark tools for such a web site.

P.S : In some cases there are 4+ depth nested ajax request over 2000 records.And there are 1m + product records , 10.000 + simultaneous connections.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
I consider myself a non-ignorant software developer and I do not really understand the origin of this question.

App performance is like Ohm's Law.  There are three co-dependent variables: the system under test, the workload and the resultant performance.  Fix any two variables and the third is determined.  Building on that foundation, here is how I optimize...

1. All performance problems appear in the I/O subsystem.  In web apps, this is the data base.  Use normalized table structures (hire a DBA) and index all the columns used in a WHERE, JOIN, ORDER BY, GROUP BY clauses, etc.

2. Make a few Google searches for PHP performance and pay attention to the detailed responses.

If you are not having performance problems now we cannot really help you correct performance problems.  If you can show us more about your performance problems, we can help you find the specific "viagra" you need for your web site.
Ali KayahanFull Stack Developer

Author

Commented:
Ray thanks for your reply ,my question is ; what are your optimization techniques for mysql (like memcached , sphinx , lucene) and for apache (like load balancing , server farms ect..) and which tools should i use to benchmark those enhancements .
Most Valuable Expert 2011
Top Expert 2016
Commented:
You can make detailed readings of the server logs.  Look out for things like missing files that might cause repeated 404. APC and MemcacheD are popular.
http://us.php.net/manual/en/book.apc.php
http://us.php.net/manual/en/book.memcached.php

Sphinx and Lucene seem to be mostly about searching.  I do not consider them to be optimization techniques.


In MySQL, EXPLAIN SELECT is a popular technique.

This article (a little old) and others like it are easily found if you search for PHP performance.
http://talks.php.net/show/perf_tunning/

I have written a stopwatch class that enables me to time part of a script.  The class and a demonstration use case are in the code snippet.  For more comprehensive diagnosis, you might consider profiling with XDebug
http://www.xdebug.org/docs/profiler

This might also be interesting:
http://about.digg.com/blog/rasmus-lerdorf-php-performance

The links on this page offer some good ideas:
http://blogs.sitepoint.com/phpbench-live-php-benchmarks-best-practices/

Overall, the problem with hypothetical performance optimization is that you don't really know what the workload looks like until you have the workload or can simulate the workload.  Only then can you see how the system under test responds.  And only in observing the response to the workload you will be able to see "what comes next" in the broad panoply of potential monitoring and optimizing tools.

HTH, ~Ray
<?php // RAY_oop_stopwatch.php
error_reporting(E_ALL);


// DEMONSTRATE A SCRIPT TIMER FOR ALL OR PART OF A SCRIPT PHP 5+
// MAN PAGE http://php.net/manual/en/function.microtime.php


class StopWatch
{
    protected $a, $z;
    public function __construct()
    {
        $this->a = array();
        $this->z = array();
    }

    // A METHOD TO CAPTURE A START TIME
    public function start($name='TIMER')
    {
        $this->a[$name] = microtime(TRUE);
    }

    // A METHOD TO CAPTURE AN END TIME
    public function stop($name='ALL')
    {
        if ($name == 'ALL')
        {
            foreach ($this->a as $name => $start_time)
            {
                if (!isset($this->z[$name])) $this->z[$name] = microtime(TRUE);
            }
        }
        else
        {
            $this->z[$name] = microtime(TRUE);
        }
    }

    // A METHOD TO READ OUT THE TIMER(S)
    public function readout($m=1000, $eol=PHP_EOL)
    {
        $str = NULL;
        foreach ($this->a as $name => $start_time)
        {
            $str .= $name;
            if (!isset($this->z[$name]))
            {
                $str .= " IS STILL RUNNING";
            }
            else
            {
                $lapse_time = $this->z[$name] - $start_time;
                $lapse_msec = $lapse_time * $m;
                $lapse_echo = number_format($lapse_msec, 1);
                $str .= " $lapse_echo";
            }
            $str .= $eol;
        }
        return $str;
    }
}


// DEMONSTRATE THE USE -- INSTANTIATE THE STOPWATCH OBJECT
$sw  = new Stopwatch;

// SET STOPWATCH NAMES
$go = 'GOOGLE ONLY';
$gy = 'GOOGLE AND YAHOO!';
$yo = 'YAHOO! ONLY';

// START SOME TIMERS
$sw->start($go);
$sw->start($gy);

// PERFORM SOME ACTIVITY THAT YOU WANT TO TIME
$page = 'http://google.com';
$html = file_get_contents($page);

// STOP ONE OF THE STOPWATCHES AND START THE OTHER
$sw->stop($go);
$sw->start($yo);

// PERFORM SOME OTHER ACTIVITY THAT YOU WANT TO TIME
$page = 'http://yahoo.com';
$html = file_get_contents($page);

// REPORT THE STOPWATCHES CONTENT (TWO WILL BE INCOMPLETE)
echo nl2br($sw->readout());

// STOP ALL OF THE REMAINING STOPWATCHES
$sw->stop();

// REPORT THE STOPWATCHES CONTENT AGAIN
echo nl2br($sw->readout());

Open in new window

How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Ali KayahanFull Stack Developer

Author

Commented:
Thanks Ray i ll have a look at them .
Ali KayahanFull Stack Developer

Author

Commented:
accidentally i chose close question , Ray's answer ID: 35760442 is the solution.
Ali KayahanFull Stack Developer

Author

Commented:
accidentally i chose close question , Ray's answer ID: 35760442 is the solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial