测试脚本
date;echo {1..500} | xargs -n 1 -P 50 /bin/sh -c "mysql -uroot -proot -e 'xxxxxxxxx' 1>/dev/null 2>/dev/null";date
insert..on duplicate key for update, insert ignore性能对比
$date;echo {1..50000} | xargs -n 1 -P 50 /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql -e "insert into test.it values ('test_dup') on duplicate key update name=values(name)"";date
2021年 03月 31日 星期三 12:35:41 CST
2021年 03月 31日 星期三 12:36:21 CST
$date;echo {1..50000} | xargs -n 1 -P 50 /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql -e "insert ignore into test.it values ('test_ig')"";date
2021年 03月 31日 星期三 12:36:47 CST
2021年 03月 31日 星期三 12:37:20 CST
经过测试后发现,使用insert ignore性能更好
select for update性能对比
$date;echo {1..50000} | xargs -n 1 |xargs -P 50 -i /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql test -e 'begin;select c2 from t1 where c1={};commit;' 1>/dev/null";date
2021年 04月 27日 星期二 18:53:56 CST
2021年 04月 27日 星期二 18:54:50 CST
$date;echo {1..50000} | xargs -n 1 |xargs -P 50 -i /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql test -e 'begin;select c2 from t1 where c1={} for update;commit;' 1>/dev/null";date
2021年 04月 27日 星期二 18:55:00 CST
2021年 04月 27日 星期二 18:56:01 CST
$date;echo {1..50000} | xargs -n 1 |xargs -P 50 -i /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql test -e 'begin;select c2 from t1 where c1={} for update wait 3;commit;' 1>/dev/null";date
2021年 04月 27日 星期二 18:56:18 CST
2021年 04月 27日 星期二 18:57:19 CST
$date;echo {1..50000} |xargs -d" " -n 1 -P 50 -i /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql test -e 'begin;select c2 from t1 where c1={};commit;' 1>/dev/null";date
2021年 04月 27日 星期二 18:57:57 CST
2021年 04月 27日 星期二 18:58:38 CST
$date;echo {1..50000} |xargs -d" " -n 1 -P 50 -i /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql test -e 'begin;select c2 from t1 where c1={} for update;commit;' 1>/dev/null";date
2021年 04月 27日 星期二 18:59:40 CST
2021年 04月 27日 星期二 19:00:37 CST
$date;echo {1..50000} |xargs -d" " -n 1 -P 50 -i /bin/sh -c "mysql -h11.166.78.136 -P32601 -uroot@mysql test -e 'begin;select c2 from t1 where c1={} for update wait 3;commit;' 1>/dev/null";date
2021年 04月 27日 星期二 19:01:02 CST
2021年 04月 27日 星期二 19:02:00 CST