Eli

To content | To menu | To search

Tag - memcached - Tag - memcached - Eli

Tag - memcached - Tag - memcached - Eli

Entries feed - Comments feed

Thursday, May 6 2010

phpMemCacheAdmin 1.1.2 released

New version of memcached monitoring administration is released and available from http://code.google.com/p/phpmemcacheadmin/

Release Notes

  • Fixed the 1.0 rates in live stats
  • Added the version number

If you have any suggestion or bugs, you can contact me by mail

Wednesday, May 5 2010

Using cas() command from PECL Memcached

Here a simple example on how using cas() command from PECL Memcached to update data that must be at all time up to date

In Memcached, series of commands are not atomic :

A series of commands is not atomic. If you issue a 'get' against an item, operate on the data, then wish to 'set' it back into memcached, you are not guaranteed to be the only process working on that value. In parallel, you could end up overwriting a value set by something else.

But PECL Memcached come with a useful function : cas()

The principle is :

  • Make a get() to get a key value and a cas token (checksum of the value that the get return)
  • Make some update on the value
  • Ask memcached to update the value with cas() method with the cas token as parameter, to let memcached see if the actual value of the key you want to update is the same as he give before or if another script has changed it

Here the code example, we update an index array, adding values in it when not present

# Initializing Memcached connection
$memcache = new Memcached();
$memcache->addServer('localhost', 11211);
 
$indexKey = 'Our index key';
$newValue = 'Some new value to add to index';
$cas = null;
 
# Starting index updating
do 
{
  # Getting data, with parameter $cas to get as we want a cas token
  $indexData = $memcache->get($indexKey, null, $cas);
 
  # Index does not exists, initializing it
  if($indexData === false)
  {
    $indexData = array($newValue);
    $memcache->add($indexKey, $data, 1800);
  }
  # Index exists, updating it
  else
  {
    # Adding new value in index
    $indexData[] = $newValue;
    $memCache->cas($cas, $indexKey, $indexData, 1800);
  }
}
# If result is not stored, or data was updated by another thread
while(($memCache->getResultCode() == Memcached::RES_NOTSTORED) 
      || ($memCache->getResultCode() == Memcached::RES_DATA_EXISTS));

With that little script, we are sure that :

  • If no index are present at start of our script but the index is created in another thread, we retrieve it before adding our value because we use the add() command (Memcached::RES_NOTSTORED)
  • If the index is modified by another script while we are working on it, we get the up to date version before trying to add our new data, thanks to the cas() method (Memcached::RES_DATA_EXISTS)


Remember to be careful with cas(), under heavy concurrent updates, the do ... while() can easily take a lot of execution time, you must add a maximum try count break condition.

And remember to not check command success in a while loop with something like

$memCache->getResultCode() != Memcached::RES_SUCCESS

Memcached::RES_SERVER_ERROR or anything like this and your script will loop forever

Saturday, April 24 2010

libMemcached 0.40 released

Release notes :

  • Placed retry logic in for busted resolvers
  • Add an ignore for SIGPIPE to solve OSX issues.
  • A couple of fixed for memcached_light server.
  • Update to debug mode to track io_wait

You can download it from : http://download.tangent.org/libmemcached-0.40.tar.gz

Monday, April 19 2010

phpMemCacheAdmin version 1.1.1 released

New version is released and available from http://code.google.com/p/phpmemcacheadmin/ and is now compatible with Memcached 1.4.5

Release Notes

  • Added the reclaimed stats and reclaimed rate (New in Memcached 1.4.5)
  • Added the eviction rate
  • Added a "Are you sure ?" for flush_all command
  • Fixed the eviction rate bug on live stats
  • Fixed the PECL Memcache/Memcached API bug with get commands
  • Fixed the flush_all link not working from slabs stats

If you have any suggestion or bugs, you can contact me by mail

Friday, April 16 2010

Memcached on Windows and telnet interface

How to install & run memcached 1.4.4 on Windows

  1. Download package from http://labs.northscale.com/memcached-packages/
  2. Unzip to your desired directory (c:\memcached_win32\ in my example)

Add memcached to the Windows services from the command line

c:\memcached_win32\memcached.exe -d install

Then you can start or stop the memcached server as a service with

net start memcached
net stop memcached

To edit the memcached server configuration, open regedit and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached, then find and edit the ImagePath

"C:\memcached_win32\memcached.exe" -d runservice -m 256 -p 11210

Example running memcached with 256 M and on port 11210

Using memcached telnet interface

You can communicate with memcached server (localhost or distant) by opening a telnet session.

Memcached text protocol can be found here about Protocol

It's a bit confusing, but here some examples

Connecting to server :

> telnet localhost 11211

Server stats :

> stats
STAT pid 14550
STAT uptime 2530
[a lot of line...]
END

Slabs stats :

> stats slabs
STAT 1:chunk_size 80
[a lot of line...]
END

Items stats :

> stats items
STAT items:1:number 1
[a lot of line...]
END

