Esempio n. 1
0
 function createWorkerInfoTable()
 {
     $this->workerInfoTable = new \swoole_table($this->sw_table_size);
     $this->workerInfoTable->column(self::$memoryKey, \swoole_table::TYPE_INT, 8);
     $this->workerInfoTable->create();
     $this->workerInfoTable->set(self::$memoryKey, [self::$memoryKey => 0]);
     $this->sessionTable = new \swoole_table(65536);
     $this->sessionTable->column(self::$sessionKey, \swoole_table::TYPE_STRING, 1024 * 4);
     $this->sessionTable->column('time', \swoole_table::TYPE_INT, 11);
     $this->sessionTable->create();
 }
Esempio n. 2
0
 private function initSwooleTable()
 {
     $swoole_table = new \swoole_table(static::SWOOLE_TABLE_SIZE);
     $swoole_table->column("value", \swoole_table::TYPE_INT, 4);
     $swoole_table->create();
     return $swoole_table;
 }
Esempio n. 3
0
File: table.php Progetto: cjq/tests
 static function run()
 {
     $table = new swoole_table(1024 * 256);
     $table->column('index', swoole_table::TYPE_INT);
     $table->column('serid', swoole_table::TYPE_INT);
     $table->column('data', swoole_table::TYPE_STRING, 64);
     $table->create();
     self::$table = $table;
     for ($i = 0; $i < self::$key_num; $i++) {
         $key = 'user_' . (self::$key_base + $i);
         $ret = self::$table->set($key, array('index' => $i, 'serid' => rand(1000, 9999), 'data' => "hello_world_{$i}"));
         if (!$ret) {
             echo "count {$i} failed.";
             break;
         }
     }
     for ($i = 0; $i < self::$worker_num; $i++) {
         $process = new swoole_process('UnitTest_Table::worker');
         $process->start();
         $workers[$i] = $process;
     }
     for ($i = 0; $i < self::$worker_num; $i++) {
         $exit = swoole_process::wait();
         echo "worker[{$i}] exit\n";
     }
 }
 private function _initTable()
 {
     $this->subscribers = new \swoole_table(4096);
     $this->subscribers->column('channel', \swoole_table::TYPE_STRING, 128);
     if (!$this->subscribers->create()) {
         Cli::error("Failed to call swoole_table::create().");
     }
 }
Esempio n. 5
0
 public function __construct($config)
 {
     if (empty($this->table)) {
         $table = new swoole_table(1024);
         $table->column('data', swoole_table::TYPE_STRING, 64);
         $table->create();
         $this->table = $table;
     }
 }
Esempio n. 6
0
 public function __construct(\swoole_server $server)
 {
     $defaultRow = 1;
     //1个基本统计量
     $rowPerWorker = 2;
     $rowPerTaskWorker = 4;
     //3个固定位置加1个记录pkTask的位置
     $this->server = $server;
     $workerNum = $server->setting['worker_num'];
     $taskNum = $server->setting['task_worker_num'];
     $rowCount = $defaultRow + $workerNum * $rowPerWorker + $taskNum * $rowPerTaskWorker;
     $rowCount = log10($rowCount) / log10(2);
     //以2为底求需要的最小倍数
     $rowCount = (int) ($rowCount + 1);
     //即便没有余数也+1取整保证留有一定的余地
     $rowCount = pow(2, $rowCount);
     //获得最接近的行数
     //Log::Debug("Monitor row count set to $rowCount");
     $this->table = new \swoole_table($rowCount);
     $this->table->column(self::FIELD, \swoole_table::TYPE_INT);
     $this->table->create();
     //初始化默认字段
     $this->Set(self::REQUEST_NUM);
     for ($i = 0; $i < $workerNum; $i++) {
         $this->Set($this->workerRequsetNum($i));
         $this->Set($this->workerSendCountField($i));
     }
     for ($i = 0; $i < $taskNum; $i++) {
         $taskWorkerID = $i + $workerNum;
         $this->Set($this->taskReceiveCountField($taskWorkerID));
         $this->Set($this->taskWorkerLastWorkerIDField($taskWorkerID));
         $this->Set($this->taskWorkerLastTaskIDField($taskWorkerID));
     }
     $this->taskNum = $taskNum;
     $this->workerNum = $workerNum;
 }
Esempio n. 7
0
 public function __construct()
 {
     $table = new \swoole_table(128);
     //$table->column('statistics', \swoole_table::TYPE_STRING, 64);
     $table->column('count', \swoole_table::TYPE_INT, 8);
     $table->column('spend', \swoole_table::TYPE_FLOAT);
     $table->column('get', \swoole_table::TYPE_INT, 8);
     $table->column('post', \swoole_table::TYPE_INT, 8);
     $table->column('options', \swoole_table::TYPE_INT, 8);
     $table->column('head', \swoole_table::TYPE_INT, 8);
     $table->column('put', \swoole_table::TYPE_INT, 8);
     $table->column('delete', \swoole_table::TYPE_INT, 8);
     $table->column('trace', \swoole_table::TYPE_INT, 8);
     $table->column('z200', \swoole_table::TYPE_INT, 8);
     $table->column('z201', \swoole_table::TYPE_INT, 8);
     $table->column('z202', \swoole_table::TYPE_INT, 8);
     $table->column('z204', \swoole_table::TYPE_INT, 8);
     $table->column('z303', \swoole_table::TYPE_INT, 8);
     $table->column('z404', \swoole_table::TYPE_INT, 8);
     $table->column('other', \swoole_table::TYPE_INT, 8);
     $table->create();
     $this->table = $table;
 }
Esempio n. 8
0
<?php

$table = new swoole_table(1024);
$table->column('id', swoole_table::TYPE_INT, 4);
//1,2,4,8
$table->column('name', swoole_table::TYPE_STRING, 64);
$table->column('num', swoole_table::TYPE_FLOAT);
$table->create();
$worker = new swoole_process('child1', false, false);
$worker->start();
//child
function child1($worker)
{
    global $table;
    $table->set('*****@*****.**', array('id' => 145, 'name' => 'rango', 'num' => 3.1415));
    $table->set('*****@*****.**', array('id' => 358, 'name' => "Rango1234", 'num' => 3.1415));
    $table->set('*****@*****.**', array('id' => 189, 'name' => 'rango3', 'num' => 3.1415));
    sleep(100000);
}
//master
sleep(1);
$s = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $arr = $table->get('*****@*****.**');
}
echo "use: " . (microtime(true) - $s) * 1000 . "ms\n";
//var_dump($table->get('*****@*****.**'));
sleep(100000);
Esempio n. 9
0
 public static function init()
 {
     if (defined('SWOOLE_DEAMON')) {
         $table = new swoole_table(1024);
         $table->column('ctime', swoole_table::TYPE_INT, 4);
         //缓存创建时间戳
         $table->column('etime', swoole_table::TYPE_INT, 4);
         //缓存失效时间戳
         $table->column('file', swoole_table::TYPE_STRING, 64);
         //缓存文件路径
         $table->create();
         self::$table = $table;
     } else {
         self::$table = new cache\cacheModel('file');
         self::$table->in('router');
     }
 }