Comments (15)
I debugged all the error messages when running both the client and server's main.go. Here are the code changes.
from bender.
For client/main.go:
package main
import (
"fmt"
"hellothrift/hello"
"context"
"github.com/apache/thrift/lib/go/thrift"
)
func RunClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
socket, err := thrift.NewTSocket(addr)
if err != nil {
return err
}
transport, err := transportFactory.GetTransport(socket)
defer transport.Close()
if err := transport.Open(); err != nil {
return err
}
client := hello.NewHelloClientFactory(transport, protocolFactory)
request := hello.NewHelloRequest()
temp := "hello world"
request.Message = &temp
response, err := client.Hello(context.Background(), request)
if err != nil {
return err
}
fmt.Println(*response.Message)
return nil
}
func main() {
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
addr := "localhost:3636"
err := RunClient(transportFactory, protocolFactory, addr)
if err != nil {
panic(err)
}
}
from bender.
For server/main.go
package main
import (
"context"
"hellothrift/hello"
"fmt"
"time"
"github.com/apache/thrift/lib/go/thrift"
)
type HelloHandler struct {
}
func (*HelloHandler) Hello(ctx context.Context, request *hello.HelloRequest) (*hello.HelloResponse, error) {
resp := hello.NewHelloResponse()
resp.Message = request.Message
fmt.Printf("%d - %s\n", time.Now().UnixNano(), request.Message)
return resp, nil
}
func NewHelloHandler() hello.Hello {
return new(HelloHandler)
}
func RunServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
transport, err := thrift.NewTServerSocket(addr)
if err != nil {
return err
}
handler := NewHelloHandler()
processor := hello.NewHelloProcessor(handler)
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
return server.Serve()
}
func main() {
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
addr := "localhost:3636"
RunServer(transportFactory, protocolFactory, addr)
}
from bender.
Output:
There was some issue with one of the functions requiring a pointer to string and not the actual string which is why you see the address being outputted on server side(didn't update this part, only on the client side for the output).
from bender.
For hellobender/main.go
package main
import (
"github.com/pinterest/bender"
bthrift "github.com/pinterest/bender/thrift"
"git.apache.org/thrift.git/lib/go/thrift"
gthrift "github.com/apache/thrift/lib/go/thrift"
"log"
"os"
"github.com/pinterest/bender/hist"
"fmt"
"time"
"context"
"strconv"
"hellothrift/hello"
)
func SyntheticRequests(n int) chan interface{} {
c := make(chan interface{}, 100)
go func() {
for i := 0; i < n; i++ {
request := hello.NewHelloRequest()
temp := "hello " + strconv.Itoa(i)
request.Message = &temp
c <- request
}
close(c)
}()
return c
}
func HelloExecutor(request interface{}, transport thrift.TTransport) (interface{}, error) {
pFac := gthrift.NewTBinaryProtocolFactoryDefault()
client := hello.NewHelloClientFactory(transport, pFac)
return client.Hello(context.Background(), request.(*hello.HelloRequest))
}
func main() {
intervals := bender.ExponentialIntervalGenerator(10.0)
requests := SyntheticRequests(10)
exec := bthrift.NewThriftRequestExec(thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()), HelloExecutor, 10 * time.Second, "localhost:3636")
recorder := make(chan interface{}, 128)
bender.LoadTestThroughput(intervals, requests, exec, recorder)
l := log.New(os.Stdout, "", log.LstdFlags)
h := hist.NewHistogram(60000, 1000000)
bender.Record(recorder, bender.NewLoggingRecorder(l), bender.NewHistogramRecorder(h))
fmt.Println(h)
}
outputs after running twice:
from bender.
@davlucal Hey, thanks for the interest in bender. This library is in dire need of a massive overhaul, but I haven't found the time to do it (particularly because most of the changes would be breaking, and Go is only recently ready for that kind of thing).
If you want to use bender, I highly recommend the more streamlined version available here:
https://github.com/cgordon/bender
Ignore the README for that repo, as it is out of date. The bender.go and intervals.go are significantly streamlined, and perform quite a lot better than the "official" version. For more details, see the comments here:
Thanks.
from bender.
Hi @cgordon, thanks for the reply. Does your bender thrift release work for go v0.13.0?
from bender.
@davlucal I am not sure, and have not tried recently, sorry.
from bender.
Is it possible that you meant Go v1.13? Version 0.13.0 is a pre-v1 release that is pretty ancient now.
from bender.
Sorry my bad, what I had meant to say was Thrift version 0.13.0
from bender.
No worries, that should have been obvious to me :)
I have not run the 0.13 or 0.14 versions of Thrift, so I don't have any experience with them. The code to integrate Thrift with Bender is pretty simple, so it may not take much to do so, if they have changed their APIs.
from bender.
Have one other question, should the values for the interval generator and synthetic requests be the same?
from bender.
from bender.
Sry, I meant as in the parameters.
My understanding is that the ExponentialIntervalGenerator function takes in the desired QPS(for this, it would be testing for a desired 300 QPS) and the total # of requests sent would be 8000(just an arbitrary large # of requests).
from bender.
from bender.
Related Issues (11)
- multiple-value tFac.GetTransport() in single-value context when building against code generated by latest thrift (808d143245f)
- UniformIntervalGenerator implementation is Buggy HOT 2
- Update the bender API to look more like jbender HOT 2
- Revisit the performance notes in the README
- how to use thrift support High concurrency? HOT 2
- Times should be stored as `time.Time` HOT 6
- golint reporting errors HOT 2
- gRPC Support HOT 1
- not enough arguments in thrift/thrift.go HOT 2
- ../client/main.go:23: cannot use "hello,world!" (type string) as type *string in assignment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bender.