-
Notifications
You must be signed in to change notification settings - Fork 50
Performance issue with big payload. #8
Comments
Can you try to profile how long it takes to pack the message without sending it? Google protofbuf have php fallback which is installed by default, you can speed up serializing by installing native C extension. You can check the serialization speed by calling message like here: https://github.com/spiral/php-grpc/blob/master/src/Invoker.php#L32 |
It turned out exactly same as you have guessed. $then = microtime(true);
$out->serializeToString();
$now = microtime(true);
error_log(sprintf("Elapsed: %f", $now-$then));
This was about the right amount time I lost when compared to json serializer. Thanks for the big help. I am going to try the C library and post the result back. |
C implemention is much more performant than the php implementation. After Switching to C, my handler only consumes 300ish ms. In the end I extended the Invoker class so that I could cache the serialized result based on my need. class CachedInvoker extends Invoker implements InvokerInterface {
/**
* @inheritdoc
*/
public function invoke(
ServiceInterface $service,
Method $method,
ContextInterface $context,
?string $input
): string {
return Cache::remember(cacheKey(), 60, function () use ($service, $method, $context, $input) {
return parent::invoke($service, $method, $context, $input);
});
}
} |
Please do not extend Invoker but rather composite parent into new one (like middleware). It will help you with BC if this implementation will ever change. |
rr-grpc takes around 1.5 seconds to return a response with a big payload ( a couple thousand of rows from database). Using plain old JSON over http it usually takes 200-300 milliseconds.
I am using STDOUT/STDIN stream relay, and anything else is copied from the example in the project. I suspect the latency is caused by the transport from php to golang. Can you share some insights on how to improve performance?
The text was updated successfully, but these errors were encountered: