mardi 20 octobre 2015

SQLite and 100% CPU [duplicate]

This question already has an answer here:

To work with big data using sqlite, but Apache consumes 100% CPU (server on Ubuntu, PHP on mod Apache).

Example script on 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";

Is it possible to limit the consumption of CPU? Or have I done something wrong?

Aucun commentaire:

Enregistrer un commentaire