GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Storage: Add benchwrapper, support STORAGE_EMULATOR_HOST. by jeanbza · Pull Request #9219 · googleapis/google-cloud-python

Storage: Add benchwrapper, support STORAGE_EMULATOR_HOST. #9219

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.

Sign up for GitHub

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

Merged
tseaver merged 5 commits into googleapis:master from jeanbza:storage_emulator
Sep 16, 2019

Uh oh!

There was an error while loading. Please reload this page.

Merged

Storage: Add benchwrapper, support STORAGE_EMULATOR_HOST. #9219

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
b427c2b
storage: add benchwrapper, support STORAGE_EMULATOR_HOST
jeanbza Sep 12, 2019
d30b64f
Avoid compounding felony: no new env vars in core.
tseaver Sep 13, 2019
5c4e6ef
DRY emulator host lookup into a helper function.
tseaver Sep 13, 2019
42abcab
Remove unused import.
tseaver Sep 13, 2019
463902a
add STORAGE_EMULATOR_HOST to README.md
jeanbza Sep 14, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

10 changes: 10 additions & 0 deletions 10 storage/google/cloud/storage/_helpers.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@

import base64
from hashlib import md5
import os

STORAGE_EMULATOR_ENV_VAR = "STORAGE_EMULATOR_HOST"
"""Environment variable defining host for Storage emulator."""

_DEFAULT_STORAGE_HOST = u"https://www.googleapis.com"


def _get_storage_host():
return os.environ.get(STORAGE_EMULATOR_ENV_VAR, _DEFAULT_STORAGE_HOST)


def _validate_name(name):
Expand Down
12 changes: 5 additions & 7 deletions 12 storage/google/cloud/storage/blob.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,25 @@
from google.resumable_media.requests import ResumableUpload

from google.cloud import exceptions
from google.cloud._helpers import _bytes_to_unicode
from google.cloud._helpers import _rfc3339_to_datetime
from google.cloud._helpers import _to_bytes
from google.cloud._helpers import _bytes_to_unicode
from google.cloud.exceptions import NotFound
from google.api_core.iam import Policy
from google.cloud.storage._helpers import _get_storage_host
from google.cloud.storage._helpers import _PropertyMixin
from google.cloud.storage._helpers import _scalar_property
from google.cloud.storage._signing import generate_signed_url_v2
from google.cloud.storage._signing import generate_signed_url_v4
from google.cloud.storage.acl import ACL
from google.cloud.storage.acl import ObjectACL

_STORAGE_HOST = _get_storage_host()

Comment thread
jeanbza marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

_API_ACCESS_ENDPOINT = "https://storage.googleapis.com"
_DEFAULT_CONTENT_TYPE = u"application/octet-stream"
_DOWNLOAD_URL_TEMPLATE = (
u"https://www.googleapis.com/download/storage/v1{path}?alt=media"
)
_BASE_UPLOAD_TEMPLATE = (
u"https://www.googleapis.com/upload/storage/v1{bucket_path}/o?uploadType="
)
_DOWNLOAD_URL_TEMPLATE = _STORAGE_HOST + u"/download/storage/v1{path}?alt=media"
_BASE_UPLOAD_TEMPLATE = _STORAGE_HOST + u"/upload/storage/v1{bucket_path}/o?uploadType="
_MULTIPART_URL_TEMPLATE = _BASE_UPLOAD_TEMPLATE + u"multipart"
_RESUMABLE_URL_TEMPLATE = _BASE_UPLOAD_TEMPLATE + u"resumable"
# NOTE: "acl" is also writeable but we defer ACL management to
Expand Down
4 changes: 4 additions & 0 deletions 4 storage/google/cloud/storage/client.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from google.cloud._helpers import _LocalStack
from google.cloud.client import ClientWithProject
from google.cloud.exceptions import NotFound
from google.cloud.storage._helpers import _get_storage_host
from google.cloud.storage._http import Connection
from google.cloud.storage.batch import Batch
from google.cloud.storage.bucket import Bucket
Expand Down Expand Up @@ -94,6 +95,9 @@ def __init__(
)

kw_args = {"client_info": client_info}

kw_args["api_endpoint"] = _get_storage_host()

Comment thread
tseaver marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
Expand Down
21 changes: 21 additions & 0 deletions 21 storage/test_utils/README.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# storage benchwrapp

main.py is a gRPC wrapper around the storage library for benchmarking purposes.

## Running

```
export STORAGE_EMULATOR_HOST=localhost:8080
pip install grpcio
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
```
48 changes: 48 additions & 0 deletions 48 storage/test_utils/benchwrapper.py
Show comments
View file
Open in desktop
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.bucket(request.bucketName)
blob = storage.Blob(request.objectName, bucket)
blob.download_as_string()
Comment thread
jeanbza marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

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)
43 changes: 43 additions & 0 deletions 43 storage/test_utils/storage.proto
Show comments
View file
Open in desktop
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{
}
Comment thread
jeanbza marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


service StorageBenchWrapper{
// Performs an upload from a specific object.
rpc Write(ObjectWrite) returns (EmptyResponse) {}
// Read a specific object.
rpc Read(ObjectRead) returns (EmptyResponse){}
}
195 changes: 195 additions & 0 deletions 195 storage/test_utils/storage_pb2.py
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.