How FastAPI Handles Requests Behind the Scenes

  Рет қаралды 11,829

Code Collider

Code Collider

2 ай бұрын

Unleash the power of FastAPI! Discover how Asyncio and blocking I/O impact performance. Learn to handle requests concurrently for a blazing-fast API! In this video, we explore FastAPI's handling of concurrent requests. We'll compare Asyncio vs Blocking methods and see how normal functions differ. Understand when to use each approach for optimal performance. Optimize your FastAPI application and handle more requests efficiently. Subscribe for more FastAPI deep dives!
fastapi handle concurrent requests
fastapi async vs def performance
fastapi asyncio.sleep vs time.sleep
improve fastapi performance
fastapi endpoint order of execution
fastapi async def blocking io
fastapi thread pool vs event loop
fastapi best practices for concurrency
how to use asyncio in fastapi for database calls
fastapi handle multiple requests at once efficiently
choose async def vs def in fastapi endpoints
fastapi concurrency with external api calls
#FastAPI #Asyncio #Python #WebDevelopment

Пікірлер: 28
@vikranttyagiRN
@vikranttyagiRN Күн бұрын
Nice explanation. Concise and to the point.
@moneeshkumar1838
@moneeshkumar1838 Ай бұрын
Great content brother Quick Modification: sync router is Concurrency not Parallelism. In python parallelism is achieved only by multiprocessing
@vladhaidukkk-learning
@vladhaidukkk-learning Ай бұрын
Great video, but I think it’s important to mention that multi-threading in Python is not parallel
@bakasenpaidesu
@bakasenpaidesu 20 күн бұрын
Multi processing*
@vladhaidukkk-learning
@vladhaidukkk-learning 19 күн бұрын
​@@bakasenpaidesu Actually you are wrong; multiprocessing is parallel because Python spawns an entirely new process with an entirely new interpreter.
@user-dr7yi2fj6x
@user-dr7yi2fj6x 2 ай бұрын
OMG! This is so helpful and a great video. Thank you and please post more videos like this!
@sany2k8
@sany2k8 7 күн бұрын
Great explanation, you should create more videos bro...
@AnaskiBaithak
@AnaskiBaithak 2 ай бұрын
Thank you for this, I always wondered the difference between async def and def
@ishaquenizamani9800
@ishaquenizamani9800 22 күн бұрын
Thanks for clearing this concept.
@sticksen
@sticksen 5 күн бұрын
My question would be how FastAPI then manages workload when it´s handed over to the worker thread. Because I can only see one worker thread running, at the same time it handles 40 'workloads' concurrently.
@myselfriz
@myselfriz Ай бұрын
very well explanation.
@ChrisHalden007
@ChrisHalden007 19 күн бұрын
Great video. Thanks
@thanhlongle6276
@thanhlongle6276 2 ай бұрын
Thanks man for the video. I am trying to use fast api for db CRUD, which one do you think i should use for get post put and delete?
@codecollider
@codecollider 2 ай бұрын
It depends on whether your database library supports non-blocking queries. Ideally, for endpoints involving database calls, use async def if your library allows awaiting query execution (like await db.execute()). If you're using SQLAlchemy, it provides both blocking and non-blocking methods for queries. It's generally recommended to use the non-blocking approach for better performance.
@thanhlongle6276
@thanhlongle6276 2 ай бұрын
@@codecollider thank you, everything i write is in normal, non async, and I am using sqlite3 package. I think i will use normal def for all of it, since they are all parallel, and the blocking of read and write on database is performed by SQLite itself
@adrianmisak07
@adrianmisak07 2 ай бұрын
great video
@HarshanGandamalla
@HarshanGandamalla 18 күн бұрын
2nd and 3rd are both concurrent I think..parallelism is achieved only by multiprocessing
@codecollider
@codecollider 18 күн бұрын
For true parallelism, multiprocessing is definitely necessary. FastAPI might utilize a separate thread, but that thread still competes for CPU resources with others. My use of "parallel" referred to how requests can be handled in overlapping time periods via threading, even with the GIL. I wanted to avoid mixing the two approaches: executing in separate thread in thread pool and executing concurrently in the main thread event loop.
@lwangacaleb2729
@lwangacaleb2729 18 күн бұрын
I need some help, I want to create a fast api endpoint that calls a synchronous function that has a lot of blocking I/0 operations. But I want the endpoint function to run asynchronously so it can accept many requests at the same time. How should I do this, is there an alternative approach?
@Praise-rs4mc
@Praise-rs4mc 14 күн бұрын
The only way to achieve that is to use multi-threading which I advice against.... instead, make the function asynchronous and try to find the non-blocking function for what you want to do...
@Praise-rs4mc
@Praise-rs4mc 14 күн бұрын
Better still, use the run_in_threadpool function from fastapi to run the process in a different thread so that you don't block the event...better than implementing multi threading on your own.
@lwangacaleb2729
@lwangacaleb2729 14 күн бұрын
@@Praise-rs4mc thanks alot, I will give it a try.
@arjunc5896
@arjunc5896 10 күн бұрын
def endpoint3() is not running parallely for me as supposed to what u said in the video. Instead it is sunning one at a time. Do u know why?
@codecollider
@codecollider 10 күн бұрын
I believe you are testing APIs in the browser. Sometimes, browsers like Chrome have limitations on making parallel requests to the same URL. In the video, if you look closely, I am using two different browsers to hit the same API in parallel. You can try the same approach.
@arjunc5896
@arjunc5896 9 күн бұрын
@@codecollider Yes you are right. I tried from different browsers and it worked. Strange though. Thanks
@lucaspraciano4640
@lucaspraciano4640 Ай бұрын
@robertavetisyan8282
@robertavetisyan8282 21 күн бұрын
boooozi txeq
@udaym4204
@udaym4204 22 күн бұрын
can you make fastapi how run under the hood and how @app.exception_handler work Thanks awesome contentent
FastAPI, Flask or Django - Which Should You Use?
9:49
Tech With Tim
Рет қаралды 44 М.
Next-Level Concurrent Programming In Python With Asyncio
19:19
ArjanCodes
Рет қаралды 164 М.
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 35 МЛН
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 6 МЛН
TRY NOT TO LAUGH 😂
00:56
Feinxy
Рет қаралды 13 МЛН
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 4,2 МЛН
The 3 Laws of Writing Readable Code
5:28
Kantan Coding
Рет қаралды 149 М.
Performance tips by the FastAPI Expert - Marcelo Trylesinski
24:59
EuroPython Conference
Рет қаралды 4,4 М.
Every FastAPI File Upload Method | Working and Best Practices!
6:22
7 Coding Habits of Top 1% Programmers (that I wish I knew earlier)
12:56
Internet Made Coder
Рет қаралды 10 М.
Javascript Promises vs Async Await EXPLAINED (in 5 minutes)
5:50
Roberts Dev Talk
Рет қаралды 546 М.
Requests vs HTTPX vs Aiohttp | Which One to Pick?
15:11
ArjanCodes
Рет қаралды 34 М.
Python Asyncio, Requests, Aiohttp | Make faster API Calls
17:56
Patrick Collins
Рет қаралды 124 М.
`const` was a mistake
31:50
Theo - t3․gg
Рет қаралды 107 М.
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 35 МЛН