Skip to content

Commit 2be4f61

Browse files
authored
Merge pull request #90453 from ggailey777/anirudh
[Anirudh] Creating a section for Concurrency
2 parents 2abbd66 + 4e879b7 commit 2be4f61

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

articles/azure-functions/functions-reference-python.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def main(req: func.HttpRequest,
168168
logging.info(f'Python HTTP triggered function processed: {obj.read()}')
169169
```
170170

171-
When the function is invoked, the HTTP request is passed to the function as `req`. An entry will be retrieved from the Azure Blob Storage based on the _ID_ in the route URL and made available as `obj` in the function body. Here the storage account specified is the connection string found in `AzureWebJobsStorage` which is the same storage account used by the function app.
171+
When the function is invoked, the HTTP request is passed to the function as `req`. An entry will be retrieved from the Azure Blob Storage based on the _ID_ in the route URL and made available as `obj` in the function body. Here the storage account specified is the connection string found in , which is the same storage account used by the function app.
172172

173173

174174
## Outputs
@@ -277,29 +277,41 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
277277
In this function, the value of the `name` query parameter is obtained from the `params` parameter of the [HttpRequest] object. The JSON-encoded message body is read using the `get_json` method.
278278

279279
Likewise, you can set the `status_code` and `headers` for the response message in the returned [HttpResponse] object.
280-
281-
## Async
282280

283-
We recommend that you write your Azure Function as an asynchronous coroutine using the `async def` statement.
281+
## Concurrency
284282

285-
```python
286-
# Will be run with asyncio directly
283+
By default, the Functions Python runtime can only process one invocation of a function at a time. This concurrency level might not be sufficient under one or more of the following conditions:
284+
285+
+ You're trying to handle a number of invocations being made at the same time.
286+
+ You're processing a large number of I/O events.
287+
+ Your application is I/O bound.
288+
289+
In these situations, you can improve performance by running asynchronously and by using multiple language worker processes.
287290

291+
### Async
292+
293+
We recommend that you use the `async def` statement to make your function run as an asynchronous coroutine.
294+
295+
```python
296+
# Runs with asyncio directly
288297

289298
async def main():
290299
await some_nonblocking_socket_io_op()
291300
```
292301

293-
If the main() function is synchronous (no qualifier), we automatically run the function in an `asyncio` thread-pool.
302+
When the `main()` function is synchronous (without the `async` qualifier), the function is automatically run in an `asyncio` thread-pool.
294303

295304
```python
296-
# Would be run in an asyncio thread-pool
297-
305+
# Runs in an asyncio thread-pool
298306

299307
def main():
300308
some_blocking_socket_io()
301309
```
302310

311+
### Use multiple language worker processes
312+
313+
By default, every Functions host instance has a single language worker process. However there's support to have multiple language worker processes per host instance. Function invocations can then be evenly distributed among these language worker processes. Use the [FUNCTIONS_WORKER_PROCESS_COUNT](functions-app-settings.md#functions_worker_process_count) application setting to change this value.
314+
303315
## Context
304316

305317
To get the invocation context of a function during execution, include the [`context`](/python/api/azure-functions/azure.functions.context?view=azure-python) argument in its signature.

0 commit comments

Comments
 (0)