Skip to content

Commit

Permalink
Merge pull request #21 from fiware/task/OIOTP-12_throttling
Browse files Browse the repository at this point in the history
OIOTP-12 throttling
  • Loading branch information
dmoranj committed Mar 3, 2016
2 parents 81944fd + 0fec1d8 commit 9c7ecc1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
45 changes: 45 additions & 0 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,48 @@ LOGGING = {
}
}
```


## Throttling

By default throlling is configured for all orchestrator API in [settings/common.py](https://pdihub.hi.inet/fiware/iotp-orchestrator/blob/develop/src/settings/common.py) to 200 request by second.

```
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.AllowAny',),
'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.AnonRateThrottle',
),
'DEFAULT_THROTTLE_RATES': {
'anon': '200/sec',
}
}
```

This value could be modified just adding to [settings/dev.py](https://pdihub.hi.inet/fiware/iotp-orchestrator/blob/develop/src/settings/dev.py)

```
REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['anon']='30/sec'
```


### WSGI server options

For an installation which uses Orchestrator RPM, there is a file in /etc/default/orchestrator-daemon to setup orchestrator port as well as number of process and threads sused by WSGI server.

By default the content of that file is:

```
VIRTUALENV=/var/env-orchestrator
ORCHESTRATOR_DIR=${VIRTUALENV}/lib/python2.6/site-packages/iotp-orchestrator
UWGSI=uwsgi
PORT=8084
STATS_PORT=8085
PROCESSES=1
THREADS=4
ENVIRONMENT="DJANGO_SETTINGS_MODULE=settings.dev"
PIDFILE="/var/run/orchestrator.pid"
PNAME="orchestrator"
USER="orchestrator"
```
3 changes: 3 additions & 0 deletions src/orchestrator/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from rest_framework.response import Response
from rest_framework import status
from rest_framework.exceptions import ParseError
from rest_framework.throttling import AnonRateThrottle

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -100,6 +101,7 @@ class Stats(object):


class IoTConf(Stats):
throttle_classes = (AnonRateThrottle,)

# Class to extract Keystone/Keypass conf from django settings
def __init__(self):
Expand Down Expand Up @@ -153,6 +155,7 @@ class ServiceList_RESTView(APIView, IoTConf):
schema_name = "ServiceList"
parser_classes = (parsers.JSONSchemaParser,)


def __init__(self):
IoTConf.__init__(self)

Expand Down
11 changes: 9 additions & 2 deletions src/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

MANAGERS = ADMINS

CACHE_BACKEND = 'locmem://'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
Expand Down Expand Up @@ -207,9 +209,14 @@
}

REST_FRAMEWORK = {
#'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.AllowAny',),
#'PAGINATE_BY': 10

'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.AnonRateThrottle',
),
'DEFAULT_THROTTLE_RATES': {
'anon': '200/sec',
}
}


Expand Down
2 changes: 2 additions & 0 deletions src/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
DEBUG = True
TEMPLATE_DEBUG = DEBUG

REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['anon']='200/sec'

# Keystone Endpoint
KEYSTONE = {
"host": "localhost",
Expand Down
2 changes: 2 additions & 0 deletions src/settings/qa_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
"port": "7070",
"protocol":"http"
}

REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['anon']='200/sec'
2 changes: 2 additions & 0 deletions src/settings/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@
"protocol":"http"
}


REST_FRAMEWORK['DEFAULT_THROTTLE_RATES']['anon']='200/sec'

0 comments on commit 9c7ecc1

Please sign in to comment.