New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions run very slow when importing libraries [lang-Python] #1626

Open
AmirPupkoSoluto opened this Issue Jun 25, 2017 · 9 comments

Comments

Projects
None yet
6 participants
@AmirPupkoSoluto
Copy link

AmirPupkoSoluto commented Jun 25, 2017

imports of libraries such as numpy and pandas cause function to be very slow (20-30 seconds)

Repro steps

import pandas

Related information

python

@AmirPupkoSoluto AmirPupkoSoluto changed the title Functions run very slow when importing libraries Functions run very slow when importing libraries [lang-Python] Jun 25, 2017

@paulbatum paulbatum self-assigned this Jun 26, 2017

@paulbatum paulbatum added this to the Active Questions milestone Jun 26, 2017

@paulbatum

This comment has been minimized.

Copy link
Member

paulbatum commented Jul 6, 2017

Unfortunately this is expected behavior right now. You're hitting a combination of two separate issues:

  1. Functions executes python code today by calling into a new instance of python.exe for each function execution. This is suboptimal from a performance perspective, in particular when you're loading non trivial libraries because the load has to happen per execution. We have a long term plan for fixing this - it basically involves introducing the ability for functions to execute your code using IPC. The high level work is tracked here, but I don't have an ETA for when this might be applied to python.
  2. Assuming you're running on the consumption plan, your function app code/content is stored on Azure Files. The performance of loading many small files from Azure Files is not ideal - this hits JavaScript performance really badly too, which led to the creation of tools such as Azure Functions Pack. Unfortunately I'm not aware of any equivalent for python.

Our support for python will probably stay in "experimental" mode until issue (1) is solved.

@ylbillyli

This comment has been minimized.

Copy link

ylbillyli commented Jul 7, 2017

@paulbatum I hit into this as well. By moving away from ConsumptionPlan to AppServicePlan, I manage to reduce the load time from 30 sec to 10 sec but still not quite acceptable for production use.

  • Are there any trick or work around I can do for now?
  • Anyway to keep python.exe live on an AppServicePlan?
  • If not, will moving away from FunctionApp and use ApiApp help or will I need a VM?

@paulbatum paulbatum modified the milestones: Backlog, Active Questions Jul 7, 2017

@paulbatum paulbatum added the blocked label Jul 7, 2017

@paulbatum

This comment has been minimized.

Copy link
Member

paulbatum commented Jul 7, 2017

@ylbillyli Sorry but I'm not aware of any good workarounds. Also you should not be looking at using the python support in production as its still considered an experimental feature. I would try using App Service (i.e. a web app) for your scenario. There are some docs on using python in App Service here.

@paulbatum paulbatum removed their assignment Jul 7, 2017

@ylbillyli

This comment has been minimized.

Copy link

ylbillyli commented Jul 14, 2017

@paulbatum do u have an update on this? Our python app might need to go live soon. Before migrating everything we have already setup from function app to web app, I just want to check if this issue is anywhere close to be resolved soon?

Alternatively, do you think I can wrap it in c# and store the Process in a static variable, start the process and never stop it and use it like this https://stackoverflow.com/questions/43876965/using-c-sharp-for-input-and-output-to-python ?

@paulbatum

This comment has been minimized.

Copy link
Member

paulbatum commented Jul 14, 2017

@AmirPupko

This comment has been minimized.

Copy link

AmirPupko commented Jul 16, 2017

hi bily,
Due to this issue (I opened it under my old github user) I've moved my code to a azure app service with docker.
I've open-sourced a sample api for python with flask, docker and sklrean, it might help...
https://github.com/Soluto/python-flask-sklearn-docker-template

@JensMadsen

This comment has been minimized.

Copy link

JensMadsen commented Nov 17, 2017

or move to AWS lambdas :-) I just like azure because it is simpler. deployment and security on AWS is hell

@jwilber

This comment has been minimized.

Copy link

jwilber commented Aug 29, 2018

Any updates?

@paulbatum

This comment has been minimized.

Copy link
Member

paulbatum commented Aug 30, 2018

There is some work in progress on an implementation of python support for functions V2 that does not have the severe performance problems of the experimental support in V1, and you can track the progress of that here:
https://github.com/Azure/azure-functions-python-worker/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment