Skip to content

Commit e4b6b42

Browse files
authored
Merge pull request #224 from JosepSampe/pywren-dev
New docker_executor()
2 parents 7c8a8f8 + 13b8682 commit e4b6b42

File tree

25 files changed

+539
-93
lines changed

25 files changed

+539
-93
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
### Added
66
- New local_executor() to run pywren jobs in the local machine
7+
- New localhost compute backend
8+
- New localhost storage backend
9+
- New docker_executor() to run pywren jobs in the local machine by using docker
10+
- New docker compute backend
711

812
### Changed
913
- Docs updated

docs/api-details.md

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# PyWren API Details
22

33
## Executor
4-
The primary object in PyWren is the executor. The standard way to get everything set up is to import pywren_ibm_cloud, and call on of the available methods to get a ready-to-use executor. The available executors are: `ibm_cf_executor()`, `knative_executor()` and `function_executor()`
4+
The primary object in PyWren is the executor. The standard way to get everything set up is to import pywren_ibm_cloud, and call on of the available methods to get a ready-to-use executor. The available executors are: `ibm_cf_executor()`, `knative_executor()`, `function_executor()`, `local_executor()` and `docker_executor()`
55

6-
**ibm_cf_executor(\*\*kwargs)**, **knative_executor(\*\*kwargs)**, **function_executor(\*\*kwargs)**
6+
**ibm_cf_executor(\*\*kwargs)**
77

8-
Initialize and return an executor object. All the parameters set in the executor will overwrite those set in the configuration.
8+
Initialize and return an IBM Cloud Functions executor object. All the parameters set in the executor will overwrite those set in the configuration.
99

1010
|Parameter | Default | Description|
1111
|---|---|---|
1212
|config | None | Settings passed in here will override those in pywren_config|
1313
|runtime | None | Name of the docker image to run the functions |
1414
|runtime_memory | 256 | Memory (in MB) to use to run the functions |
15+
|storage_backend | ibm_cos | Storage backend to store temp data|
1516
|rabbitmq_monitor | False | Activate RabbitMQ monitoring |
1617
|log_level | None | Log level printing (INFO, DEBUG, ...) |
1718

