Raj
Raj

Reputation: 29

Azure Python function timeout

I have an Azure python HTTP trigger function that needs to execute dynamic code. If 100 users executing dynamic code simultaneously, even if one user has bad code (infinite loop), other valid requests were failing. Is there a way in Azure to invoke HTTP function as it's own instance so other API requests were not impacted or programmatically terminate invalid request?

I tried functionTimeout in host.json but this is terminating invalid and other valid requests too that were processing simultaneously.

Thanks

Upvotes: 0

Views: 930

Answers (1)

JayaChatterjee-MSFT
JayaChatterjee-MSFT

Reputation: 959

This behavior could be due to the single threaded architecture of Python. This is an expected behavior.

It is documented in Python Functions Developer reference on how to handle such scenario’s: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#scaling-and-concurrency

Here are the two methods to handle this:

  1. Use Async calls
  2. Add more Language worker processes per host, this can be done by using application setting : FUNCTIONS_WORKER_PROCESS_COUNT up to a maximum value of 10. ( So basically, for the CPU-bound workload you are simulating with any loops, we do recommend setting FUNCTIONS_WORKER_PROCESS_COUNT to a higher number to parallelize the work given to a single instance. [Please note that each new language worker is spawned every 10 seconds until they are warmed up.]

Here is a GitHub issue which talks about this issue in detail : https://github.com/Azure/azure-functions-python-worker/issues/236

Upvotes: 0

Related Questions