https://github.com/anilsenay/go-http-vs-grpc
Benchmark for HTTP and gRPC implementations in Golang
https://github.com/anilsenay/go-http-vs-grpc
go golang grpc http
Last synced: about 1 year ago
JSON representation
Benchmark for HTTP and gRPC implementations in Golang
- Host: GitHub
- URL: https://github.com/anilsenay/go-http-vs-grpc
- Owner: anilsenay
- License: gpl-3.0
- Created: 2023-02-01T00:49:52.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-01T01:29:07.000Z (about 3 years ago)
- Last Synced: 2024-10-12T07:39:36.847Z (over 1 year ago)
- Topics: go, golang, grpc, http
- Language: Go
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Notes:
- I tested sending the same struct in both gRPC and HTTP and made simple benchmarks recording their response times.
- There are some benchmark tests in `request_benchmark_test.go` file. You can run them with `go test -bench=. -benchtime=1000x -benchmem`. There are 2 tests as `BenchmarkServer` and `BenchmarkServer_NewClientEachRequest`. I tested that what if it creates new gRPC connection for each request or use a single one for all requests. According to the results of those benchmarks, creating new connection for each request is not efficient for gRPC while it loses advantages of itself.
- Results may change by runs but gRPC was always better in my results.
- This test may not accurately reflect reality, or they may have wrong implementations etc. If you think there are some issues you can open an issue or contribute directly.
## Run benchmarks
#### Generate plots:
> Draws plots for grpc and http benchmarks
usage: `go run cmd/benchmark/plots/plots.go `
```bash
go run cmd/benchmark/plots/plots.go 1000 20
```
Last run results:

#### gRPC benchmark:
> Prints time values in array
usage: `go run cmd/benchmark/grpc/main.go `
```bash
go run cmd/benchmark/grpc/main.go 1000 20
```
#### HTTP benchmark:
> Prints time values in array
usage: `go run cmd/benchmark/http/main.go `
```bash
go run cmd/benchmark/http/main.go 1000 20
```
## Run server/client
#### gRPC server:
```bash
go run cmd/grpc/server/server.go
```
#### gRPC client:
```bash
go run cmd/grpc/client/client.go
```
#### HTTP server:
```bash
go run cmd/http/server/server.go
```
#### HTTP client:
```bash
go run cmd/http/client/client.go
```