Hi,

Lately we got traffic trouble with our news site so decided to start
using memcache. I've read about memcached but never tried it on
production.

Now i have a test page (test.php) on my localserver (Apache, Mysql
5.5, Php 5.3 and memcached installed) Mysql data is about 220 MB and
has 400k rows total.

Test page has a simple query that pulls 50 rows from database (about
200kb)

Sample code:

<?php
global $memcache;
$memcache = new Memcache();

//$memcache->flush();
$memcache->connect("127.0.0.1", "11211");

$key = "10";

$cache_result = $memcache->get($key);

if($cache_result) {
    $data = $cache_result;
    echo "<h1>cache data</h1>";
} else {
    mysql_connect("localhost", "root", "root") or die(mysql_error());
    mysql_select_db("newstest");
    mysql_set_charset("utf8");

    $q = mysql_query("SELECT * `news`, `categories` WHERE
`publish_area` LIKE 'headline' AND `published`='1' AND
`category_parent`=`category_id` AND `publish_date` <= '".date("Y-m-d
H:i:s")."' ORDER BY publish_date DESC LIMIT 0,15");

    while($o = mysql_fetch_object($q)) {
        $data[] = $o;
    }

    $memcache->set($key, $data);
    echo "<h1>mysql data</h1>";

    mysql_close();
}

foreach($data as $o) {
    print_r($o);
}

I've used ab(Apache Benchmark) and siege to test sample code.

First of all using memcached fixed my mysql heavy load problem also
web site speed up which is good but both benchmark causes same
problems;

1. Web server load average goes really high based on the time
benchmark runs.
2. memcache connection losts on heavy especially on heavy concurrent
requests.

Tried with both high and low cachesizes and maxconn

I have check apache configuration and memcache configuration but no
clue.

Reply via email to