Set command :

> set key 0 900 13
> data_to_store
STORED

Details on set command :

set <key> <flags> <exptime> <bytes> with <bytes> = number of bytes of data you want to store.

Get command :

> get
END
> get key
VALUE key 0 13
data_to_store
END

Increment & decrement commands :

> set key 0 900 2
> 10
STORED
> incr key 5
15
> decr key 2
13
> get key
VALUE key 0 2
13

You can also use phpMemCacheAdmin to execute these command and monitor your queries

Wednesday, April 14 2010

phpMemCacheAdmin version 1.1.0 released

Graphic stand-alone administration for memcached to monitor and debug purpose

This program allows to see in real-time or from the start of the server, stats for get, set, delete, increment, decrement, cas command, as well as server stats (network, items, server version) with googlecharts

You can go further to see each server slabs, occupation, memory wasted and items (key & value).

To extract these informations, phpMemCacheAdmin uses, as you wish, direct communication with server, PECL Memcache or PECL Memcached API.

Download it here : http://code.google.com/p/phpmemcacheadmin/

Do not hesitate to give your comments, ideas and corrections.

Feature list

Statistics

  • Stats for each or all memcached servers
  • Stats for every command : set, get, delete, incr, decr, cas, ...
  • Slabs stats (Memory, pages, wasted, items)
  • Items stats (View items in slabs, then data for each key)
  • Network stats (Traffic, bandwidth)

Commands

  • Execute commands : get, set, delete, flush_all on servers to administrate or debug it
  • Get data with key on servers
  • Delete keys on servers
  • Flush servers

Live Stats

  • Top-like real time stats with configurable alerts
Last update : Tue, 13 Apr 2010 16:12:36 +0200   (refresh rate : 2 sec)
SERVER:PORT                      %MEM   %HIT  HIT/s  CONN   GET/s   SET/s   DEL/s    EVI/s    READ/s   WRITE/s
XXXXXXXXXXXXXXXXXX:11211          0.6   96.8   15.0    39     5.0     5.8     0.0      0.0    7.9 Kb    7.9 Kb
XXXXXXXXXXXXXXX:11211            50.8   95.7  279.5   485   279.5    12.5     0.0      0.0   34.0 Kb  203.5 Kb
XXXXXXXXXXXXXXXX:11211           48.1   95.1  259.3   464   259.5    13.0     0.0      0.0   29.9 Kb  116.3 Kb
XXXXXXXXXXXXXXXX:11211           49.8   96.0  314.8   463   314.5    13.3     0.0      0.0   68.0 Kb  108.5 Kb

Configuration

  • Edit configuration directly from web page
  • phpMemCacheAdmin can use socket communication, PECL Memcache or Memcached API

Compatibility

  • PHP 5.1, 5.2, 5.3 (Linux & Windows)
  • Memcache 1.4+ (Linux & Windows), not compatible with 1.3 or fewer
  • Firefox, Opera, Chrome

Known Bugs

  • Some part may not be very resistant to error
  • Live stats can sometime generate errors, it will be fixed

Thursday, April 8 2010

libMemcached 0.39 released

Release notes :

  • Add support for prefix keys to binary protocol.
  • Remove the undocumented call memcached_server_remove().
  • The undocumented call memcached_server_by_key() now returns const.
  • memcached_server_error_reset() has been deprecated.
  • memcached_server_list() has been deprecated.
  • Use memcached_server_cursor() to walk the servers found in a memcached_st() structure.
  • memcached_verbosity() can now be run concurrently with other operations.
  • SASL support.
  • Fixes memory leak found in EJECT HOSTS.

You can download it from : http://download.tangent.org/libmemcached-0.39.tar.gz

Memcached 1.4.5 released

Release notes from official site :

Overview

This is a maintenance release with some build fixes, doc fixes, and one new stat.

Fixes

  • Properly detect CPU alignment on ARM. bug100
  • Remove 1MB assertion. bug 119
  • More automake versions supported.
  • Compiler warning fixes for OpenBSD.
  • Potential buffer overflow in vperror
  • Report errors opening pidfiles using vperror

New Features

  • reclaimed : This stat reports the number of times an entry was stored using memory from an expired entry.
  • sasl_pwdb : For more simple auth deployments

You can download it from : http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz

Wednesday, March 31 2010

phpMemCacheAdmin

phpMemCacheAdmin is an stand alone administration for memcached server, written in PHP and hosted on googlecode

PHP Script included with PECL Memcache package was a very good help during our first trys, but does not support increment, decrement, and cas stats, so i decided to write a new one.

Stats include : get, set, delete, increment, decrement hits and misses as well as cas hits, misses and bad value. Many server stats are included to.

Selecting a particular server, you can walk through each instanced slabs, to see items key, value and memory wasted.

Each command is configurable, to use server communication, PECL Memcache or Memcached API.

You can check it on http://code.google.com/p/phpmemcacheadmin/