You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 11, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+69-2Lines changed: 69 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,15 +20,14 @@ To override, set `--registry-secret` according to [tm docs](https://github.com/t
20
20
21
21
### Concurrency
22
22
23
-
Concurrency in KLR represented by two components: parallel running [bootstrap](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) processes per container and Knative [container concurrency](https://github.com/knative/serving/blob/master/docs/spec/spec.md#revision) model. By default [AWS runtime interface](https://github.com/triggermesh/aws-custom-runtime) fires up 8 bootstrap processes (functions, in other words) and allows multiple concurrent requests (`containerConcurrency: 0`) to be handled by each container. Default concurrency configuration can be changed on function deployment or update using `tm deploy service` command parameters:
23
+
Concurrency in KLR represented by two components: parallel running [bootstrap](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) processes per container and Knative [container concurrency](https://github.com/knative/serving/blob/master/docs/spec/spec.md#revision) model. By default [AWS runtime interface](https://github.com/triggermesh/aws-custom-runtime) fires up 4 bootstrap processes (functions, in other words) and allows multiple concurrent requests (`containerConcurrency: 0`) to be handled by each container. Default concurrency configuration can be changed on function deployment or update using `tm deploy service` command parameters:
24
24
25
25
`--concurrency <N>` - sets Knative service `containerConcurrency` value to `N`
26
26
27
27
`--build-argument INVOKER_COUNT=<N>` - passes number of parallel running functions to AWS lambda runtime
28
28
29
29
Values for these two parameters should be calculated individually for each function and depends on operation characteristics. Knative [autoscaling](https://github.com/knative/docs/blob/master/docs/serving/samples/autoscale-go/README.md) is another important factor that affects service performance, but right now KLR uses default autoscaling configuration.
30
30
31
-
32
31
### Examples
33
32
34
33
NOTE: all examples below work with [Local Registry](https://github.com/triggermesh/knative-local-registry). If you don't have local registry in knative cluster, you can use external registry as discribed in CLI [documentation](https://github.com/triggermesh/tm#docker-registry)
{"message":"Hello, the current time is Tue Apr 07 13:59:17 GMT 2020"}
260
259
```
261
260
261
+
### Run in Docker
262
+
263
+
For cases in which the use of additional components (tm CLI, Tekton, Knative, k8s) is undesirable, it is possible to build a KLR function as a standalone Docker container and run it in any environment. To do this, you should extract the Dockerfile from the runtime you are interested in, put it in the directory with your function, update the handler variable, and build the container. Here are Dockerfile definitions for all runtimes:
1. Create directory and save your function code there:
277
+
278
+
```
279
+
mkdir python
280
+
cd python
281
+
cat > handler.py <<EOF
282
+
import json
283
+
import datetime
284
+
def endpoint(event, context):
285
+
current_time = datetime.datetime.now().time()
286
+
body = {
287
+
"message": "Hello, the current time is " + str(current_time)
288
+
}
289
+
response = {
290
+
"statusCode": 200,
291
+
"body": json.dumps(body)
292
+
}
293
+
return response
294
+
EOF
295
+
```
296
+
297
+
2. Extract the runtime's [Dockerfile](https://github.com/triggermesh/knative-lambda-runtime/blob/9a74ce1ac03d56d233cfc7a46d84f2c5e5f2685a/python-3.7/runtime.yaml#L43-L50), store it in the same directory, and update the `_HANDLER` variable:
298
+
299
+
```
300
+
cat > Dockerfile <<EOF
301
+
FROM gcr.io/triggermesh/knative-lambda-python37
302
+
ENV _HANDLER handler.endpoint
303
+
COPY . .
304
+
RUN if [ -f requirements.txt ]; then pip3.7 install -r requirements.txt ;fi
305
+
ENTRYPOINT ["/opt/aws-custom-runtime"]
306
+
EOF
307
+
```
308
+
309
+
The `_HANDLER` variable in most cases consists of the filename without the file extension, and the function name.
310
+
311
+
3. Build, run, test:
312
+
313
+
```
314
+
docker build -t python-klr-image .
315
+
docker run -d --rm --name python-klr-container python-klr-image
316
+
# following command will work if you use Docker bridge network and you have jq tool
317
+
# otherwise, you should get the container address manually
The response will contain a JSON document with the current time.
322
+
323
+
4. Cleanup:
324
+
325
+
```
326
+
docker stop python-klr-container
327
+
```
328
+
262
329
### Support
263
330
264
331
We would love your feedback on this tool so don't hesitate to let us know what is wrong and how we could improve it, just file an [issue](https://github.com/triggermesh/knative-lambda-runtime/issues/new)
0 commit comments