比如1个数据库连接,串行执行:
select * from table1 where field1 like '%abc%' 耗时50ms
select * from table2 where field1 like '%abc%' 耗时50ms
select * from table3 where field1 like '%abc%' 耗时50ms
select * from table4 where field1 like '%abc%' 耗时50ms
select * from table5 where field1 like '%abc%' 耗时50ms5个数据库连接,并行同时执行:
select * from table1 where field1 like '%abc%' 耗时220ms
select * from table2 where field1 like '%abc%' 耗时220ms
select * from table3 where field1 like '%abc%' 耗时220ms
select * from table4 where field1 like '%abc%' 耗时220ms
select * from table5 where field1 like '%abc%' 耗时220ms为什么并行执行,查询效率明显比串行低(同一张表,原先只要50ms,现在却要220ms),是不是mysql端没有优化好?
select * from table1 where field1 like '%abc%' 耗时50ms
select * from table2 where field1 like '%abc%' 耗时50ms
select * from table3 where field1 like '%abc%' 耗时50ms
select * from table4 where field1 like '%abc%' 耗时50ms
select * from table5 where field1 like '%abc%' 耗时50ms5个数据库连接,并行同时执行:
select * from table1 where field1 like '%abc%' 耗时220ms
select * from table2 where field1 like '%abc%' 耗时220ms
select * from table3 where field1 like '%abc%' 耗时220ms
select * from table4 where field1 like '%abc%' 耗时220ms
select * from table5 where field1 like '%abc%' 耗时220ms为什么并行执行,查询效率明显比串行低(同一张表,原先只要50ms,现在却要220ms),是不是mysql端没有优化好?
串行总共250ms
1 和硬盘有关
2 和缓存有关。
3 可以分别测多核cpu+innodb pk myisam ,也就是说和cpu核数和存储引擎有关。可以试着测测并行数逐渐增加的情况下,性能的差异。
单线程下,磁头重头扫描到尾
多线程下,线程1要读A区,线程2有命令它去S区,线程3又命令它到B区,线程4又需要它去X区,来回移动,速度当然慢了。