<?php include 'db.php'; echo `rm -rf test`; mkdir('test'); $db = new YNDb('test'); $db->create('cdr', array('id' => 'INT', 'cust' => 'INT', 'dt' => 'TINYTEXT'), array('AUTO_INCREMENT' => 'id', 'INDEX' => array('cust'))); date_default_timezone_set('Europe/Moscow'); for ($i = 0; $i < 25; $i++) { $db->insert('cdr', array('cust' => mt_rand(0, 4), 'dt' => date('Y-m-d H:i:s'))); sleep(mt_rand(1, 3)); }
<?php include 'parallel-const.php'; // 2^2 = 4 processes if (pcntl_fork()) { usleep(mt_rand(0, 10000000)); } // sleep for some interval... if (pcntl_fork()) { usleep(mt_rand(0, 10000000)); } // sleep for some interval... //if(pcntl_fork()) usleep(mt_rand(0,10000000)); // sleep for some interval... //if(pcntl_fork()) usleep(mt_rand(0,10000000)); // sleep for some interval... //if(pcntl_fork()) usleep(mt_rand(0,10000000)); // sleep for some interval... //if(pcntl_fork()) usleep(mt_rand(0,10000000)); // sleep for some interval... $pid = posix_getpid(); // it is essential to initialize YNDb AFTER fork() $MOO = new YNDb('./data'); for ($i = 0; $i < NUM_SELECTS; $i++) { $br = mt_rand(0, INSERT_VALUES / AVG_BAD_RAND); echo "{$pid} Begins select #{$i} with {$br}\n"; $res = $MOO->select('test', array('cond' => array(array('bad_rand', '=', $br)), 'limit' => INSERT_VALUES)); echo "{$pid} Selected " . sizeof($res) . " rows (excepted around " . AVG_BAD_RAND . " rows)\n"; echo "{$pid} Begin results testing\n"; foreach ($res as $k => $v) { if ($v['bad_rand'] != $br) { die('Invalid row #' . $k . ': ' . print_r($v, true)); } } }
<?php header('Content-type: text/html; charset="UTF-8"'); error_reporting(E_ALL); ini_set('display_errors', 'On'); include '../Client.php'; if (!isset($_REQUEST['act']) && isset($argv[1])) { $_REQUEST['act'] = $argv[1]; } $db = new YNDb('./data'); function print_res($res) { if ($res && is_array($res)) { $keys = array_keys($res[0]); echo '<table border=1><tr>'; foreach ($keys as $v) { echo '<th>' . $v . '</th>'; } echo '</tr>'; foreach ($res as $v) { echo '<tr>'; foreach ($keys as $k) { echo '<td>' . $v[$k] . '</td>'; } echo '</tr>'; } echo '</table>'; } else { echo '<table border=1><tr><td>' . ($res ? 'TRUE' : 'FALSE') . '</td></tr></table>'; } }
<?php include 'parallel-const.php'; //system('rm -r ./data/*'); // compare performance on single proccess // versus two processes // 2 parallel inserts pcntl_fork(); //pcntl_fork(); //pcntl_fork(); //$pid = 0; echo "Initializing YNDb\n"; $MOO = new YNDb('data'); echo "Create table test\n"; try { $MOO->create('test', array('id' => 'INT', 'bad_rand' => 'INT', 'name' => 'TINYTEXT'), array('AUTO_INCREMENT' => 'id', 'INDEX' => array('bad_rand'))); } catch (Exception $e) { echo "Caught exception: " . $e->getMessage() . "\n"; } usleep(1000); // sleep just a moment to ensure that table is created echo "Inserting " . INSERT_VALUES . " values\n"; for ($i = 0; $i < INSERT_VALUES; $i++) { if ($i % 50 == 0) { echo 'Inserted ' . $MOO->insert_id() . "\n"; } $br = mt_rand(0, INSERT_VALUES / AVG_BAD_RAND); //echo 'inserting br = '.$br."\n"; $MOO->insert('test', array('name' => 'entry #' . $i, 'bad_rand' => $br)); // }
function set_error($err) { return parent::set_error('DataInterface (internal) error: ' . $err); }