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

can vegeta do the performance test to a RPC methond request #688

Open
pengtech opened this issue Jun 19, 2024 · 1 comment
Open

can vegeta do the performance test to a RPC methond request #688

pengtech opened this issue Jun 19, 2024 · 1 comment

Comments

@pengtech
Copy link

Question

@ljluestc
Copy link

Create a targets.txt file with the RPC request payloads:

POST https://localhost:50051/mypackage.MyService/MyMethod
{"field1": "value1", "field2": "value2"}

POST https://localhost:50051/mypackage.MyService/AnotherMethod
{"field1": "value3", "field2": "value4"}

Run Vegeta with the custom targets file:

vegeta attack -targets=targets.txt -duration=30s -rate=50/1s | vegeta report

  1. Use a Dedicated RPC Load Testing Tool
    If Vegeta is not suitable for your use case, consider using a tool specifically designed for RPC load testing:

gRPC: Use ghz for gRPC load testing.

Thrift: Use thrift-tools.

Custom RPC: Write a custom load testing script in your preferred language.

  1. Example with gRPC and Vegeta
    If you're using gRPC, you can combine Vegeta with a gRPC-to-HTTP proxy. Here's an example using a Go-based proxy:

Step 1: Create a gRPC-to-HTTP Proxy

package main

import (
	"context"
	"log"
	"net/http"
	"google.golang.org/grpc"
	pb "path/to/your/grpc/proto"
)

func handler(w http.ResponseWriter, r *http.Request) {
	conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()

	client := pb.NewMyServiceClient(conn)
	response, err := client.MyMethod(context.Background(), &pb.MyRequest{Field1: "value1", Field2: "value2"})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Write([]byte(response.GetResult()))
}

func main() {
	http.HandleFunc("/rpc", handler)
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Step 2: Use Vegeta to Test the Proxy

echo "POST http://localhost:8080/rpc" | vegeta attack \
  -body='{"field1": "value1", "field2": "value2"}' \
  -header="Content-Type: application/json" \
  -duration=30s \
  -rate=50/1s | vegeta report

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