英文:
How to call microservice without slowing down the response?
问题
我想要将一个新功能与基于Laravel的电子商务解决方案集成。目前,主要脚本运行时间约为2.7秒。整个网站加载时间超过6秒,我们刚刚开始监控。目标是使脚本运行时间低于2秒,整个网站加载时间低于4秒。
这个微服务和功能通过gRPC暴露。
已经使用基于TLS的客户端-服务器身份验证(电子商务实例和我的服务可以证明它们的身份)。这会消耗几毫秒的时间。
在测试Go客户端和Go服务器时,使用20个连接池,每个请求的时间低于35毫秒。而在PHP中,每个请求需要超过200毫秒的时间。
是否可以:
- 在请求之间缓存与服务的连接?
- 异步调用RPC方法?
在考虑其他解决方案时,我正在考虑:
- 设置一个本地的gRPC代理,只接受由PHP脚本发出的本地主机GET请求,并将其转换为安全的gRPC调用。
- 在PHP应用程序前设置一个代理来调用微服务。
- 直接从网站使用JavaScript调用服务(给用户的浏览器增加负担,需要维护JavaScript)。
有什么建议吗?
英文:
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?
答案1
得分: 1
-
如果您正在使用相同的客户端,应该重用连接。另一方面,您可以选择预先创建一个 Grpc\Channel 对象,然后将其作为可选的第三个参数传递给您的服务客户端:https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php#L58。这样,您应该能够在服务之间重用相同的连接。
-
目前我们还没有为 PHP 提供异步 API。我们曾经有一个跟踪问题 https://github.com/grpc/grpc/issues/6654,我们可能会在将来考虑。
英文:
-
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论