Is Laravel really this slow?

后端 未结 10 1576
长情又很酷
长情又很酷 2020-12-04 06:20

I just started using Laravel. I\'ve barely written any code yet, but my pages are taking nearly a second to load!

\"

相关标签:
10条回答
  • 2020-12-04 06:44

    Since nobody else has mentioned it, I found that the xdebug debugger dramatically increased the time. I served a basic "Hello World, the time is 2020-01-01T01:01:01.010101" dynamic page and used this in my httpd.conf to time the request:

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" **%T/%D**" combined
    

    %T is the serve time in seconds, %D is the time in microseconds. With this in my php.ini:

    [XDebug]
    xdebug.remote_autostart = 1
    xdebug.remote_enable = 1
    

    I was getting around 770ms response times, but with both of those set to 0 to disable them, it jumped to 160ms instantly. Running both of these brought it down to 120ms:

    php artisan route:cache
    php artisan config:cache
    

    The downside being that if I made config or route changes, I would need to re-cache them, which is annoying.

    As a sidenote, oddly, moving the site from my SSD to a spinning HDD provided no performance benefits, which is super odd to me, but I suppose it's maybe cached, I'm on Windows 10 with XAMPP.

    0 讨论(0)
  • 2020-12-04 06:46

    Yes - Laravel IS really that slow. I built a POC app for this sake. Simple router, with a login form. I could only get 60 RPS with 10 concurrent connections on a $20 digital ocean server (few GB ram);

    Setup:

    2gb RAM
    Php7.0
    apache2.4
    mysql 5.7
    memcached server (for laravel session)
    

    I ran optimizations, composer dump autoload etc, and it actually lowered the RPS to 43-ish.

    The problem is the app responds in 200-400ms. I ran AB test from the local machine laravel was on (ie, not through web traffic); and I got only 112 RPS; with 200ms faster response time with an average of 300ms.

    Comparatively, I tested my production PHP Native app running a few million requests a day on a AWS t2.medium (x3, load balanced). When I AB'd 25 concurrent connections from my local machine to that over web, through ELB, I got roughly 1200 RPS. Huge difference on a machine with load vs a laravel "login" page.

    These are pages with Sessions (elasticache / memcached), Live DB lookups (cached queries via memcached), Assets pulled over CDNs, etc, etc, etc.

    What I can tell, laravel sticks about 200-300ms load over things. Its fine for PHP Generated views, after all, that type of delay is tolerable on load. However, for PHP views that use Ajax/JS to handle small updates, it begins to feel sluggish.

    I cant imagine what this system would look like with a multi tenant app while 200 bots crawl 100 pages each all at the same time.

    Laravel is great for simple apps. Lumen is tolerable if you dont need to do anything fancy that would require middleware nonsense (IE, no multi tenant apps and custom domains, etc);

    However, I never like starting with something that can bind and cause 300ms load for a "hello world" post.

    If youre thinking "Who cares?"

    .. Write a predictive search that relies on quick queries to respond to autocomplete suggestions across a few hundred thousand results. That 200-300ms lag will drive your users absolutely insane.

    0 讨论(0)
  • 2020-12-04 06:48

    From my Hello World contest, Which one is Laravel? I think you can guess. I used docker container for the test and here is the results

    To make http-response "Hello World":

    • Golang with log handler stdout : 6000 rps
    • SpringBoot with Log Handler stdout: 3600 rps
    • Laravel 5 with off log :230 rps
    0 讨论(0)
  • 2020-12-04 06:49

    Laravel is slow, because in most cases, using PHP for web pages is slow.

    With Laravel, the entire framework is rebuilt on every invocation - that is why all pages point to index.php. Since the entire framework is PHP scripts, they all need to go through the PHP interpreter - each time. The larger the framework, the longer this takes.

    Contrast this with a "server environment" (e.g. tomcat) where the server runs the initialization code once, and eventually all pages will be in native code (after JIT).

    As a reference example, using the same hardware, OS, etc. a simple 'hello world' using JSP on this hardware is 3000 rps, the same hello world on laravel is 51 rps.

    The easiest way to test framework overhead, and the resulting maximum RPS per core, is to use Apache AB and a concurrency value of 1, with a simple 'hello world' that is dynamic (to avoid static page caching).

    0 讨论(0)
  • 2020-12-04 06:50

    I faced 1.40s while working with a pure laravel in development area!

    the problem was using: php artisan serve to run the webserver

    when I used apache webserver (or NGINX) instead for the same code I got it down to 153ms

    0 讨论(0)
  • 2020-12-04 06:51

    I found that biggest speed gain with Laravel 4 you can achieve choosing right session drivers;

    Sessions "driver" file;
    
    Requests per second:    188.07 [#/sec] (mean)
    Time per request:       26.586 [ms] (mean)
    Time per request:       5.317 [ms] (mean, across all concurrent requests)
    
    
    Session "driver" database;
    
    Requests per second:    41.12 [#/sec] (mean)
    Time per request:       121.604 [ms] (mean)
    Time per request:       24.321 [ms] (mean, across all concurrent requests)
    

    Hope that helps

    0 讨论(0)
提交回复
热议问题