Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with running go install #44

Closed
davlucal opened this issue Jun 2, 2021 · 15 comments
Closed

Issues with running go install #44

davlucal opened this issue Jun 2, 2021 · 15 comments
Assignees

Comments

@davlucal
Copy link

davlucal commented Jun 2, 2021

Screen Shot 2021-06-02 at 2 54 21 AM

Also, when running " thrift --out src/hellothrift --gen go:package_prefix=src/hellothrift src/hellothrift/hello.thrift" , i do not get the exact 3 files in the hello directory.

Screen Shot 2021-06-02 at 2 55 05 AM

Any ideas?

@davlucal
Copy link
Author

davlucal commented Jun 2, 2021

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

@davlucal
Copy link
Author

davlucal commented Jun 2, 2021

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)
	}
}

@davlucal
Copy link
Author

davlucal commented Jun 2, 2021

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)
}

@davlucal
Copy link
Author

davlucal commented Jun 2, 2021

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).

@davlucal davlucal closed this as completed Jun 2, 2021
@davlucal davlucal reopened this Jun 2, 2021
@davlucal
Copy link
Author

davlucal commented Jun 3, 2021

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

@cgordon
Copy link
Collaborator

cgordon commented Jun 4, 2021

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

@davlucal
Copy link
Author

davlucal commented Jun 4, 2021

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

@cgordon
Copy link
Collaborator

cgordon commented Jun 5, 2021

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

@cgordon
Copy link
Collaborator

cgordon commented Jun 5, 2021

Is it possible that you meant Go v1.13? Version 0.13.0 is a pre-v1 release that is pretty ancient now.

@davlucal
Copy link
Author

davlucal commented Jun 5, 2021

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

@cgordon
Copy link
Collaborator

cgordon commented Jun 7, 2021

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.

@davlucal
Copy link
Author

davlucal commented Jun 8, 2021

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

@cgordon
Copy link
Collaborator

cgordon commented Jun 9, 2021 via email

@davlucal
Copy link
Author

davlucal commented Jun 9, 2021

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).

@cgordon
Copy link
Collaborator

cgordon commented Jun 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants