Tsukikage7 opened a new pull request, #856:
URL: https://github.com/apache/dubbo-go-pixiu/pull/856

   ## What this PR does
   
   This PR unifies the IDL definitions and modernizes the API in 
`tools/benchmark` module.
   
   Closes #835
   
   ## Background
   
   The benchmark module previously had three separate IDL definitions:
   - `api/samples_api.proto` - for Triple protocol with `Greeter` service
   - `protocol/grpc/proto/hello_grpc.proto` - for gRPC protocol with 
`UserProvider` service
   - Go structs with Hessian serialization - for Dubbo protocol
   
   This inconsistency made it difficult to compare performance across protocols 
fairly.
   
   ## Changes
   
   ### Unified IDL Definition
   
   Created a single `benchmark.proto` defining `BenchmarkService` with 
consistent message types:
   
   ```protobuf
   service BenchmarkService {
     rpc GetUser(GetUserRequest) returns (GetUsersResponse);
     rpc GetUsers(GetUsersRequest) returns (GetUsersResponse);
     rpc GetUserByName(GetUserByNameRequest) returns (GetUsersResponse);
     rpc SayHello(HelloRequest) returns (HelloResponse);
   }
   ```
   
   ### Protocol-Specific Stubs
   
   - **Triple**: Stubs generated in `api/` using `protoc-gen-go-triple/v3` (new 
programmatic API)
   - **gRPC**: Stubs generated in `api/grpcstub/` using standard 
`protoc-gen-go-grpc`
   - **Dubbo**: Continues to use Hessian serialization with updated provider 
implementation
   
   ### Server Implementations Updated
   
   | Protocol | Changes |
   |----------|---------|
   | gRPC | Uses `grpcstub.BenchmarkServiceServer` with standard 
`google.golang.org/grpc` |
   | Triple | Uses new dubbo-go v3 programmatic API (`server.NewServer()` + 
`RegisterBenchmarkServiceHandler()`) |
   | Dubbo | Cleaned up `UserProvider` with simplified structure |
   
   ### Triple Protocol Modernization
   
   Migrated from config-based API to new dubbo-go v3 programmatic API:
   
   **Server (before)**:
   ```go
   config.SetProviderService(&pkg.BenchmarkProvider{})
   config.Load()
   ```
   
   **Server (after)**:
   ```go
   srv, _ := server.NewServer(
       server.WithServerProtocol(
           protocol.WithPort(20000),
           protocol.WithTriple(),
       ),
   )
   api.RegisterBenchmarkServiceHandler(srv, pkg.NewBenchmarkProvider())
   srv.Serve()
   ```
   
   **Client (before)**:
   ```go
   config.SetConsumerService(grpcBenchmarkService)
   config.Load()
   ```
   
   **Client (after)**:
   ```go
   cli, _ := client.NewClient(client.WithClientURL("tri://127.0.0.1:20000"))
   benchmarkService, _ := api.NewBenchmarkService(cli)
   ```
   
   ### Dependencies
   
   - Upgraded `google.golang.org/grpc` to v1.78.0
   - Updated `dubbo.apache.org/dubbo-go/v3` to v3.3.1
   
   ### Removed Files
   
   - `api/samples_api.proto` and generated files
   - `protocol/grpc/proto/hello_grpc.proto` and generated files
   
   ## Benchmark Results
   
   Test environment: macOS, Apple Silicon, N=500 samples per method
   
   ### gRPC Protocol (Direct)
   
   | Method | Min | Median | Mean | StdDev | Max |
   |--------|-----|--------|------|--------|-----|
   | GetUser | 100µs | 200µs | 400µs | 1.1ms | 8.2ms |
   | GetUsers | 100µs | 200µs | 200µs | 100µs | 400µs |
   | GetUserByName | 100µs | 200µs | 200µs | 100µs | 600µs |
   | SayHello | 100µs | 200µs | 200µs | 100µs | 400µs |
   
   ### gRPC via Pixiu
   
   | Method | Min | Median | Mean | StdDev | Max |
   |--------|-----|--------|------|--------|-----|
   | GetUser | 600µs | 1.4ms | 1.8ms | 1.8ms | 12.7ms |
   | GetUsers | 500µs | 1.4ms | 1.7ms | 1.2ms | 14.6ms |
   | GetUserByName | 500µs | 1.3ms | 2ms | 2ms | 17.1ms |
   | SayHello | 600µs | 1.3ms | 1.8ms | 2ms | 32.8ms |
   
   ### Triple Protocol (Direct)
   
   | Method | Min | Median | Mean | StdDev | Max |
   |--------|-----|--------|------|--------|-----|
   | GetUser | 200µs | 1.8ms | 2.5ms | 2.4ms | 14.5ms |
   | SayHello | 200µs | 900µs | 1.4ms | 1.3ms | 12.5ms |
   
   ### Triple via Pixiu
   
   | Method | Min | Median | Mean | StdDev | Max |
   |--------|-----|--------|------|--------|-----|
   | GetUser | 1ms | 2.1ms | 2.8ms | 3.1ms | 24.4ms |
   | SayHello | 700µs | 2ms | 2.5ms | 1.4ms | 12ms |
   
   ### Dubbo via Pixiu
   
   | Method | Min | Median | Mean | StdDev | Max |
   |--------|-----|--------|------|--------|-----|
   | GetUser | 700µs | 2ms | 3ms | 5.9ms | 44.7ms |
   | GetGender | 300µs | 800µs | 1ms | 500µs | 3.1ms |
   | GetUser0 | 300µs | 700µs | 800µs | 500µs | 4.2ms |
   | GetUsers | 100µs | 500µs | 600µs | 400µs | 3.2ms |
   
   ### Summary
   
   Pixiu proxy adds approximately 0.3-1.1ms overhead compared to direct 
protocol calls. Performance comparison (median latency):
   
   | Protocol | Direct | via Pixiu | Overhead |
   |----------|--------|-----------|----------|
   | gRPC | ~200µs | ~1.3ms | ~1.1ms |
   | Triple | ~1.4ms | ~2ms | ~0.6ms |
   | Dubbo | - | ~700µs | - |
   
   ## How to verify
   
   ```bash
   cd tools/benchmark
   
   # Build all packages
   go build ./...
   
   # Run import formatter
   cd ../.. && make import-format
   
   # Run tests (requires local environment setup)
   go test ./test/...
   ```
   
   ## Checklist
   
   - [x] Code compiles correctly
   - [x] Passes `make import-format`
   - [x] Updated `generate.sh` for code generation
   - [x] All three protocol servers use unified service definition
   - [x] Test files updated to use new API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to