Giter Site home page Giter Site logo

throttleproxy's Introduction

ThrottleProxy

A basic throttling proxy, implemented in Flask. Enforces a configurable daily byte limit per IP address. Also enforces a global daily byte limit for the whole server. Prior to hitting the daily limit, the server begins to degrade performance by inserting sleep requests between each chunk of relayed bytes. This degradation occurs in two steps. Once the daily limit is reached, the proxy returns HTTP status 429.

You need to deploy a REDIS server with Serverless VPC Access.

Using a redis server:

  1. Set up the server. Enable the Memorystore API. Create the instance.
  2. For App Enging Standard, have to set up Serverless VPC Access.
  3. Enable the Serverless VPC Access API
  4. Create a connector, e.g.: redis-connector default us-central1 10.8.180.0/28 200 300

Force Redeploy

throttleproxy's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

throttleproxy's Issues

extra ^M characters in multipart-related series download

When downloading a series using dicomweb wado-rs to get multipart content of type application/dicom, the contents of the download from the proxy is different from accessing the Google dicomweb directly.

In this image the left side is from the proxy and the right side is from google.

image

This is the proxy URL:

https://proxy-dot-idc-dev.appspot.com:443/v1beta1/projects/idc-dev-etl/locations/us-central1/datasets/idc_tcia_mvp_wave0/dicomStores/idc_tcia/dicomWeb/studies/1.3.6.1.4.1.14519.5.2.1.2744.7002.150059977302243314164020079415/series/1.2.276.0.7230010.3.1.3.8323329.18234.1440001306.224430

And this is to access the corresponding series from Google.

export PROJECT_ID=chc-tcia
export REGION=us-central1
export DATASET_ID=qin-headneck
export DICOM_STORE_ID=qin-headneck

export URL=https://healthcare.googleapis.com/v1beta1/projects/$PROJECT_ID/locations/$REGION/datasets/$DATASET_ID/dicomStores/$DICOM_STORE_ID/dicomWeb/studies/1.3.6.1.4.1.14519.5.2.1.2744.7002.150059977302243314164020079415/series/1.2.276.0.7230010.3.1.3.8323329.18234.1440001306.224430
echo $URL

curl -X GET --silent \
     -H "Authorization: Bearer "$(gcloud auth print-access-token) \
     $URL \
     -o /tmp/series.content2

Connection reset by peer from REDIS

Gettng 500 errors from the server. Per the issue at the bottom, Redis in Google cloud might be a bit flaky in App Engine Standard. Wrap the call to catch the exception.
File "/srv/main.py", line 359, in root
curr_use_per_ip_str = redis_client.get(client_ip)
File "/env/lib/python3.7/site-packages/redis/client.py", line 1606, in get
return self.execute_command('GET', name)
File "/env/lib/python3.7/site-packages/redis/client.py", line 901, in execute_command
return self.parse_response(conn, command_name, **options)
File "/env/lib/python3.7/site-packages/redis/client.py", line 915, in parse_response
response = connection.read_response()
File "/env/lib/python3.7/site-packages/redis/connection.py", line 739, in read_response
response = self._parser.read_response()
File "/env/lib/python3.7/site-packages/redis/connection.py", line 324, in read_response
raw = self._buffer.readline()
File "/env/lib/python3.7/site-packages/redis/connection.py", line 256, in readline
self._read_from_socket()
File "/env/lib/python3.7/site-packages/redis/connection.py", line 223, in _read_from_socket
(ex.args,))
redis.exceptions.ConnectionError: Error while reading from socket: (104, 'Connection reset by peer')"

See: redis/redis-py#1186

Check for content-length

Once the proxy was revised to pass through gzip'd content untouched, the OHIF loading counter started to just hold at 0% during a load. Previously, when proxy was uncompressing, the counter progressed from 0 to 100. Investigate content-length header suppression.

500 internal server error accessing large series

Accessing a series using wado-rs series retrieve leads to server error if the series has more than a few items in it.

This URL leads to the crash for instance:

https://proxy-dot-idc-dev.appspot.com/v1beta1/projects/idc-dev-etl/locations/us-central1/datasets/idc_tcia_mvp_wave0/dicomStores/idc_tcia/dicomWeb/studies/1.3.6.1.4.1.14519.5.2.1.2744.7002.150059977302243314164020079415/series/1.3.6.1.4.1.14519.5.2.1.2744.7002.248974378224961074547541151175

It should return a 95MB multipart message of content-type application/dicom. The correct result is provided by accessing the Google dicom store directly.

Probably the proxy is running out of memory or something similar.

endpoint to query current status

OHIF is adding the ability to handle http errors like those generated when an IP hits the threshold by this proxy (OHIF/Viewers#1598).

But we want to be able to give users some advance warning, like a notification that they are close to the limit or maybe an area that turns yellow then red as you get close to the limit.

Can we have an api endpoint to query the current usage compared to the cap?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.