@@ -21,6 +22,82 @@ import pywren_ibm_cloud as pywren
2122
pw = pywren.ibm_cf_executor()
2223
```
2324

25+
**knative_executor(\*\*kwargs)**
26+
27+
Initialize and return a Knative executor object. All the parameters set in the executor will overwrite those set in the configuration.
28+
29+
|Parameter | Default | Description|
30+
|---|---|---|
31+
|config | None | Settings passed in here will override those in pywren_config|
32+
|runtime | None | Name of the docker image to run the functions |
33+
|runtime_memory | 256 | Memory (in MB) to use to run the functions |
34+
|storage_backend | ibm_cos | Storage backend to store temp data|
35+
|rabbitmq_monitor | False | Activate RabbitMQ monitoring |
36+
|log_level | None | Log level printing (INFO, DEBUG, ...) |
37+
38+
Usage:
39+
```python
40+
import pywren_ibm_cloud as pywren
41+
pw = pywren.knative_executor()
42+
```
43+
44+
**function_executor(\*\*kwargs)**
45+
46+
Initialize and return a generic executor object. All the parameters set in the executor will overwrite those set in the configuration.
47+
48+
|Parameter | Default | Description|
49+
|---|---|---|
50+
|config | None | Settings passed in here will override those in pywren_config|
51+
|runtime | None | Name of the docker image to run the functions |
52+
|runtime_memory | 256 | Memory (in MB) to use to run the functions |
53+
|backend | ibm_cf | name of the compute backend to run the functions |
54+
|storage_backend | ibm_cos | Storage backend to store temp data|
55+
|rabbitmq_monitor | False | Activate RabbitMQ monitoring |
56+
|log_level | None | Log level printing (INFO, DEBUG, ...) |
57+
58+
Usage:
59+
```python
60+
import pywren_ibm_cloud as pywren
61+
pw = pywren.function_executor()
62+
```
63+
64+
**local_executor(\*\*kwargs)**
65+
66+
Initialize and return a Localhost executor object. This executor runs the functions in local processes. All the parameters set in the executor will overwrite those set in the configuration.
67+
68+
69+
|Parameter | Default | Description|
70+
|---|---|---|
71+
|config | None | Settings passed in here will override those in pywren_config|
72+
|storage_backend | localhost | Storage backend to store temp data |
73+
|rabbitmq_monitor | False | Activate RabbitMQ monitoring |
74+
|log_level | None | Log level printing (INFO, DEBUG, ...) |
75+
76+
Usage:
77+
```python
78+
import pywren_ibm_cloud as pywren
79+
pw = pywren.local_executor()
80+
```
81+
82+
**docker_executor(\*\*kwargs)**
83+
84+
Initialize and return a Docker executor object. This executor runs the functions in local Dockers. All the parameters set in the executor will overwrite those set in the configuration.
85+
86+
87+
|Parameter | Default | Description|
88+
|---|---|---|
89+
|config | None | Settings passed in here will override those in pywren_config|
90+
|runtime | None | Name of the docker image to run the functions |
91+
|storage_backend | localhost | Storage backend to store temp data |
92+
|rabbitmq_monitor | False | Activate RabbitMQ monitoring |
93+
|log_level | None | Log level printing (INFO, DEBUG, ...) |
94+
95+
Usage:
96+
```python
97+
import pywren_ibm_cloud as pywren
98+
pw = pywren.docker_executor()
99+
```
100+
24101
## Executor.call_async()
25102
Spawn only one function activation.
26103

pywren_ibm_cloud/__init__.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
def ibm_cf_executor(config=None, runtime=None, runtime_memory=None,
25-
compute_backend_region=None, storage_backend=None,
25+
region=None, storage_backend=None,
2626
storage_backend_region=None, rabbitmq_monitor=None,
2727
log_level=None):
2828
"""
@@ -32,26 +32,25 @@ def ibm_cf_executor(config=None, runtime=None, runtime_memory=None,
3232
return FunctionExecutor(
3333
config=config, runtime=runtime, runtime_memory=runtime_memory,
3434
compute_backend=compute_backend,
35-
compute_backend_region=compute_backend_region,
35+
compute_backend_region=region,
3636
storage_backend=storage_backend,
3737
storage_backend_region=storage_backend_region,
3838
rabbitmq_monitor=rabbitmq_monitor,
3939
log_level=log_level
4040
)
4141

4242

43-
def knative_executor(config=None, runtime=None, runtime_memory=None,
44-
compute_backend_region=None, storage_backend=None,
45-
storage_backend_region=None, rabbitmq_monitor=None,
46-
log_level=None):
43+
def knative_executor(config=None, runtime=None, runtime_memory=None, region=None,
44+
storage_backend=None, storage_backend_region=None,
45+
rabbitmq_monitor=None, log_level=None):
4746
"""
4847
Function executor for Knative
4948
"""
5049
compute_backend = 'knative'
5150
return FunctionExecutor(
5251
config=config, runtime=runtime, runtime_memory=runtime_memory,
5352
compute_backend=compute_backend,
54-
compute_backend_region=compute_backend_region,
53+
compute_backend_region=region,
5554
storage_backend=storage_backend,
5655
storage_backend_region=storage_backend_region,
5756
rabbitmq_monitor=rabbitmq_monitor,
@@ -60,16 +59,17 @@ def knative_executor(config=None, runtime=None, runtime_memory=None,
6059

6160

6261
def function_executor(config=None, runtime=None, runtime_memory=None,
63-
compute_backend=None, compute_backend_region=None,
62+
backend=None, region=None,
6463
storage_backend=None, storage_backend_region=None,
6564
rabbitmq_monitor=None, log_level=None):
6665
"""
6766
Generic function executor
6867
"""
6968
return FunctionExecutor(
70-
config=config, runtime=runtime, runtime_memory=runtime_memory,
71-
compute_backend=compute_backend,
72-
compute_backend_region=compute_backend_region,
69+
config=config, runtime=runtime,
70+
runtime_memory=runtime_memory,
71+
compute_backend=backend,
72+
compute_backend_region=region,
7373
storage_backend=storage_backend,
7474
storage_backend_region=storage_backend_region,
7575
rabbitmq_monitor=rabbitmq_monitor,
@@ -94,3 +94,24 @@ def local_executor(config=None, storage_backend=None, storage_backend_region=Non
9494
rabbitmq_monitor=rabbitmq_monitor,
9595
log_level=log_level
9696
)
97+
98+
99+
def docker_executor(config=None, runtime=None, storage_backend=None,
100+
storage_backend_region=None, rabbitmq_monitor=None,
101+
log_level=None):
102+
"""
103+
Localhost function executor
104+
"""
105+
compute_backend = 'docker'
106+
107+
if storage_backend is None:
108+
storage_backend = 'localhost'
109+
110+
return FunctionExecutor(
111+
config=config, runtime=runtime,
112+
compute_backend=compute_backend,
113+
storage_backend=storage_backend,
114+
storage_backend_region=storage_backend_region,
115+
rabbitmq_monitor=rabbitmq_monitor,
116+
log_level=log_level
117+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .docker import DockerBackend as ComputeBackend
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import sys
2+
import multiprocessing
3+
from pywren_ibm_cloud.utils import version_str
4+
5+
RUNTIME_DEFAULT_35 = 'pywren-docker-runtime-v3.5:latest'
6+
RUNTIME_DEFAULT_36 = 'pywren-docker-runtime-v3.6:latest'
7+
RUNTIME_DEFAULT_37 = 'pywren-docker-runtime-v3.7:latest'
8+
RUNTIME_TIMEOUT_DEFAULT = 600 # 10 minutes
9+
RUNTIME_MEMORY_DEFAULT = 256 # 256 MB
10+
11+
_DOCKERFILE_DEFAULT = """
12+
RUN apt-get update && apt-get install -y \
13+
git
14+
15+
RUN pip install --upgrade pip setuptools six \
16+
&& pip install --no-cache-dir \
17+
pika==0.13.1 \
18+
ibm-cos-sdk \
19+
redis \
20+
requests \
21+
numpy
22+
23+
# Copy PyWren app to the container image.
24+
ENV APP_HOME /pywren
25+
WORKDIR $APP_HOME
26+
27+
RUN git clone https://github.com/pywren/pywren-ibm-cloud && cd pywren-ibm-cloud && pip install .
28+
29+
# entry_point.py is automatically generated. Do not modify next lines!
30+
COPY entry_point.py .
31+
32+
ENTRYPOINT ["python", "entry_point.py"]
33+
CMD []
34+
"""
35+
36+
DOCKERFILE_DEFAULT_35 = """
37+
FROM python:3.5-slim-buster
38+
""" + _DOCKERFILE_DEFAULT
39+
40+
DOCKERFILE_DEFAULT_36 = """
41+
FROM python:3.6-slim-buster
42+
""" + _DOCKERFILE_DEFAULT
43+
44+
DOCKERFILE_DEFAULT_37 = """
45+
FROM python:3.7-slim-buster
46+
""" + _DOCKERFILE_DEFAULT
47+
48+
49+
def load_config(config_data):
50+
if 'runtime_memory' not in config_data['pywren']:
51+
config_data['pywren']['runtime_memory'] = RUNTIME_MEMORY_DEFAULT
52+
if 'runtime_timeout' not in config_data['pywren']:
53+
config_data['pywren']['runtime_timeout'] = RUNTIME_TIMEOUT_DEFAULT
54+
if 'runtime' not in config_data['pywren']:
55+
this_version_str = version_str(sys.version_info)
56+
if this_version_str == '3.5':
57+
config_data['pywren']['runtime'] = RUNTIME_DEFAULT_35
58+
elif this_version_str == '3.6':
59+
config_data['pywren']['runtime'] = RUNTIME_DEFAULT_36
60+
elif this_version_str == '3.7':
61+
config_data['pywren']['runtime'] = RUNTIME_DEFAULT_37
62+
63+
total_cores = multiprocessing.cpu_count()
64+
if 'docker' not in config_data:
65+
config_data['docker'] = {}
66+
config_data['docker']['workers'] = total_cores
67+
elif 'workers' not in config_data['docker']:
68+
config_data['docker']['workers'] = total_cores

0 commit comments

Comments
 (0)