laravel vs lumen 執行對比

環境

  • centos7 + docker(alpine3.7)php

    • 1核
    • 內存2G
  • php7.1.17
  • 開啓opcache
  • 性能監控tideways_xhprof
  • composer 使用生產環境命令進行安裝laravel

    composer install --no-dev --optimize-autoloader --prefer-dist

統一執行 vension 打印

框架 執行時間 內存
lumen 8ms 0.4MB
lumen + Facades 8.5ms 0.5MB
lumen + Facades + Eloquent 13ms~14ms 0.8MB
laravel 50ms~60ms 1.6MB

最主要差別:33.667ms

  • 加載全部config文件:6.711ms
  • Provider register: 5.756ms
  • Provider boot: 8.048ms
  • Route Middleware: 9.084ms
  • terminateMiddleware: 4.068ms

lumen + Facades + Eloquent 整理時間線

  • 總體docker

    • 執行時間: 13.284ms
    • cpu時間: 13.1ms
  • public/index.phpbootstrap

    • bootstrap/app.phpcentos

      • vendor/autoload.php: 0.617ms
      • Dotenv load: 1.882ms 改成php加載
      • Application::__construct: 0.674ms
      • withFacades: 0.455ms
      • withEloquent: 5.144ms 如何動態加載?php7

        • loadComponent database: 4.931msapp

          • configure: 0.5ms ==可優化==
          • DatabaseServiceProvidercomposer

            • register: 0.684ms
            • boot: 0.981ms
          • PaginationServiceProvider框架

            • register: 0.167ms
            • boot: 2.115ms 可優化
      • Router::group: 0.215ms
    • Application::run: 3.758mside

      • dispatch: 3.479ms

        • parseIncomingRequest: 2.643ms

          • Request::capture: 2.007ms

            • Request::createFromGlobals: 0.984ms

              • Request::createRequestFromFactory: 0.947ms

                • Request::initialize: 0.982ms
            • Request::createFromBase: 1.005ms

              • Request::duplicate: 0.789ms 爲何須要複製一份?
        • sendThroughPipeline: 0.826ms
      • Response::send: 0.263ms

laravel 整理時間線

  • 總體

    • 執行時間:54.3ms
    • CPU時間:53.2ms
  • public/index.php

    • vendor/autoload.php: 0.926ms
    • bootstrap/app.php

      • Application::__construct: 1.471ms

        • registerBaseServiceProviders: 0.708ms
      • make Kernel: 1.3ms
      • Request::capture: 1.841ms
      • kernel::handle: 43.308ms

        • Kernel::sendRequestThroughRouter: 43.117ms

          • bootstrap: 28.188ms

            • Application::bootstrapWith: 28.175ms

              • LoadEnvironmentVariables::bootstrap: 4.372ms

                • Dotenv::load: 4.212ms
              • LoadConfiguration::bootstrap: 6.711ms 加載全部config文件,差別
              • RegisterFacades::bootstrap: 0.587ms
              • RegisterProviders::bootstrap: 5.657ms Provider register 差別

                • Collection::partition: 0.8ms
                • ProviderRepository::load: 4.250ms

                  • IlluminateAuthAuthServiceProvider
                  • IlluminateCookieCookieServiceProvider
                  • IlluminateDatabaseDatabaseServiceProvider
                  • IlluminateEncryptionEncryptionServiceProvider
                  • IlluminateFilesystemFilesystemServiceProvider
                  • IlluminateFoundationProvidersFoundationServiceProvider
                  • IlluminateNotificationsNotificationServiceProvider
                  • IlluminatePaginationPaginationServiceProvider
                  • IlluminateSessionSessionServiceProvider
                  • IlluminateViewViewServiceProvider
                  • FideloperProxyTrustedProxyServiceProvider
                  • AppProvidersAppServiceProvider
                  • AppProvidersAuthServiceProvider
                  • AppProvidersEventServiceProvider
                  • AppProvidersRouteServiceProvider
              • BootProviders::bootstrap: 8.048ms Provider boot 差別

                • array_walk: 7.793ms
          • Pipeline::then: 14.690ms

            • Router::dispatch: 12.202ms

              • findRoute: 1.754ms
              • runRoute: 10.434ms

                • runRouteWithinStack: 9.084ms Middleware 差別

                  • Pipeline::then: 8.586ms
                • prepareResponse: 2.220ms

                  • prepare: 1.6ms
      • Response::send: 0.591ms
      • Kernel::terminate: 4.068ms

        • Kernel::terminateMiddleware: 4.056ms

          • StartSession::terminate: 0.915ms
相關文章
相關標籤/搜索