Closed xueli-daisy closed 2 years ago
Hi @xueli-daisy unfortunately we cannot support community users on specific python modules.
However, if you take the time to create a GitHub repo with all the code in, I will take a few minutes of my time to build it and see if I can make a recommendation.
By the way, the file you're trying to use as handler.py called run_benchmark.py is not compatible as a function handler file.
For that reason, a full repository would be better and shouldn't take you very long to do.
Please also look into how to format your code or YAML using code blocks in issues:
Alex
/add label: support, question
/set title: Support request for pyperf and Python3 template
I looked into this with the code example in the pyperf docs: https://pyperf.readthedocs.io/en/latest/run_benchmark.html
version: 1.0
provider:
name: openfaas
gateway: http://127.0.0.1:8080
functions:
pyperf1:
lang: python3
handler: ./pyperf1
image: pyperf1:latest
#!/usr/bin/env python3
import pyperf
import time
def func():
time.sleep(0.001)
def handle(req):
"""handle a request to the function
Args:
req (str): request body
"""
runner = pyperf.Runner()
runner.bench_func('sleep', func)
return req
requirements.txt
pyperf
I found that the same error was created, but only for this particular python module. Others that I tried are working as expected.
It seems to be related to pyperf expecting to be able to hook into __main__
.
Unfortunately I can't take this further with free community support.
My suggestion would be for you to try the Dockerfile approach instead, where you can control how pip runs, which exact version of python3 you require and how to set permissions for the libraries. Here's an example of how to write your own Dockerfile: https://www.openfaas.com/blog/openfaas-flask/
If pyperf works in Docker, then it will work on openfaas with this approach.
Alternatively, look into different benchmarking pip modules.
Alex
Expected Behaviour
The function should be invoked successfully
Current Behaviour
echo "100"|faas-cli invoke deltablue --gateway http://127.0.0.1:31112 Server returned unexpected status code: 500 - exit status 1 Traceback (most recent call last): File "/home/app/index.py", line 6, in
from function import handler
File "/home/app/function/handler.py", line 17, in
import pyperf
ModuleNotFoundError: No module named 'pyperf'
Are you a GitHub Sponsor (Yes/No?)
No
Which Solution Do You Recommend?
Tried with python3-debian template, but I still encounter the same problem
Steps to Reproduce (for bugs)
more deltablue.yml version: 1.0 provider: name: openfaas gateway: http://127.0.0.1:8080 functions: deltablue:
lang: python3
handler.py is https://github.com/python/pyperformance/blob/main/pyperformance/data-files/benchmarks/bm_deltablue/run_benchmark.py
cat requirements.txt pyperf
Context
Your Environment
What Docker version are you using?
docker version
18.09.0What version of Kubernetes are you using?
kubectl version
v1.20.4Operating System and version (e.g. Linux, Windows, MacOS): Description: Ubuntu 18.04.4 LTS Release: 18.04 Codename: bionic
Link to your project or a code example to reproduce issue: sudo faas-cli build -f ./deltablue.yml sudo faas-cli push -f ./deltablue.yml faas-cli deploy -f ./deltablue.yml --gateway http://127.0.0.1:31112