[英]MySQL/MariaDB - Setting global variable “innodb_flush_log_at_trx_commit = 2” doesn't affect speed
I have set global variable of innodb_flush_log_at_trx_commit to 2 but when I run command ab.exe -n 200 -c 200 -s 9999 http://127.0.0.1/index.php
there is no difference in speed before and after that.我已将 innodb_flush_log_at_trx_commit 的全局变量设置为 2,但是当我运行命令
ab.exe -n 200 -c 200 -s 9999 http://127.0.0.1/index.php
之前和之后的速度没有区别。
When the value of the variable is 1当变量的值为 1
When the value of the variable is 2当变量的值为 2
The query inside the file is written in php/laravel:文件里面的查询是用 php/laravel 写的:
$status = ['enable', 'disable'];
try {
\DB::beginTransaction();
for($p = 1; $p <= 1000; $p++) {
$price = mt_rand(1000, 5000);
CarPrice::create([
'car_id' => $p,
'amount' => $price,
'status' => $status[rand(0, 1)],
]);
}
\DB::commit();
} catch (\Exception $exception) {
\DB::rollback();
die('Err!');
}
innodb_flush_log_at_trx_commit
, I restart the Apache and MariaDB.innodb_flush_log_at_trx_commit
时,我都会重新启动 Apache 和 MariaDB。You probably need to COMMIT
more than 100 transactions per second to see any difference.您可能需要每秒
COMMIT
超过 100 个事务才能看到任何差异。 That's with HDD;那是硬盘驱动器; if you have SDD, it might be 1000.
如果你有 SDD,它可能是 1000。
Are you doing the following?你在做以下事情吗?
START TRANSACTION;
INSERT
INSERT
...
INSERT -- 1000 1-row inserts in a single connection?
COMMIT; -- This is where that setting makes a difference.
The COMMIT
is such a tiny percentage of the total that it will be hard to measure. COMMIT
占总数的比例很小,很难衡量。
The real speed up is to do this:真正的加速是这样做的:
START TRANSACTION;
INSERT ... VALUES
( row ),
( row ),
...
( row ); -- one 1000-row insert?
COMMIT; -- This is where that setting makes a difference.
That will, however, require changes to your app code.但是,这将需要更改您的应用程序代码。
Potential issue: Do you need to grab Last_insert_id()
for each row?潜在问题:您需要为每一行获取
Last_insert_id()
吗?
PS: This would show off the diff with innodb_flush_log_at_trx_commit
; PS:这将展示与
innodb_flush_log_at_trx_commit
的差异; it will be much slower:它会慢得多:
START TRANSACTION;
INSERT
COMMIT;
START TRANSACTION;
INSERT
COMMIT;
... -- 1000 1-row inserts in a single connection
START TRANSACTION;
INSERT
COMMIT; -- after each row inserted!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.