-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: add benchwrapper, support STORAGE_EMULATOR_HOST
- Loading branch information
Showing
8 changed files
with
385 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# storage benchwrapp | ||
|
||
main.py is a gRPC wrapper around the storage library for benchmarking purposes. | ||
|
||
## Running | ||
|
||
``` | ||
cd storage | ||
pip install -e . # install google.cloud.storage locally | ||
cd test_utils | ||
python3 benchwrapper.py --port 8081 | ||
``` | ||
|
||
## Re-generating protos | ||
|
||
``` | ||
pip install grpcio-tools | ||
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. *.proto | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import argparse | ||
import sys | ||
import time | ||
import grpc | ||
import os | ||
from concurrent import futures | ||
import storage_pb2_grpc | ||
import storage_pb2 | ||
from google.cloud import storage | ||
|
||
_ONE_DAY_IN_SECONDS = 60 * 60 * 24 | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
if os.environ.get('STORAGE_EMULATOR_HOST') == None: | ||
sys.exit('This benchmarking server only works when connected to an emulator. Please set STORAGE_EMULATOR_HOST.') | ||
|
||
parser.add_argument('--port', help='The port to run on.') | ||
|
||
args = parser.parse_args() | ||
|
||
if args.port == None: | ||
sys.exit('Usage: python3 main.py --port 8081') | ||
|
||
client = storage.Client() | ||
|
||
class StorageBenchWrapperServicer(storage_pb2_grpc.StorageBenchWrapperServicer): | ||
def Write(self, request, context): | ||
# TODO(deklerk): implement this | ||
return storage_pb2.EmptyResponse() | ||
|
||
def Read(self, request, context): | ||
bucket = client.get_bucket(request.bucketName) | ||
blob = storage.Blob(request.objectName, bucket) | ||
blob.download_as_string() | ||
return storage_pb2.EmptyResponse() | ||
|
||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | ||
storage_pb2_grpc.add_StorageBenchWrapperServicer_to_server(StorageBenchWrapperServicer(), server) | ||
|
||
print('listening on localhost:'+args.port) | ||
server.add_insecure_port('[::]:'+args.port) | ||
server.start() | ||
try: | ||
while True: | ||
time.sleep(_ONE_DAY_IN_SECONDS) | ||
except KeyboardInterrupt: | ||
server.stop(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// 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"; | ||
|
||
package storage_bench; | ||
|
||
message ObjectRead{ | ||
// The bucket string identifier. | ||
string bucketName = 1; | ||
// The object/blob string identifier. | ||
string objectName = 2; | ||
} | ||
|
||
message ObjectWrite{ | ||
// The bucket string identifier. | ||
string bucketName = 1; | ||
// The object/blob string identifiers. | ||
string objectName = 2; | ||
// The string containing the upload file path. | ||
string destination = 3; | ||
} | ||
|
||
message EmptyResponse{ | ||
} | ||
|
||
service StorageBenchWrapper{ | ||
// Performs an upload from a specific object. | ||
rpc Write(ObjectWrite) returns (EmptyResponse) {} | ||
// Read a specific object. | ||
rpc Read(ObjectRead) returns (EmptyResponse){} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.