Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUNIT very slow in Homestead #36

Open
AdamEsterle opened this issue Feb 11, 2017 · 16 comments
Open

PHPUNIT very slow in Homestead #36

AdamEsterle opened this issue Feb 11, 2017 · 16 comments

Comments

@AdamEsterle
Copy link
Collaborator

AdamEsterle commented Feb 11, 2017

@adamwathan
Do you have recommendations on where to run your tests?
I use homestead on both my mac and windows and it is very slow
Homestead is configured to have 8GB ram and 4 CPUs. It is also on the latest version (1.1.0)

Your whole test suite (except the Stripe tests) runs in about 500ms when you run phpunit

When already SSH'ed into Homestead:

  • If I run one method with just $this->assertTrue(true); in the method
    It takes 2 seconds
  • If I run it with DatabaseMigrations it takes about 4 seconds
  • This is for :memory: and MySql databases (sqlite in memory is slightly faster)

I am going to use your "DatabaseSetup" trait, but that still does a migration

So bottom line is that a single test takes at least 4 seconds to run

Thoughts?
Should I run phpunit on my Mac/Windows instead of inside Homestead?

UPDATE

Just put type: "nfs" in my Homestead.yaml file
It is faster (1.5s instead of 4s and .5s instead of 2s (without migrations)), but still nothing like what you are running

UPDATE 2

Running phpunit on my host (mac) is blazing fast.
90ms for just the test and 350ms with a migration

So that seems to solve the problem. But is there a way to solve it and still use Homestead? It would be nice to not have to worry about what is installed on your host machine.

Tangent

After installing php on my host and seeing how blazing fast the tests were, it makes me think: Should I just stop using Homestead and start using Valet? Perhaps the rest of my application would be way faster without Homestead?

@zaknesler
Copy link
Collaborator

If you can use Valet, use it. :p

Homestead is a joke for regular websites.

@adamwathan
Copy link
Collaborator

Yeah everything is miles faster if you can run PHP right on your normal machine, like we do with Valet. For apps I'm running locally, I get about a ~10ms response time on most pages, whereas using a virtual machine, it would often be 300-400ms, sometimes more!

Virtual machines are just really, really slow sadly 😔

@svenluijten
Copy link
Collaborator

Try running phpunit from your local machine directly. My tests are about 2-3 times faster locally compared to within Homestead.

@jartaud
Copy link
Collaborator

jartaud commented Feb 12, 2017

Sadly at work (doing good old java + jsp + oracle), they got me a PC laptop. I have to use Homestead + cmder working on my personal stuff 😎. It's so damn slow 😒

@svenluijten
Copy link
Collaborator

I'm on Windows as well, @jartaud. Running phpunit directly from the local machine (so not from within Homestead) runs fine for me.

@drbyte
Copy link
Collaborator

drbyte commented Feb 12, 2017

@AdamEsterle Here's how I tackle it:

a) I use Valet for all my normal development work. This lets me do blazing fast unit/integration testing too.

b) In the rare occasions where I need to have an exact clone of the Production Server, I use a virtual machine, often Homestead. I'm finding this is less and less necessary all the time ... but that's usually because I have DevOps access to the production server, or have easy access to the person who does.

If it was more of a "black box" and had some very specific configuration needs that I couldn't emulate sufficiently in Valet, then I'd need a virtual machine.

Further, I also find that most of my deployments happen over Forge ... so if I need a clone, then Homestead is an easy grab. But even then, Valet is still adequate in 99% of cases.

I definitely prefer Valet over Homestead, both for speed and simplicity.

@jartaud
Copy link
Collaborator

jartaud commented Feb 12, 2017

@svenluijten Running phpunit directly from windows is even slower for me. Maybe cmder is to blame. I'll test it with cmd prompt.

@AdamEsterle
Copy link
Collaborator Author

@jartaud I use git bash. Works nicely.

But for my actual workflow, I run my tests in PhpStorm. Easy hotkey setup to run: single test, the whole file, or just failed tests.

@coxlr
Copy link
Collaborator

coxlr commented Feb 19, 2017

@adamwathan do you know of any reasons why tests would be running slow when running directly from my mac?

I have the same code on both Windows and Mac and my Mac is running the tests a lot slower. Around 9 seconds compared to 900ms on Windows.

I have been trying to debug without much luck.

@adamwathan
Copy link
Collaborator

@coxy121 Hmm not sure, the first thing that comes to mind is checking if you have XDebug installed/enabled on your Mac; it really slows things down a lot.

You can use php -i | grep xdebug to look for some clues to see if it's enabled 👍

@coxlr
Copy link
Collaborator

coxlr commented Feb 19, 2017

@adamwathan thanks. I removed xdebug and that took about 1 second off the total time, so is now runs 9 test in about 8 seconds. So still a lot slower than on my Windows set up at 900ms.

I rebooted and ran phpunit as soon as system started up which ran the tests in less than 2 seconds, a few minutes later it was back to running at 8-9 seconds. So seems like I may have something else running that may be slowing it down.

@Nestecha
Copy link
Collaborator

Nestecha commented Feb 20, 2017 via email

@Helfull
Copy link
Collaborator

Helfull commented Aug 8, 2017

hey i am having the same problem on my windows pc, if i run the laravel testcase i get around 500-900ms for a single assertTrue(true), but if i run without the laravel testcase, just the basic PhpUnit testcase, it speeds up to 150-160ms.

PHP 7.1.5
xDebug is disabled

not runnig in homestead or anything special just plain cmd prompt

tested with cmdr git bash same result

@jartaud
Copy link
Collaborator

jartaud commented Aug 13, 2017

strace points me to MSWSOCK.DLL. I backuped it and then deleted it, my tests run fast but fail because mysql and a bunch of other stuff stop working.

I restored MSWSOCK.DLL and now everything works fast and great.

@mikeerickson
Copy link
Collaborator

Do you have OPCache enabled

@mstnorris
Copy link
Collaborator

@mikeerickson would OPCache speed it up or slow it down?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests