开发者

Memcached weird problem!

I have a Facebook application with 250K DAU. I use Memcached to cache the files and MySql selects because without that my server is go开发者_JAVA技巧ing crazy.

I have set up the code like this:

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");

// FOR FILES

$doc = $memcache->get('mem_index_html');

if ($doc == null)
{
    $doc = new Document( HTML.'index.html' );
    $memcache->set('mem_index_html', $doc, 0, 86400);
}

// FOR SQL

$sql=sprintf('count(qtn_id) FROM tb_questions where qtn_lang="EN"));
$total_pages = $memcache->get($sql);

if ($total_pages == null)
{       
    $query_id = DB::query($sql);        
    list( $total_pages ) = DB::nextRow( $query_id );
    DB::free( $query_id );
    $memcache->set($sql, $total_pages, 0, 86400);
}

The problem is that after some time – usually 24 hours, errors are starting to show. No log is created but I receive a timeouts if I try to reload the page. I assume that there is a lots of traffic in that moments, the Memcached is not working correct and everything is slowing down. My temporary solution is to Flush the memcache - $memcache->flush(), but that is not good solution.

Am I doing something wrong? Is there something to optimize or I don’t know. I found searching thru web this http://code.google.com/p/memcached/wiki/TutorialCachingStory about making more that one Memecached servers. Is that the best solution?

Thanks for your answers.

Darko


The fourth parameter in the $memcache->set command represents the expiration timeout. Once this is exceeded, the object stored will no longer be available. Since you set it to 24 hours they would not be available after that period unless you updated them.

If the expiry parameter is set to 0, the item will never be expire, but it can still be deleted if memcached is filled up and need to free some space.

If the value is less than 30 days (30 * 24 * 3600 = 2592000), the value provided is treated as a offset from the current time.

If the value is larger than that it will be interpreted as absolute time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