[英]MySQL/MariaDB - Setting global variable “innodb_flush_log_at_trx_commit = 2” doesn't affect speed
我已將 innodb_flush_log_at_trx_commit 的全局變量設置為 2,但是當我運行命令ab.exe -n 200 -c 200 -s 9999 http://127.0.0.1/index.php
之前和之后的速度沒有區別。
文件里面的查詢是用 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
時,我都會重新啟動 Apache 和 MariaDB。您可能需要每秒COMMIT
超過 100 個事務才能看到任何差異。 那是硬盤驅動器; 如果你有 SDD,它可能是 1000。
你在做以下事情嗎?
START TRANSACTION;
INSERT
INSERT
...
INSERT -- 1000 1-row inserts in a single connection?
COMMIT; -- This is where that setting makes a difference.
COMMIT
占總數的比例很小,很難衡量。
真正的加速是這樣做的:
START TRANSACTION;
INSERT ... VALUES
( row ),
( row ),
...
( row ); -- one 1000-row insert?
COMMIT; -- This is where that setting makes a difference.
但是,這將需要更改您的應用程序代碼。
潛在問題:您需要為每一行獲取Last_insert_id()
嗎?
PS:這將展示與innodb_flush_log_at_trx_commit
的差異; 它會慢得多:
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.