valyala / fastrpc Goto Github PK
View Code? Open in Web Editor NEWBuilding blocks for fast rpc systems
License: MIT License
Building blocks for fast rpc systems
License: MIT License
@valyala looking forward to updates. thx!
go 1.22 ubuntu 22.04
go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/lesismal/nbio-examples/tls/fastrpc
cpu: AMD Ryzen 5 7640HS w/ Radeon 760M Graphics
BenchmarkCoarseTimeNow-12 1000000000 0.2144 ns/op 0 B/op 0 allocs/op
BenchmarkTimeNow-12 297431959 4.122 ns/op 0 B/op 0 allocs/op
BenchmarkEndToEndNoDelay1-12 3858876 294.9 ns/op 885.04 MB/s 56 B/op 2 allocs/op
BenchmarkEndToEndNoDelay10-12 4136758 300.4 ns/op 868.96 MB/s 56 B/op 2 allocs/op
BenchmarkEndToEndNoDelay100-12 4177710 296.0 ns/op 881.74 MB/s 57 B/op 2 allocs/op
BenchmarkEndToEndNoDelay1000-12 4457485 348.0 ns/op 749.90 MB/s 63 B/op 2 allocs/op
BenchmarkEndToEndNoDelay10K-12 2385739 440.8 ns/op 592.17 MB/s 101 B/op 2 allocs/op
BenchmarkEndToEndDelay1ms-12 2300378 715.5 ns/op 364.78 MB/s 65 B/op 2 allocs/op
BenchmarkEndToEndDelay2ms-12 2281453 715.1 ns/op 365.00 MB/s 65 B/op 2 allocs/op
BenchmarkEndToEndDelay4ms-12 1464742 839.8 ns/op 310.78 MB/s 70 B/op 2 allocs/op
BenchmarkEndToEndDelay8ms-12 888604 1504 ns/op 173.52 MB/s 80 B/op 2 allocs/op
BenchmarkEndToEndDelay16ms-12 424404 2809 ns/op 92.93 MB/s 103 B/op 2 allocs/op
BenchmarkEndToEndCompressNone-12 2417059 686.3 ns/op 380.27 MB/s 65 B/op 2 allocs/op
BenchmarkEndToEndCompressFlate-12 1247566 909.3 ns/op 287.02 MB/s 90 B/op 2 allocs/op
BenchmarkEndToEndCompressSnappy-12 2516986 726.8 ns/op 359.09 MB/s 66 B/op 2 allocs/op
BenchmarkEndToEndTLSCompressNone-12 2302455 672.2 ns/op 388.27 MB/s 67 B/op 2 allocs/op
BenchmarkEndToEndTLSCompressFlate-12 1337059 922.3 ns/op 283.00 MB/s 89 B/op 2 allocs/op
BenchmarkEndToEndTLSCompressSnappy-12 2511356 740.8 ns/op 352.34 MB/s 67 B/op 2 allocs/op
BenchmarkEndToEndPipeline1-12 4681083 253.5 ns/op 1029.45 MB/s 0 B/op 0 allocs/op
BenchmarkEndToEndPipeline10-12 4730472 269.1 ns/op 970.00 MB/s 0 B/op 0 allocs/op
BenchmarkEndToEndPipeline100-12 4612183 259.8 ns/op 1004.44 MB/s 1 B/op 0 allocs/op
BenchmarkEndToEndPipeline1000-12 4996646 275.7 ns/op 946.55 MB/s 4 B/op 0 allocs/op
BenchmarkSendNowait-12 25008582 40.15 ns/op 0 B/op 0 allocs/op
PASS
Just suggestion to add a more examples of use Fastrpc)
Hi I got an error:
error on connection : cannot write response: cannot write response value: too big size=1134653. Must not exceed 1048576
how increase a limits?
Thank you!
Hi @valyala fastrpc's performace looks impressive, looking at gorpc's performance, it seems fastrpc is 10x faster than gorpc, Am I right?
Hi,
I'm currently working in an high level TCP framework build on top of fastrpc.
This works great when client is called concurrently, but if a client is doing sequential requests the server latency is very high.
30000 42433 ns/op 6.15 MB/s
PASS
you can reproduce the issue with this test
package echo
import (
"time"
"github.com/valyala/fastrpc"
"github.com/valyala/fastrpc/tlv"
"net"
"github.com/valyala/fasthttp"
"fmt"
"testing"
"bytes"
)
func BenchmarkSequentialRPCall(b *testing.B) {
expectedBody := []byte("Hello world foobar baz aaa bbb ccc ddd eee gklj kljsdfsdf" +
"sdfasdaf asdf asdf dsa fasd fdasf afsgfdsg ertytrshdsf fds gf" +
"dfagsf asglsdkflaskdflkqowqiot asdkljlp 0293 4u09u0sd9fulksj lksfj lksdfj sdf" +
"sfjkko9u iodjsf-[9j lksdjf;lkasdj02r fsd fhjas;klfj asd;lfjwjfsd; ")
s := &fastrpc.Server{
NewHandlerCtx: newTestHandlerCtx,
Handler: func(ctxv fastrpc.HandlerCtx) fastrpc.HandlerCtx {
ctx := ctxv.(*tlv.RequestCtx)
ctx.Response.Append(expectedBody)
return ctx
},
Concurrency: 8,
MaxBatchDelay: 0,
CompressType: fastrpc.CompressNone,
TLSConfig: nil,
PipelineRequests: false,
}
serverStop, _ := newTestServerTCP(s, "127.0.0.1:5678")
c := newTestClientTCP()
c.Addr="127.0.0.1:5678"
c.MaxPendingRequests = s.Concurrency
c.MaxBatchDelay = 0
c.CompressType = fastrpc.CompressNone
deadline := time.Now().Add(time.Hour)
b.SetBytes(int64(len(expectedBody)))
var req tlv.Request
var resp tlv.Response
req.SwapValue([]byte("foobar"))
for i := 0; i < b.N; i++ {
if err := c.DoDeadline(&req, &resp, deadline); err != nil {
b.Fatalf("unexpected error: %s", err)
}
if !bytes.Equal(resp.Value(), expectedBody) {
b.Fatalf("unexpected body: %q. Expecting %q", resp.Value(), expectedBody)
}
}
if err := serverStop(); err != nil {
b.Fatalf("cannot shutdown server: %s", err)
}
}
func newTestResponse() fastrpc.ResponseReader {
return &tlv.Response{}
}
func newTestClientTCP() *fastrpc.Client {
return &fastrpc.Client{
NewResponse: newTestResponse,
Dial: func(addr string) (net.Conn, error) {
return fasthttp.Dial(addr)
},
}
}
func newTestServerTCP(s *fastrpc.Server, addr string) (func() error, net.Listener) {
ln, err := net.Listen("tcp", addr)
if err != nil {
panic(err)
}
serverResultCh := make(chan error, 1)
go func() {
serverResultCh <- s.Serve(ln)
}()
return func() error {
ln.Close()
select {
case err := <-serverResultCh:
if err != nil {
return fmt.Errorf("unexpected error: %s", err)
}
case <-time.After(time.Second):
return fmt.Errorf("timeout")
}
return nil
}, ln
}
func newTestHandlerCtx() fastrpc.HandlerCtx {
return &tlv.RequestCtx{
ConcurrencyLimitErrorHandler: nil,
}
}
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.