$start = microtime(true);
$num = 1000;
$step = 10000;
$count = $step * $num;
for ($i = 0; $i < $num; $i++) {
$items = [];
for ($j = 0; $j < $step; $j++) {
$items[] = [
'name' => uniqid(),
'created' => Carbon::now()->format('Y-m-d H:i:s'),
];
}
Db::table('users')->insert($items);
}
$end = microtime(true);
$output->writeln("insert " . $count/10000 . "w, use " . round($end - $start, 2) . 's');
如上代码,用webman开命令行 10个进程一起跑
写1亿条数据,用了大概12分钟
查询的时候比较奇怪,用DB Browser for SQLite查询,count总条数耗时大概3秒,用webman反而只耗时1s
你这第二次已经有数据库缓存了
mysql的buffer pool缓存了
机器配置:https://termbin.com/gk1y