I want to integrate a new functionality with a Laravel based ecommerce solution. At this point the main scripts takes around 2.7s to run. The whole site loads in above 6s and we've just started to monitor it. The goal is to get below 2s with script and 4s with everything.
The microservice and the functionality is exposed through a gRPC.
There is a TLS based client-server authentication in place (ecommerce instances and my service can prove who they are). This eats few milliseconds.
When testing Go-client and Go-server, with a pool of 20 connections, it achieved below 35ms per requests. In PHP each request takes above 200ms.
Is it possible to:
- cache the connection to service between requests?
- call RPC methods asynchronously?
Among other solutions I'm considering:
- Setting up a local gRPC proxy which will accept only localhost GET requests made by PHP script and make them a secure gRPC calls.
- Setting up a proxy in front of PHP application to call microservice.
- Calling a service directly from website with JavaScript (puts a burden on a users browser, need to maintain JavaScript).
Any suggestions?
The connection should be re-used if you are using the same Client. On the other hand, there is an option to pre-create a Grpc\Channel object first and then pass it to the your service client as an optional 3rd parameter: https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php#L58. That way you should be able to re-use the same connection across services.
Currently we don't provide an async API for PHP. We did have a tracking issue https://github.com/grpc/grpc/issues/6654 which we may consider in the future