缓慢的 PHP 单元测试 [英] Slow PHPUnit Tests

查看:29
本文介绍了缓慢的 PHP 单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 PHPUnit 以使用 CIUnit(两者之间的第三方接口)测试 CodeIgniter 应用程序.许多测试从一个空的 MySQL 数据库中选择数据,该数据库在 setUp() 中填充了 5-10 条记录.在 Windows 和 Web 服务器(Ubuntu 10.04/Apache 2.2/MySQL 5.1/PHP 5.3)上,105 个测试在 2-3 秒内运行,内存使用量约为 30mb.在我的本地(Ubuntu 12.04/Apache 2.2/MySQL 5.5/PHP 5.3)上,105 个测试以相同的内存使用量运行,但大约需要 45 秒.

I am running PHPUnit to test a CodeIgniter application using CIUnit (a third party interface between the two). A number of the tests select data from an empty MySQL database that is populated with 5-10 records in setUp(). On Windows and the web server (Ubuntu 10.04/Apache 2.2/MySQL 5.1/PHP 5.3), the 105 tests run in 2-3 seconds with a memory usage of around 30mb. On my local (Ubuntu 12.04/Apache 2.2/MySQL 5.5/PHP 5.3), the 105 tests run with the same memory usage, but take approx 45 seconds.

我已经缩小了使用数据库的测试的速度;是否有任何我可能缺少的配置设置使测试运行速度慢了 15 倍?如果没有,我最好的选择是尝试降级 MySQL,甚至是 Ubuntu(我已经尝试从 12.10 降级到 12.04)?

I have narrowed down the slowness to tests which utilise the database; are there any configuration settings that I am possibly missing that are making the tests run 15 times slower? If not, would my best bet be to try downgrading MySQL, or maybe even Ubuntu (I have already tried downgrading from 12.10 to 12.04)?

非常感谢任何答案.

推荐答案

您很可能会遇到 barriers 是 ext4 文件系统中的默认设置.在此处阅读更多内容:

You are most likely running into the performance hit created by barriers being default on in the ext4 filesystem. Read more of them here:

这是他们所做的来自文档:

障碍=<0|1(*)>
jbd 代码.barrier=0 禁用,barrier=1 启用.这也是需要一个可以支持屏障的 IO 堆栈,并且如果 jbd 得到一个屏障写入时出错,它将再次禁用并发出警告.写屏障强制执行日志提交的正确磁盘排序,使易失性磁盘写入缓存可以安全使用,但会降低一些性能.如果您的磁盘以一种或另一种方式由电池供电,则禁用障碍可以安全地提高性能.

barrier=<0|1(*)>
the jbd code. barrier=0 disables, barrier=1 enables. This also requires an IO stack which can support barriers, and if jbd gets an error on a barrier write, it will disable again with a warning. Write barriers enforce proper on-disk ordering of journal commits, making volatile disk write caches safe to use, at some performance penalty. If your disks are battery-backed in one way or another, disabling barriers may safely improve performance.

您可以尝试在没有它们的情况下重新挂载文件系统(使用 mysql 数据文件所在的挂载点)

You can try to remount your filesystem without them like this (use the mount point where the mysql data files are living)

mount -o remount,nobarrier /

在我的环境中,这使得 Tests: 83, Assertions: 194 套件的运行时间从 48 秒减少到 6 秒.

In my environment this makes a Tests: 83, Assertions: 194 suite's runtime reduce from 48 seconds to 6.

这篇关于缓慢的 PHP 单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