Answer the question
In order to leave comments, you need to log in
Percona MySQL table locking
Good afternoon
I installed Percona MySQL server 5.5 + HandlerSocket. Decided to play. Here is the test script:
<?php
function out($line = '')
{
echo PHP_EOL.$line.PHP_EOL;
}
function sep()
{
out();
out('------------------------------');
out();
}
/**
* @param $pdo PDO
* @param $config array
*/
function run($pdo, $config)
{
$sql = "TRUNCATE products";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$numberOfInsertOps = $config['insert_number'];
$startInsertTime = microtime(true);
$sql = "INSERT INTO products (name, price) VALUES (:name, :price)";
$stmt = $pdo->prepare($sql);
for ($i = 0; $i < $numberOfInsertOps; $i++)
{
$name = md5(rand(0, 1000));
$price = rand(1, 1000);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':price', $price);
try
{
$result = $stmt->execute();
if (!$result)
{
out('shit happened');
}
out($pdo->lastInsertId());
}
catch (Exception $e)
{
sep($e->getMessage());
}
}
out('Insert in one query time: ' . ( microtime(true) - $startInsertTime) );
}
$pdo = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
run($pdo, array(
'insert_number' => 100
));
$pdo->errorInfo()
- it returns the code 0000 - it knows that everything is fine, just the number of affected rows is 0. 1
2
3
…
60
61
62
shit
62
shit
62
shit
62
shit
CREATE TABLE IF NOT EXISTS `products` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`price` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
$hs = new \HSPHP\WriteSocket();
$hs->connect();
$id = $hs->getIndexId('test','products','','name,price');
$startHandlerSocketInsertTime = microtime(true);
for ($i = 0; $i < $numberOfInsertOps; $i++)
{
$name = 'handler-'.md5(rand(0, 1000));
$price = rand(0, 1000);
$hs->insert($id, array($name, $price));
}
out('Insert HandlerSocket time: ' . ( microtime(true) - $startHandlerSocketInsertTime) );
if 10 loops - I have 100 rows in DB table
if 50 loops - 50 rows
if 100 loops - 100 rows
if 500 loops - 500 rows
if 1000 loops - ~1100 rows and this number will change every time the script is run.
Array (
[0] => 00000
[1] =>
[2] =>
)
An error occuredSQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query
Answer the question
In order to leave comments, you need to log in
looks like deadlock.
Try doing
CREATE TABLE innodb_monitor (i INT) ENGINE=INNODB;
Plus, you need to check the settings innodb_thread_concurrency and innodb_buffer_pool_instances
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question