缓慢的PHPUnit测试 [英] Slow PHPUnit Tests

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

问题描述

我正在运行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)?

任何回答都很感激.

推荐答案

您很可能会遇到

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

这就是他们在文档中> /a>:

Here's what they do from the docs:

barrier =< 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.

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

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