Code Monkey home page Code Monkey logo

Comments (15)

davlucal avatar davlucal commented on May 20, 2024

I debugged all the error messages when running both the client and server's main.go. Here are the code changes.

from bender.

davlucal avatar davlucal commented on May 20, 2024

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.

davlucal avatar davlucal commented on May 20, 2024

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.

davlucal avatar davlucal commented on May 20, 2024

Output:

Screen Shot 2021-06-02 at 5 50 01 PM

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.

davlucal avatar davlucal commented on May 20, 2024

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:

Screen Shot 2021-06-02 at 8 05 43 PM
Screen Shot 2021-06-02 at 8 06 04 PM

from bender.

cgordon avatar cgordon commented on May 20, 2024

@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:

#24

Thanks.

from bender.

davlucal avatar davlucal commented on May 20, 2024

Hi @cgordon, thanks for the reply. Does your bender thrift release work for go v0.13.0?

from bender.

cgordon avatar cgordon commented on May 20, 2024

@davlucal I am not sure, and have not tried recently, sorry.

from bender.

cgordon avatar cgordon commented on May 20, 2024

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.

davlucal avatar davlucal commented on May 20, 2024

Sorry my bad, what I had meant to say was Thrift version 0.13.0

from bender.

cgordon avatar cgordon commented on May 20, 2024

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.

davlucal avatar davlucal commented on May 20, 2024

Have one other question, should the values for the interval generator and synthetic requests be the same?

from bender.

cgordon avatar cgordon commented on May 20, 2024

from bender.

davlucal avatar davlucal commented on May 20, 2024

Sry, I meant as in the parameters.
Screen Shot 2021-06-09 at 12 43 09 AM

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.

cgordon avatar cgordon commented on May 20, 2024

from bender.

Related Issues (11)

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.