Phalcon bulk insert-performance. Modelle oder Raw-SQL

Gibt es einen Weg, um bulk-inserts in phalcon php?

Ich habe versucht, das einfügen von 10000 Datensätze, die mit \Phalcon\Mvc\Model create und das gleiche auch mit raw-SQL: insert into 'tablename' (a, b, c) values (), (), (), ... ()

Ich diesem sehr einfachen test, und war von den Ergebnissen überrascht

  • mit \Phalcon\Mvc\Modell dauerte etwa 36 Sekunden
  • mit raw-sql dauerte 3,6 Sekunden.

\Phalcon\Mvc\Modell:

$transactionManager = new TransactionManager(); 

$transaction = $transactionManager->get();

$entity = new Entity();
$entity->setTransaction($transaction);
for($i = 0; $i < 10000; $i++){
    $entity->setValue1(rand(1,50));
    $entity->setValue2(rand(1,50));
    $entity->setValue3(rand(1,50));
}
$entity->create();
$transaction->commit();

Raw-SQL:

$query = "insert into 'tablename' (a, b, c) values ";

for($i = 0; $i < 10000; $i++){
    $values .= "(" . rand(1,50) . ", " . rand(1, 50). ", " . rand(1, 50). "),";
}

$values = substr($values, 0, strlen($values) - 1);
$query .= $values;
$this->db->query($query);
InformationsquelleAutor lloiacono | 2014-02-14
Schreibe einen Kommentar