grpc-example

module
v0.0.0-...-e192e2f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2022 License: Apache-2.0

README

Simple GRPC/REST API as a Knative Service.

This repository contains a simple GRPC/REST API, which can be run as a Knative service.

Local

To run the service locally:

go run ./cmd/server

To hit the server locally:

# Create
curl -X POST -d '{"field1":"foo","field2":"bar"}' http://localhost:8080/v1/things

# List
curl http://localhost:8080/v1/things

Knative

To install Knative, my goto is mink (replace mattmoor.dev with your own domain):

mink install --domain mattmoor.dev

Note: mink prints the DNS record you need to configure for the specified domain when it is done.

To deploy this to Knative Serving:

ko apply -Bf config/

Now you should be able to curl things:

curl https://foo.default.mattmoor.dev/v1/things

Or load test things, my goto is vegeta (edit attack.log with your domain):

vegeta -cpus=1 attack -duration=4m -rate=1000/1s -targets=attack.log | vegeta report -type='hist[0,10ms,100ms,1s,10s]'

This should generate a nice little report with latency breakdown (it is most interesting if you let things scale to zero first!):

Bucket           #       %       Histogram
[0s,     10ms]   163     0.07%   
[10ms,   100ms]  233302  97.21%  ########################################################################
[100ms,  1s]     4487    1.87%   #
[1s,     10s]    2048    0.85%   
[10s,    +Inf]   0       0.00%   

Directories

Path Synopsis
cmd
pkg
Package proto contains the GRPC client and server definitions for our sample
Package proto contains the GRPC client and server definitions for our sample

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL