nothingworksinc / ticketbeast

Back to the lesson videos:
https://course.testdrivenlaravel.com/lessons
552 stars 11 forks source link

PHPUNIT very slow in Homestead #36

Open AdamEsterle opened 7 years ago

AdamEsterle commented 7 years ago

@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:

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 commented 7 years ago

If you can use Valet, use it. :p

Homestead is a joke for regular websites.

adamwathan commented 7 years ago

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 commented 7 years ago

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

jartaud commented 7 years ago

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 :sunglasses:. It's so damn slow :unamused:

svenluijten commented 7 years ago

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

drbyte commented 7 years ago

@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 commented 7 years ago

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

AdamEsterle commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

Don't use Homestead but rather a local web server like MAMP.

Also, use the pathcache option in the php.ini it makes it really faster. And try to use PHP7 if you can.

All in all, your Mac should be a lot faster since it uses Linux file system.

Envoyé de mon iPhone

Le 19 févr. 2017 à 17:54, Lee notifications@github.com<mailto:notifications@github.com> a écrit :

@adamwathanhttps://github.com/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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/nothingworksinc/ticketbeast/issues/36#issuecomment-280931626, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AHUtzEj4KENxsXUlKLGsYGyENVN9UFsgks5reHPFgaJpZM4L-QnD.

Helfull commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Do you have OPCache enabled

mstnorris commented 6 years ago

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