SQLite和100%CPU

时间:2015-10-20 07:37:12

标签: php sqlite ubuntu cpu

使用sqlite处理大数据,但Apache消耗100%CPU(Ubuntu上的服务器,mod上的PHP)。

PHP上的示例脚本:

$pdo = new PDO('sqlite:');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->query('CREATE TABLE `members` (uid INTEGER PRIMARY KEY, f INTEGER DEFAULT 1)');
for ($i=0; $i<250000; $i++){
    $uid = rand(1, 500000);
    $pdo->beginTransaction();
    $pdo->exec('INSERT OR IGNORE INTO members VALUES ('.$uid.', 0);');
    $pdo->exec('UPDATE members SET f = f + 1 WHERE
        uid = '.$uid);
    $pdo->commit();
}

$one_row = $pdo->query('SELECT COUNT(*) AS `count` FROM `members`')->fetch();

echo 'COUNT: '.$one_row['count']."\r";

是否可以限制CPU的消耗?或者我做错了什么?

0 个答案:

没有答案