Forums

CPU usage with one flask server and a Webhook / post request seems a bit high.

Hi Guys,

I've setup this account with just a Hacker / 5USD subscription to prototype some applications. I have setup a simple flask server that listens on mywebaddress/webhook and sends a mail each 3min / 180SEC to my mail address.

Please see my response handler here in flask_app.py:

app = Flask(__name__)

#@app.route('/')
#def hello_world():
#    return 'Hello from Flask!'

@app.route('/webhook', methods=['POST'])
def respond():
    #bme280value = request.json
    #msgText = MIMEText(bme280value, 'html')
    sendmail()
    print(request.json);
    return Response(status=200)

My running processes are: enter link description here (please check the image).

The CPU usage after one day was 2300/2000sec.

Thank you!

I think the culprits are those Jupyter processes -- they are started up when you view an IPython Notebook, and they continue to run even when you're not viewing the notebook. While running, they "sip" CPU time at a rate of a bit more than one second per minute. They do that by starting a subprocess, which consumes a small amount of CPU then exits, so you'll not see the usage appearing next to the processes themselves.

If you're not using a notebook, you can safely kill them -- the ones with names like "kernel", "jupyterhub" and "sudospawner".

Yes, the problem were the Jupyter processes. For faster prototyping, it would help me if I can print the received values, which is much more convenient than changing the webhook API to connect to my laptop. Is there a recommended way of e.g. seeing print(request.json) in the above code example?

If you print to stderr in your web app, it will appear in your error log.