race conditions and network latency

Kevin Webb kevin at tackledesign.com
Sun Mar 5 16:34:07 UTC 2006


Hi,

I've been developing a shared memory architecture with locking using
memcached's PHP client. It's working wonderfully on a single machine
(with many concurrent accesses) or machines on a local network.
However, over the Internet, clients accessing the server with
significant latency appear collide.  Are there any known issues with
latency and use of the Add call?

In pseudo code I'm doing this:

lock_id = random()
while(!memcached->add(lock_name, lock_id))
{
   wait()
}

data = memcached->get(data_name)
data++;
memcached->set(data_name, data)

memcached->delete(lock_name)


When things break down it appears that two clients are able to add
different "lock_id" values for the same lock_name. It's very hard to
track down the concurrency of this given the latency however, based on
the way the program runs, I can see values getting skipped as "data"
increments. On a local machine, no matter how many clients I run or
how fast they increment values don't get skipped.

If you have any thoughts or suggestion on why I might be having issues
with high latency clients I'd very intersted to know.

Thanks for your help!
Kevin


More information about the memcached mailing list