GithubHelp home page GithubHelp logo

benchmark-grpc-protobuf-vs-http-json's Introduction

gRPC+Protobuf or JSON+HTTP?

This repository contains 2 equal APIs: gRPC using Protobuf and JSON over HTTP. The goal is to run benchmarks for 2 approaches and compare them. APIs have 1 endpoint to create user, containing validation of request. Request, validation and response are the same in 2 packages, so we're benchmarking only mechanism itself. Benchmarks also include response parsing.

Requirements

  • Go 1.11

Run tests

Run benchmarks:

GO111MODULE=on go test -bench=. -benchmem

Results

goos: darwin
goarch: amd64
BenchmarkGRPCProtobuf-8            10000            117649 ns/op            7686 B/op        154 allocs/op
BenchmarkHTTPJSON-8                10000            105837 ns/op            8932 B/op        116 allocs/op
PASS
ok      github.com/plutov/benchmark-grpc-protobuf-vs-http-json  4.340s

They are almost the same, HTTP+JSON is a bit faster and has less allocs/op.

CPU usage comparison

This will create an executable benchmark-grpc-protobuf-vs-http-json.test and the profile information will be stored in grpcprotobuf.cpu and httpjson.cpu:

GO111MODULE=on go test -bench=BenchmarkGRPCProtobuf -cpuprofile=grpcprotobuf.cpu
GO111MODULE=on go test -bench=BenchmarkHTTPJSON -cpuprofile=httpjson.cpu

Check CPU usage per approach using:

go tool pprof grpcprotobuf.cpu
go tool pprof httpjson.cpu

My results show that Protobuf consumes less ressources, around 30% less.

gRPC definition

  • Install Go
  • Install Protocol Buffers
  • Install protoc plugin: go get github.com/golang/protobuf/proto github.com/golang/protobuf/protoc-gen-go
protoc --go_out=plugins=grpc:. grpc-protobuf/proto/api.proto

benchmark-grpc-protobuf-vs-http-json's People

Contributors

plutov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

benchmark-grpc-protobuf-vs-http-json's Issues

test result

I use your code to test performance between protobuff and http and someing weird were happend that the http takes less resource in my computer.
Does it happened regularly?

go tool pprof httpjson.cpu
File: benchmark-grpc-protobuf-vs-http-json.test
Type: cpu
Time: Jun 16, 2023 at 3:23pm (CST)
Duration: 1.20s, Total samples = 1.20s (99.83%)

go tool pprof grpcprotobuf.cpu
File: benchmark-grpc-protobuf-vs-http-json.test
Type: cpu
Time: Jun 16, 2023 at 3:21pm (CST)
Duration: 2.30s, Total samples = 3.31s (143.71%)
Entering interactive mode (type "help" for commands, "o" for options)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.