Skip to content

Checklist For Speed

scil edited this page Dec 1, 2018 · 33 revisions

Try to boot a third party serivce on worker

  • put Third_Party/ServiceProvider::class => [], in 'providers_on_worker' in config/laravelfly.php
  • find out middlewares in that service provider, and you can put them into 'singleton_route_middlewares' or `'singleton_middlewares' if these middlewares are like WORKER SERVICE.
  • find out singleton services in that service provider, and decide to make the services to be CLONE SERVICE or WORKER SERVICE (former is simpler but requires more care when using the service).

CLONE SERVICE

  • put Third_Party/ServiceProvider::class => [ 'service_name' => 'clone', ],

  • If other CLONE SERVICEs or WORKER SERVVCEs have ref to this service, update the ref in update_on_request in config/laravelfly.php.

  • There is no ref to this service in your controllers, see controller and stale reference.

  • If it has ref to other CLONE SERVICEs, upate ref to CLONE SERVICE

  • Static props should keep consistent. see static props

WORKER SERVICE

A. using coroutine

  • ensure the service can be COROUTINE-FRIENDLY SERVICE, read WORKER SERVICE and WORKER OBJECT. If refactor by extending 3rd party service provider, replace third-party service provider with new service provider.

    • singleton

    • its props will not change in any requests. For associate array type, changed are allowed if there is no harm.

    • if it has ref attibutes, the ref object must be A COROUTINE-FRIENDLY SERVICE.
      Give app['events'], it has an attribubte container, the container must be also A COROUTINE-FRIENDLY SERVICE. Yes, the container is, as LaravelFly has make necessary refactor.
      But for third-party services, you should check out if it uses something not COROUTINE-FRIENDLY added by you.

    • [ ] Note: if LARAVELFLY_SERVICES['request'] != true , if can not have ref to app('request') or app('url')`.

  • put Third_Party/ServiceProvider::class => [ 'service_name' => true, ],

  • Static props should keep consistent. see static props

B. no coroutine

  • ensure the service can be WORKER SERVICE, read WORKER SERVICE and WORKER OBJECT. If refactor by extending 3rd party service provider, replace third-party service provider with new service provider.

    • singleton
    • its vars should restore if a change made in a request and harm the next request.
    • If it has ref attibutes, the ref should be
      • a WOKER SERVICE. Like app['events'] has an attribubte container, the attribute container must be also A WORKER SERVICE.
        • [ ] if LARAVELFLY_SERVICES['request'] != true , app('request') and app('url') are not WORKER SERVICEs. Update references to them.
      • or a CLONE SERVICE, and you should upate ref to CLONE SERVICE
  • put Third_Party/ServiceProvider::class => [ 'service_name' => true, ],

  • Static props should keep consistent. see static props

update ref to a CLONE SERVICE

  • For CLONE SERVICE, if it has ref to other CLONE SERVICEs, update the ref in update_on_request in config/laravelfly.php. By default, LaravelFly would output CLONE SERVICEs to console.

    • [ ] If LARAVELFLY_SERVICES['request'] != true and the service has an ref to app('request') or app('url'), like (mcamara/laravel-localization it should be updated like this
    'update_on_request' => [
        // not needed anymore, because 'request' and 'url' are always single now
        LARAVELFLY_SERVICES['request'] ? null : [
            'this' => 'laravellocalization',
            'closure' => function () {
                $this->url = app('url');
                app()->rebinding('request', function () {
                    $this->request = app('request');
                });
            }
        ],

    ],