Skip to content

Commit

Permalink
add grpc profile
Browse files Browse the repository at this point in the history
  • Loading branch information
zizdlp committed Oct 8, 2023
1 parent 8ee9146 commit 41ec507
Show file tree
Hide file tree
Showing 10 changed files with 799 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ build:
bazel build //profile/workflow:async_client
bazel build //profile/socket:server
bazel build //profile/socket:client
bazel build //profile/grpc:async_server
bazel build //profile/grpc:async_client
bazel build //profile/grpc:sync_server
bazel build //profile/grpc:sync_client
benchmark:
python benchmark.py --loop=$(LOOP) --length=$(LENGTH) --port=$(PORT)
.PHONY: workflow_sync_server workflow_sync_client benchmark
5 changes: 4 additions & 1 deletion benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ def benchmark(server, client, length=None, loop=None,port=None):
"./bazel-bin/profile/socket/server",
"./bazel-bin/profile/workflow/sync_server",
"./bazel-bin/profile/workflow/async_server",

"./bazel-bin/profile/grpc/sync_server",
"./bazel-bin/profile/grpc/async_server",
]
client_lists=[
"./bazel-bin/profile/socket/client",
"./bazel-bin/profile/workflow/sync_client",
"./bazel-bin/profile/workflow/async_client",
"./bazel-bin/profile/grpc/sync_client",
"./bazel-bin/profile/grpc/async_client",
]
for i in range(len(server_lists)):
server = server_lists[i]
Expand Down
58 changes: 58 additions & 0 deletions examples/protos/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2020 the gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@com_github_grpc_grpc//bazel:grpc_build_system.bzl", "grpc_proto_library")
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

# The following three rules demonstrate the usage of the cc_grpc_library rule in
# in a mode compatible with the native proto_library and cc_proto_library rules.
proto_library(
name = "helloworld_proto",
srcs = ["helloworld.proto"],
)

cc_proto_library(
name = "helloworld_cc_proto",
deps = [":helloworld_proto"],
)

cc_grpc_library(
name = "helloworld_cc_grpc",
srcs = [":helloworld_proto"],
grpc_only = True,
deps = [":helloworld_cc_proto"],
)

## data_stream proto
proto_library(
name = "data_proto",
srcs = ["data.proto"],
)
cc_proto_library(
name = "data_cc_proto",
deps = [":data_proto"],
)

cc_grpc_library(
name = "data_cc_grpc",
srcs = [":data_proto"],
grpc_only = True,
deps = [":data_cc_proto"],
)
55 changes: 55 additions & 0 deletions examples/protos/data.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2019 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// 语法版本声明,必须放在非注释的第一行
// Syntax version declaration. Must be placed on the first line of non-commentary.

syntax = "proto3";
// The document of proto3: https://developers.google.com/protocol-buffers/docs/proto3

// 包名定义, Python中使用时可以省略不写
// Package name definition, which can be omitted in Python.
package data;

/*
`message`是用来定义传输的数据的格式的, 等号后面的是字段编号
消息定义中的每个字段都有唯一的编号
总体格式类似于Python中定义一个类或者Golang中定义一个结构体
*/
/*
`message` is used to define the structure of the data to be transmitted, after the equal sign
is the field number. Each field in the message definition has a unique number.
The overall format is similar to defining a class in Python or a structure in Golang.
*/
message Request {
bytes data=2;
}

message Response {
bytes data=2;
}

// `service` 是用来给gRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
// `service` is used to define methods for gRPC services in a fixed format, similar to defining
//an interface in Golang
service GRPCDemo {
// 客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
// stream-unary (In a single call, the client can transfer data to the server several times,
// but the server can only return a response once.)
rpc StreamingMethod (stream Request) returns (stream Response);
rpc UnaryMethod (Request) returns (Response);
}



40 changes: 40 additions & 0 deletions examples/protos/helloworld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}

rpc SayHelloStreamReply (HelloRequest) returns (stream HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
123 changes: 123 additions & 0 deletions profile/grpc/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright 2020 the gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"])

cc_binary(
name = "sync_client",
srcs = ["sync_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
],
linkshared = False,
linkstatic = True,

)
cc_binary(
name = "client_multi",
srcs = ["client_multi.cc","thread_pool.hpp"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
],
linkshared = False,
linkstatic = True,

)


cc_binary(
name = "sync_server",
srcs = ["sync_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"@com_github_grpc_grpc//:grpc++_reflection",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/strings:str_format",
],
linkshared = False,
linkstatic = True,
)
cc_binary(
name = "async_server",
srcs = ["async_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"@com_github_grpc_grpc//:grpc++_reflection",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/strings:str_format",
],
linkshared = False,
linkstatic = True,
)

cc_binary(
name = "async_client",
srcs = ["async_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
],
linkshared = False,
linkstatic = True,

)


cc_binary(
name = "grpc_async_client",
srcs = ["greeter_async_client.cc"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
],
linkshared = False,
linkstatic = True,

)

cc_binary(
name = "grpc_async_server",
srcs = ["greeter_async_server.cc"],
defines = ["BAZEL_BUILD"],
deps = [
"@com_github_grpc_grpc//:grpc++",
"@com_github_grpc_grpc//:grpc++_reflection",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/strings:str_format",
],
linkshared = False,
linkstatic = True,
)
Loading

0 comments on commit 41ec507

Please sign in to comment.