简体   繁体   English

Laravel 迁移/数据库:种子超慢

[英]Laravel migrations/db:seed super slow

I recently upgraded from my old Windows computer into a gen.我最近从旧的 Windows 计算机升级到了 gen。 4 I7 Ubuntu 15.04 4 I7 Ubuntu 15.04

Runs like a dream, well...Except that any Laravel artisan command that touch the database takes a million years to complete, while my old computer performed any of those commands in seconds.像梦一样运行,嗯......除了任何涉及数据库的 Laravel 工匠命令都需要一百万年才能完成,而我的旧计算机在几秒钟内执行任何这些命令。

The major difference is that instead of XAMPP I'm running MySQL as a local service.主要区别在于,我将 MySQL 作为本地服务运行,而不是 XAMPP。

Also in my old computer I could see how migrations slowly showed on screen as they appear to be processed while now, it takes like 2~5 minutes and when done the whole migration list is shown at once.同样在我的旧计算机中,我可以看到迁移是如何在屏幕上缓慢显示的,因为它们现在似乎正在处理,大约需要 2 到 5 分钟,完成后会立即显示整个迁移列表。 This could indicate a bottle neck of sort somewhere.这可能表明某处存在某种瓶颈。

Somewhere around the internet someone said to use '127.0.0.1' instead of 'localhost' because of DSN resolution.在互联网的某个地方,有人说因为 DSN 解析而使用“127.0.0.1”而不是“localhost” Didn't solve it.没解决。

To make sure that's not the issue i ran为了确保这不是我跑的问题

    $time = microtime(true);

    //also with host=127.0.0.1
    new PDO("mysql:host=localhost;dbname=some_db", "username", "password");

    //some simple queries here...

    //yielded similar marginal times
    echo microtime(true) - $time;

~halp ~半


Edit编辑

I collected the running times for each query from the framework, I have LOTS of migrations, analyzing the data I found there's nothing insanely slow (like a query running for a minute).我收集了从框架中的每个查询的运行时间,我有迁徙的地段,分析我发现没有什么出奇的慢(就像一分钟运行查询)的数据。

Here's a link with the data .这是数据的链接 Actual queries were ommited in favor of my employer.我的雇主省略了实际查询。

Although there's many queries running for a second or longer, the slowest, number 221 takes a whoping 3.5 seconds.尽管有许多查询运行了 1 秒或更长时间,但最慢的number 221需要高达 3.5 秒。

I have around a hundred migrations(I know) but here's the thing, if each migration took a second I'd be waiting around a minute and a half to migrate, but it often takes from 4 to 5 minutes.我有大约一百次迁移(我知道),但问题是,如果每次迁移需要一秒钟,我会等待大约一分半钟才能迁移,但通常需要 4 到 5 分钟。

As suggested by oliverpool, I did some profiling by replaying queries on the mysql via terminal, but I never had to wait longer than a second with the average query taking around thenth of a second.正如 Oliverpool 所建议的,我通过终端在 mysql 上重放查询进行了一些分析,但我不必等待超过一秒,平均查询大约需要一秒左右。

Here is a pic of the profiling for the slowest query (3.5secs in migration, not close to a second in the pic)这是最慢查询的分析图片(迁移 3.5 秒,图片中不到一秒)

在此处输入图片说明

Maybe this points towards the connection?也许这指向连接? By the way the slow query log is empty after running the migrations.顺便说一下,运行迁移后慢查询日志是空的。

Also, I'm using laravel 5 now and the behaviour is the same.另外,我现在使用 laravel 5 并且行为是相同的。 I dont know how to trouble shoot connection so I guess some googling is in order, any suggestions are welcome.我不知道如何解决连接问题,所以我想可以使用谷歌搜索,欢迎提出任何建议。

Thanks in advance .提前致谢

In this case, I think that the buffer pool size increment is required.在这种情况下,我认为需要增加缓冲池大小。 Set the following:设置以下内容:

[mysqld]
innodb_io_capacity = 2000
innodb_read_io_threads = 64
innodb_thread_concurrency = 0
innodb_write_io_threads = 64

if you are using MySQL 8如果您使用的是 MySQL 8

in my case, the problem was MySQL 8 slower insert speed which occurred after updating MySQL 5.7 to 8就我而言,问题是 MySQL 8 的insert速度较慢,这是在将 MySQL 5.7 更新到 8 后发生的

A difference between 5.7 and 8.0 is that binary logging (to be used for replication and PITR) is on by default in MySQL 8.0. 5.7 和 8.0 之间的区别在于 MySQL 8.0 中默认启用二进制日志记录(用于复制和 PITR)。 To run without binary logging in 8.0在 8.0 中不使用二进制日志运行

the quick fix of this problem is to start your MySQL server with --disable-log-bin这个问题的快速解决方法是使用--disable-log-bin启动你的 MySQL 服务器

or you can write below codes in your my.cnf或者您可以在 my.cnf 中编写以下代码

[mysqld]
skip-log-bin

for more information, please visit欲了解更多信息,请访问

https://dba.stackexchange.com/questions/216352/inserts-in-mysql-8-are-slower-than-inserts-in-mysql-5-7?newreg=fe2b7682e8314f07a785ddc9a8ffbdce https://dba.stackexchange.com/questions/216352/inserts-in-mysql-8-are-slower-than-inserts-in-mysql-5-7?newreg=fe2b7682e8314f07a785ddc9a8ffbdce

https://dba.stackexchange.com/questions/227742/extreme-performance-loss-due-to-moving-from-mysql-5-7-23-to-mysql-8-0-status-c https://dba.stackexchange.com/questions/227742/extreme-performance-loss-due-to-moving-from-mysql-5-7-23-to-mysql-8-0-status-c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM