Skip to content

thesyncim/exposed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exposed - minimal high performant reflectionless RPC Server

GoDoc Go Report Card Build Status codecov

Features

the following features are currently available:

  • requests with timeout/cancellation

  • codecs - specify your own codec to marshal/unmarshal messages

  • expose - codegen utility to generate exposed services from interface definitions

Getting Started

Installing

To start using exposed, install Go 1.10 or above and run:

go get github.com/thesyncim/exposed

This will retrieve the library and install it.

Usage

example server:

package main

import (
        "log"
        "net"

        "github.com/thesyncim/exposed"
        "github.com/thesyncim/exposed/encoding/codec/json"
)

func main() {
        ln, err := net.Listen("tcp", "127.0.0.1:8888")
        if err != nil {
                panic(err)
        }

        server := exposed.NewServer(
                exposed.ServerCodec(json.CodecName),
                //exposed.ServerCompression(exposed.CompressSnappy),
        )

        server.HandleFunc("echo",
                func(ctx *exposed.Context, req exposed.Message, resp exposed.Message) (err error) {
                        resp.(*string) = req.(*string)
                        return nil
                },
                &exposed.OperationTypes{
                        ReplyType: func() exposed.Message {
                                return new(string)
                        },
                        ArgsType: func() exposed.Message {
                                return new(string)
                        },
                })

        log.Fatalln(server.Serve(ln))
}

example client:

package main

import (
        "fmt"

        "github.com/thesyncim/exposed"
        "github.com/thesyncim/exposed/encoding/codec/json"
)

func main() {
        client := exposed.NewClient("127.0.0.1:8888",
                exposed.ClientCodec(json.CodecName),
                //exposed.ServerCompression(exposed.CompressSnappy),
        )

        var req = "ping"
        var resp string

        err := client.Call("echo", &req, &resp)
        if err != nil {
                panic(err)
        }

        fmt.Println(resp)
}

Generate service from interface definition

lets looks at the example

package echo

type Echoer interface {
	Echo(msg []byte) (ret []byte)
}

type Echo struct {
}

func (Echo) Echo(msg []byte) []byte {
	return msg
}
go get github.com/thesyncim/expose

download and install expose. A codegen tool to generate an exposed service from your interface definition

expose gen -i  Echoer -p github.com/thesyncim/exposed/examples/echo -s echoservice -o echoservice

this will generate all the boilerplate code to expose your interface as an service

Benchmark

server and client, on the same machine (Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz | 8GB)

Framework payload size (bytes) number clients concurrency op/s MB/s p50(ms) p95(ms) p99(ms) Max(ms) number GC Total memory allocated
grpc 8 1 1 17286.8 0.3 0.0 1.0 1.0 3.5 20 61 MB
exposed 8 1 1 20227.4 0.3 0.0 0.0 1.0 4.2 5 23 MB
grpc 8 1 50 394620.7 6.0 1.0 1.0 1.0 2.4 538 1.4 GB
exposed 8 1 50 527199.3 8.0 1.0 1.0 1.0 1.4 111 472 MB
grpc 8 1 500 481753.7 7.4 0.0 3.0 4.1 12.1 396 1.7 GB
exposed 8 1 500 889530.4 13.6 1.0 1.0 2.0 3.0 169 802 MB
grpc 8 1 5000 314578.3 4.8 13.1 39.8 41.9 113.2 39 1.1 GB
exposed 8 1 5000 686707.7 10.5 8.1 10.5 12.1 37.7 73 627 MB
grpc 8 1 50000 231089.1 3.5 142.6 453.0 939.5 1140.9 10 1.3 GB
exposed 8 1 50000 563226.8 8.6 88.1 130.0 142.6 268.4 15 585 MB
grpc 8 5 1 17292.9 0.3 0.0 1.0 1.0 6.0 29 62 MB
exposed 8 5 1 19808.6 0.3 1.0 1.0 1.0 6.0 4 38 MB
grpc 8 5 50 338058.5 5.2 0.0 1.0 1.0 2.0 549 1.2 GB
exposed 8 5 50 341923.1 5.2 1.0 1.0 1.0 3.0 19 322 MB
grpc 8 5 500 506828.6 7.7 3.0 3.0 4.1 13.1 351 1.8 GB
exposed 8 5 500 583374.8 8.9 1.0 1.0 2.0 7.1 30 537 MB
grpc 8 5 5000 329039.9 5.0 0.0 39.8 44.0 121.6 39 1.2 GB
exposed 8 5 5000 1003451.8 15.3 0.0 10.5 13.1 26.2 43 952 MB
grpc 8 5 50000 246001.1 3.8 159.4 469.8 637.5 1140.9 10 1.3 GB
exposed 8 5 50000 723392.4 11.0 41.9 130.0 176.2 302.0 19 849 MB
grpc 8 10 1 16970.8 0.3 1.0 1.0 1.0 3.0 22 62 MB
exposed 8 10 1 20400.5 0.3 0.0 0.0 1.0 7.6 5 57 MB
grpc 8 10 50 307945.9 4.7 1.0 1.0 1.0 2.0 338 1.1 GB
exposed 8 10 50 242724.8 3.7 1.0 1.0 1.0 3.4 10 253 MB
grpc 8 10 500 508940.5 7.8 1.0 3.0 4.1 8.1 292 1.8 GB
exposed 8 10 500 301884.1 4.6 0.0 2.0 2.0 9.4 11 306 MB
grpc 8 10 5000 332706.9 5.1 39.8 39.8 46.1 167.8 40 1.2 GB
exposed 8 10 5000 544115.1 8.3 15.2 15.2 22.0 44.0 16 533 MB
grpc 8 10 50000 264648.9 4.0 151.0 503.3 738.2 1610.6 10 1.4 GB
exposed 8 10 50000 676505.7 10.3 67.1 167.8 192.9 419.4 13 754 MB
grpc 128 1 1 16728.0 4.1 0.0 1.0 1.0 5.5 56 165 MB
exposed 128 1 1 19921.4 4.9 0.0 0.0 1.0 2.4 17 72 MB
grpc 128 1 50 325784.9 79.5 0.0 1.0 1.0 2.0 1313 3.2 GB
exposed 128 1 50 465914.7 113.7 1.0 1.0 1.0 2.2 363 1.6 GB
grpc 128 1 500 316656.5 77.3 1.0 4.1 4.1 13.1 708 3.1 GB
exposed 128 1 500 744000.4 181.6 0.0 1.0 2.0 5.2 518 2.5 GB
grpc 128 1 5000 224204.5 54.7 15.2 41.9 44.0 113.2 67 2.2 GB
exposed 128 1 5000 570240.3 139.2 8.1 13.1 15.2 26.2 188 2.0 GB
grpc 128 1 50000 177842.9 43.4 167.8 838.9 906.0 1610.6 12 2.2 GB
exposed 128 1 50000 450624.5 110.0 142.6 151.0 218.1 335.5 29 1.7 GB
grpc 128 5 1 16355.2 4.0 0.0 1.0 1.0 4.7 78 162 MB
exposed 128 5 1 19860.8 4.8 1.0 0.7 1.0 3.0 7 87 MB
grpc 128 5 50 284731.1 69.5 1.0 1.0 1.0 4.1 1339 2.8 GB
exposed 128 5 50 330050.5 80.6 1.0 1.0 1.0 5.2 58 1.1 GB
grpc 128 5 500 332104.2 81.1 3.0 4.1 5.2 12.1 623 3.3 GB
exposed 128 5 500 519153.6 126.7 1.0 1.0 3.0 6.0 92 1.8 GB
grpc 128 5 5000 224808.4 54.9 41.9 44.0 50.3 117.4 66 2.3 GB
exposed 128 5 5000 704461.9 172.0 10.5 13.1 17.8 39.8 100 2.5 GB
grpc 128 5 50000 182469.6 44.5 159.4 469.8 805.3 1610.6 12 2.3 GB
exposed 128 5 50000 476001.4 116.2 104.9 142.6 184.5 436.2 34 2.0 GB
grpc 128 10 1 16392.5 4.0 1.0 1.0 1.0 3.0 59 164 MB
exposed 128 10 1 19543.9 4.8 0.0 1.0 1.0 3.7 6 105 MB
grpc 128 10 50 273431.5 66.8 1.0 1.0 1.0 7.1 854 2.7 GB
exposed 128 10 50 238418.7 58.2 1.0 1.0 1.0 7.1 25 841 MB
grpc 128 10 500 337812.0 82.5 1.0 4.1 5.2 9.4 529 3.3 GB
exposed 128 10 500 296522.2 72.4 2.0 2.0 3.0 9.4 30 1.0 GB
grpc 128 10 5000 232633.8 56.8 0.0 50.3 60.8 121.6 66 2.3 GB
exposed 128 10 5000 529278.2 129.2 10.5 17.8 22.0 44.0 45 1.9 GB
grpc 128 10 50000 195578.8 47.7 453.0 486.5 738.2 1476.4 12 2.4 GB
exposed 128 10 50000 490957.4 119.9 56.6 201.3 302.0 469.8 23 1.9 GB
grpc 1024 1 1 15263.2 29.8 0.0 1.0 1.0 7.9 313 904 MB
exposed 1024 1 1 18560.2 36.3 0.0 1.0 1.0 3.0 95 422 MB
grpc 1024 1 50 136637.4 266.9 1.0 1.0 1.0 6.0 3641 8.1 GB
exposed 1024 1 50 263237.3 514.1 1.0 1.0 1.0 2.2 1229 6.0 GB
grpc 1024 1 500 99009.9 193.4 0.0 6.0 10.5 26.2 961 5.9 GB
exposed 1024 1 500 244891.6 478.3 0.0 3.0 4.1 15.2 868 5.7 GB
grpc 1024 1 5000 90479.8 176.7 30.4 83.9 109.1 218.1 95 5.4 GB
exposed 1024 1 5000 179325.5 350.2 28.3 35.7 41.9 65.0 171 4.3 GB
grpc 1024 1 50000 59154.3 115.5 570.4 1208.0 1476.4 2684.4 11 4.2 GB
exposed 1024 1 50000 157647.4 307.9 335.5 402.7 486.5 570.4 23 3.9 GB
grpc 1024 5 1 14876.0 29.1 0.0 1.0 1.0 3.0 434 882 MB
exposed 1024 5 1 18126.0 35.4 1.0 1.0 1.0 3.1 25 426 MB
grpc 1024 5 50 123724.5 241.6 0.0 1.0 1.0 5.2 3160 7.3 GB
exposed 1024 5 50 213660.0 417.3 1.0 1.0 1.0 8.1 218 4.8 GB
grpc 1024 5 500 100852.3 197.0 5.2 9.4 11.0 26.2 879 6.0 GB
exposed 1024 5 500 198070.6 386.9 4.1 5.2 6.0 8.1 208 4.5 GB
grpc 1024 5 5000 85116.4 166.2 54.5 88.1 109.1 184.5 96 5.1 GB
exposed 1024 5 5000 181842.6 355.2 29.4 35.7 39.8 83.9 107 4.2 GB
grpc 1024 5 50000 68798.1 134.4 604.0 939.5 1208.0 2550.1 15 4.7 GB
exposed 1024 5 50000 167795.8 327.7 0.0 503.3 704.6 939.5 25 4.1 GB
grpc 1024 10 1 15067.5 29.4 0.0 1.0 1.0 4.7 318 895 MB
exposed 1024 10 1 17599.2 34.4 1.0 1.0 1.0 5.5 15 434 MB
grpc 1024 10 50 120910.2 236.2 1.0 1.0 1.0 3.0 2115 7.2 GB
exposed 1024 10 50 167830.7 327.8 1.0 1.0 1.0 5.0 93 3.8 GB
grpc 1024 10 500 98692.1 192.8 5.2 11.0 13.1 29.4 765 5.9 GB
exposed 1024 10 500 166947.8 326.1 3.0 4.5 7.1 12.1 96 3.8 GB
grpc 1024 10 5000 82778.4 161.7 54.5 92.3 109.1 176.2 94 5.0 GB
exposed 1024 10 5000 174706.7 341.2 26.2 35.7 39.8 67.1 72 4.0 GB
grpc 1024 10 50000 76091.0 148.6 771.8 1040.2 1208.0 3087.0 14 5.2 GB
exposed 1024 10 50000 158741.0 310.0 0.0 520.1 1140.9 1610.6 23 4.0 GB
grpc 32768 1 1 4396.2 274.8 0.0 1.0 1.0 2.0 2698 7.2 GB
exposed 32768 1 1 5680.3 355.0 0.0 1.0 1.0 5.2 816 4.4 GB
grpc 32768 1 50 6931.8 433.2 0.0 10.5 12.1 23.1 1598 12 GB
exposed 32768 1 50 8609.0 538.1 6.0 6.0 7.1 11.0 571 6.5 GB
grpc 32768 1 500 7271.0 454.4 0.0 100.7 121.6 176.2 187 12 GB
exposed 32768 1 500 8437.8 527.4 0.0 65.0 75.5 83.9 107 6.3 GB
grpc 32768 1 5000 6849.0 428.1 704.6 1073.7 1275.1 1610.6 26 12 GB
exposed 32768 1 5000 6211.0 388.2 0.0 872.4 872.4 1476.4 15 5.3 GB
grpc 32768 1 50000 0.2 0.0 0.0 738.2 738.2 738.2 4 4.6 GB
exposed 32768 1 50000 2972.6 185.8 5100.3 5100.3 5368.7 5637.1 6 6.6 GB
grpc 32768 5 1 4236.5 264.8 0.0 1.0 1.0 6.0 3113 7.0 GB
exposed 32768 5 1 6080.8 380.0 1.0 1.0 1.0 2.4 219 4.6 GB
grpc 32768 5 50 6537.7 408.6 7.1 11.0 13.1 22.0 1343 11 GB
exposed 32768 5 50 8167.0 510.4 0.0 8.1 9.4 19.9 219 6.1 GB
grpc 32768 5 500 6061.2 378.8 79.7 113.2 134.2 209.7 158 10 GB
exposed 32768 5 500 8199.3 512.5 0.0 67.1 134.2 260.0 82 6.2 GB
grpc 32768 5 5000 5704.5 356.5 0.0 1208.0 1342.2 2013.3 25 10 GB
exposed 32768 5 5000 5895.0 368.4 0.0 1275.1 1543.5 1744.8 17 5.3 GB
grpc 32768 5 50000 378.5 23.7 5637.1 5368.7 5637.1 5637.1 10 7.4 GB
exposed 32768 5 50000 3257.9 203.6 5637.1 5100.3 5368.7 5905.6 8 7.8 GB
grpc 32768 10 1 4437.7 277.4 0.0 1.0 1.0 2.0 2175 7.3 GB
exposed 32768 10 1 5787.5 361.7 1.0 1.0 1.0 7.9 112 4.3 GB
grpc 32768 10 50 5666.5 354.2 8.1 12.1 14.2 22.0 1060 9.3 GB
exposed 32768 10 50 7740.4 483.8 0.0 9.4 10.5 26.2 122 5.8 GB
grpc 32768 10 500 5513.4 344.6 88.1 125.8 151.0 209.7 143 9.2 GB
exposed 32768 10 500 8116.8 507.3 0.0 67.1 104.9 201.3 66 6.1 GB
grpc 32768 10 5000 4800.2 300.0 1040.2 1409.3 1610.6 2415.9 24 8.8 GB
exposed 32768 10 5000 7329.3 458.1 0.0 2415.9 3087.0 3623.9 18 6.3 GB
grpc 32768 10 50000 412.9 25.8 5100.3 4563.4 5368.7 5905.6 9 7.4 GB
exposed 32768 10 50000 2257.1 141.1 5368.7 5637.1 5637.1 5905.6 12 7.7 GB
grpc 65536 1 1 2363.6 295.4 0.0 1.0 1.0 3.9 2872 7.0 GB
exposed 65536 1 1 3119.4 389.9 1.0 1.0 1.0 6.0 817 4.6 GB
grpc 65536 1 50 3862.4 482.8 14.2 17.8 19.9 37.7 932 12 GB
exposed 65536 1 50 4223.0 527.9 0.0 16.3 19.9 41.9 367 6.1 GB
grpc 65536 1 500 3868.5 483.6 121.6 176.2 201.3 285.2 104 12 GB
exposed 65536 1 500 4714.7 589.3 109.1 134.2 151.0 243.3 67 6.7 GB
grpc 65536 1 5000 3125.4 390.7 1879.0 1946.2 2080.4 2684.4 17 11 GB
exposed 65536 1 5000 4689.5 586.2 0.0 1208.0 1275.1 2147.5 18 7.6 GB
grpc 65536 1 50000 0.0 0.0 0.0 0.0 0.0 0.0 6 7.2 GB
exposed 65536 1 50000 380.6 47.6 7247.8 6442.5 6710.9 7247.8 5 7.7 GB
grpc 65536 5 1 2328.8 291.1 0.0 1.0 1.0 4.1 2961 6.9 GB
exposed 65536 5 1 3322.5 415.3 0.0 1.0 1.0 9.4 224 4.7 GB
grpc 65536 5 50 2694.1 336.8 0.0 30.4 41.9 79.7 631 8.0 GB
exposed 65536 5 50 3442.3 430.3 0.0 22.0 25.2 32.5 150 4.9 GB
grpc 65536 5 500 2987.8 373.5 0.0 226.5 260.0 369.1 82 9.1 GB
exposed 65536 5 500 3614.4 451.8 0.0 159.4 192.9 302.0 46 5.2 GB
grpc 65536 5 5000 3030.6 378.8 0.0 2080.4 2415.9 3087.0 15 10 GB
exposed 65536 5 5000 3236.6 404.6 0.0 1811.9 1879.0 1946.2 14 5.8 GB
grpc 65536 5 50000 0.0 0.0 0.0 0.0 0.0 0.0 8 6.8 GB
exposed 65536 5 50000 551.0 68.9 6442.5 5637.1 6174.0 6442.5 9 7.8 GB
grpc 65536 10 1 2404.1 300.5 0.0 1.0 1.0 3.0 2082 7.1 GB
exposed 65536 10 1 3335.1 416.9 1.0 1.0 1.0 7.3 120 4.7 GB
grpc 65536 10 50 2963.6 370.5 16.3 22.0 25.2 32.5 643 8.8 GB
exposed 65536 10 50 3936.4 492.1 17.8 16.3 18.9 44.0 106 5.6 GB
grpc 65536 10 500 2911.2 363.9 0.0 226.5 260.0 385.9 82 8.9 GB
exposed 65536 10 500 3324.3 415.5 0.0 176.2 192.9 268.4 38 4.8 GB
grpc 65536 10 5000 2534.9 316.9 1610.6 2281.7 2550.1 2952.8 19 9.1 GB
exposed 65536 10 5000 3192.0 399.0 0.0 1610.6 1610.6 3221.2 14 5.6 GB
grpc 65536 10 50000 0.8 0.1 0.0 5905.6 5905.6 5905.6 6 8.7 GB
exposed 65536 10 50000 173.7 21.7 10200.5 10200.5 10200.5 10200.5 11 8.5 GB

Credits

Releases

No releases published

Packages

No packages published

Languages