connect(new ClientConfiguration('localhost:10800')); $cache = $cli->getOrCreateCache('concurrency_cache')->setKeyType(ObjectType::STRING)->setValueType(ObjectType::INTEGER); for($i = 0; $i < NOPS/NTHREADS; $i++) { $hot = $cache->get('hot'); $hot = $hot + 1; $cache->put('hot', $hot); } $cli->disconnect(); } function test3() { $cli = new Client(); $cli->connect(new ClientConfiguration('localhost:10800')); $cache = $cli->getOrCreateCache('concurrency_cache')->setKeyType(ObjectType::STRING)->setValueType(ObjectType::INTEGER); for($i = 0; $i < NOPS/NTHREADS; $i++) { $done = FALSE; while(!$done) { $hot1 = $cache->get('hot'); $hot2 = $hot1 + 1; $done = $cache->replaceIfEquals('hot', $hot1, $hot2); } } $cli->disconnect(); } function dispatch($me, $f) { $cmd = sprintf('%s -d include_path=%s %s %s', PHP_BINARY, get_include_path(), $me, $f); shell_exec($cmd); } function test($lbl, $me, $f) { $cli = new Client(); $cli->connect(new ClientConfiguration('localhost:10800')); $cache = $cli->getOrCreateCache('concurrency_cache')->setKeyType(ObjectType::STRING)->setValueType(ObjectType::INTEGER); $t1 = gettimeofday(TRUE); $cache->put('hot', 0); $t = array(); for($i = 0; $i < NTHREADS; $i++) { $t[] = new Thread(); $t[$i]->addFunctionTask('dispatch', $me, $f); } for($i = 0; $i < NTHREADS; $i++) { $t[$i]->start(); } for($i = 0; $i < NTHREADS; $i++) { $t[$i]->join(); } $hot = $cache->get('hot'); $t2 = gettimeofday(TRUE); echo sprintf("%s : %d = %d (%d ms)\r\n", $lbl, $hot, NOPS, (int)(($t2 - $t1) * 1000)); $cli->disconnect(); } if(count($argv) < 2) { test('No handling', $argv[0], 'test1'); // locking not supported using thin test('Replace with check', $argv[0],'test3'); // atomic increment not supported using thin } else { $argv[1](); } ?>