头图

gRPC PHP and GO data growth performance test and analysis

CrazyCodes
中文

Preface

Hello, everyone. I’m CrazyCodes. I recently investigated how PHP requests go through gRPC and PHP requests through HTTP. According to the increasing amount of data, the average response time will be much different.

Declaration of conformity

The test reports are all tested by the development machine without any configuration changes.

Native configuration

  • 3 GHz six-core Intel Core i5
  • 16 GB 2400 MHz DDR4
  • MacOs

Go start HTTP

http.ListenAndServe

PHP start HTTP

php -S 127.0.0.1:8088

Ab

ab -c 200 -n 200 -k

test data description
As the server, Go is the test data iterated directly through for, without any other redundant operations

// 伪代码
for i := 0; i < 2,20,200,2000,5000; i++ {

}

Other instructions

The GPH[number] below represents gRPC + PHP + HTTP + data volume

GPH 2

returns the same data set size

gRPC Document Length≈87bytes
Http Document Length≈315bytes

Go Grpc -> Go Grpc average response time is 66.215 ms

go-2.png

Php Grpc -> Go Grpc average response time is 190.551 ms

php-2.png

Php Http -> Go Http average response time is 120.692 ms

php-http-2.png

GPH 20

returns the same data set size

gRPC Document Length≈556bytes
Http Document Length≈2198bytes

Go Grpc -> Go Grpc average response time is 71.525 ms

go-20.png

Php Grpc -> Go Grpc average response time is 212.019 ms

php-20.png

Php Http -> Go Http average response time is 138.332 ms

php-http-20.png

GPH 200

returns the same data set size

gRPC Document Length≈5527bytes
Http Document Length≈21199bytes

Go Grpc -> Go Grpc average response time is 93.963 ms

go-200.png

Php Grpc -> Go Grpc average response time is 250.104 ms

php-200.png

Php Http -> Go Http average response time is 175.916 ms

php-http-200.png

GPH 2000

returns the same data set size

gRPC Document Length≈56928bytes
Http Document Length≈213000bytes

Go Grpc -> Go Grpc average response time is 379.699 ms

go-2000.png

Php Grpc -> Go Grpc average response time is 678.643 ms

php-2000.png

Php Http -> Go Http average response time is 593.252 ms

php-http-2000.png

GPH 5000

returns the same data set size

gRPC Document Length≈143928bytes
Http Document Length≈534000bytes

Go Grpc -> Go Grpc average response time is 920.897 ms

go-5000.png

Php Grpc -> Go Grpc average response time is 1406.589 ms

php-5000.png

Php Http -> Go Http average response time is 1285.640 ms

php-http-5000.png

in conclusion

Way22020020005000
PHP->gRPC190.551/ms212.332250.104678.6431406.589
Go->gRPC66.215/ms71.52593.963379.699920.897
PHP->Http120.692/ms138.332175.916593.2521285.640

According to the test results, it is not difficult to see that when building microservices, it is the most undesirable situation for PHP to request via gRPC. In terms of response time, PHP invoking via Http is slightly better than PHP via gRPC in terms of response time. Some, but with the continuous growth of data and concurrency, this gap will continue to grow. Therefore, when deciding to use PHP as the client, it is best to use the traditional HTTP method to call.

Wan Zun

image.png

You must think that PHP has been crushed in doing microservices, but this is actually not a fault of PHP itself. We all know that PHP is an interpreted language, and Go is a compiled language. Go is pre-compiled and can be directly generated. Execute the file, and PHP is dynamically compiled.

So why is it so slow to call through gRPC in PHP? This depends on the package we use officially provided by Google. The package encapsulates the data in the class , and the class is not as small and exquisite as the structure of Go. When the data continues to grow, the class will expand exponentially, and we When I see that PHP is called through HTTP, although the content body is several times that of gRPC calls, the time is reduced. The reason for this is also very simple. is called through HTTP, and the communication must be carried out first, and the HTTP header is encapsulated, the content body Wait, this has caused the request body to be very large, but because it is a direct request for a result, and the class is not passed, the time is shorter than the gRPC call, which is one of the reasons why PHP uses gRPC slowly.

The second is what we call the characteristics of PHP itself, to the user after dynamic compilation. This process also takes time, but Go does not need this time, so this is also a key factor affecting response time.

Thanks

image.png

Thank you for seeing here, I hope I can help you.

The first publication of such analysis-related articles may have many shortcomings and accept various adjustments.

阅读 1.9k

Grace development
记录分享开发、学习中的点点滴滴
avatar
CrazyCodes
后端开发工程师

I am CrazyCodes,生命不息,编码不止。

16.7k 声望
14.6k 粉丝
0 条评论
avatar
CrazyCodes
后端开发工程师

I am CrazyCodes,生命不息,编码不止。

16.7k 声望
14.6k 粉丝
文章目录
宣传栏