Тёмный

How FastAPI Handles Requests Behind the Scenes 

Code Collider
Подписаться 888
Просмотров 25 тыс.
50% 1

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 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@moneeshkumar1838
@moneeshkumar1838 5 месяцев назад
Great content brother Quick Modification: sync router is Concurrency not Parallelism. In python parallelism is achieved only by multiprocessing
@vladhaidukkk-learning
@vladhaidukkk-learning 5 месяцев назад
Great video, but I think it’s important to mention that multi-threading in Python is not parallel
@bakasenpaidesu
@bakasenpaidesu 4 месяца назад
Multi processing*
@vladhaidukkk-learning
@vladhaidukkk-learning 4 месяца назад
​@@bakasenpaidesu Actually you are wrong; multiprocessing is parallel because Python spawns an entirely new process with an entirely new interpreter.
@benshapiro9731
@benshapiro9731 3 месяца назад
Multi threading in python is technically also parallel programming whenever a thread releases the GIL, such as during time.sleep or open calls. In those specific instances, there can be two (or more) threads truly executing in parallel in the same python process, because one thread is waiting for the results of a system call, during which time it releases the GIL since reference counts don’t need to be updated, allowing another thread to acquire the GIL and execute a piece of code in parallel.
@benshapiro9731
@benshapiro9731 3 месяца назад
On this topic also: check out the beta of. Python 3.13! There is a flag that can be passed when launching python that removes the GIL, allowing truly parallelized execution with just threads. Been playing around with asyncio and concurrent.futures.ThreadPoolExecutor -> noticeable speed up. Shame that c-extension based libraries like numpy are unusable with this setting
@vladhaidukkk-learning
@vladhaidukkk-learning 3 месяца назад
​@@benshapiro9731 This is called concurrency, not parallelism. Parallelism is when two or more tasks can run simultaneously, using the CPU, without waiting for I/O-bound operations. While the GIL doesn't prevent Python from switching context between threads waiting for I/O-bound operations, this is still considered concurrency, not parallelism.
@sany2k8
@sany2k8 3 месяца назад
Great explanation, you should create more videos bro...
@AnaskiBaithak
@AnaskiBaithak 6 месяцев назад
Thank you for this, I always wondered the difference between async def and def
@sticksen
@sticksen 3 месяца назад
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.
@lwangacaleb2729
@lwangacaleb2729 4 месяца назад
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 3 месяца назад
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 3 месяца назад
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 3 месяца назад
@@Praise-rs4mc thanks alot, I will give it a try.
@PyPeak
@PyPeak 3 месяца назад
Beautifully explained!
@adityahpatel
@adityahpatel 17 дней назад
2 and 3 look the same. hello of each is printed first then bye from each. how is 2 and 3 different? its not explained crystal clearly
@arjunc5896
@arjunc5896 3 месяца назад
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 3 месяца назад
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 3 месяца назад
@@codecollider Yes you are right. I tried from different browsers and it worked. Strange though. Thanks
@startup_cult
@startup_cult Месяц назад
this is such an underrated video
@robertavetisyan8282
@robertavetisyan8282 4 месяца назад
boooozi txeq
@PriyankRupareliya
@PriyankRupareliya 6 дней назад
This is very valuable content. New job, starting to work on FastAPI. The whole python paradigm is new for me. This video helped clear one of the most critical concept for me. Thanks brother.
@hyakuheli
@hyakuheli 5 дней назад
what happens if the server is created with multiple processes (for multiple cores) with uvicorn main:app --workers 4. The first 4 clients are given a new process? or it can be either a process or another thread if a thread is in a non-blocking task? and what happens when there are more than 4 clients at the same time in this case? the new clients are assigned to threads randomly across the 4 processes?
@ArulMuruganAS
@ArulMuruganAS 25 дней назад
its working as explained in unix but for some reason its a different behavior in windows
@정하은-h6s
@정하은-h6s 5 месяцев назад
OMG! This is so helpful and a great video. Thank you and please post more videos like this!
@ishaquenizamani9800
@ishaquenizamani9800 4 месяца назад
Thanks for clearing this concept.
@rainbowrunner1136
@rainbowrunner1136 Месяц назад
Hello, great video. I am super new to python. And started using very recently for backend where its being used along with FastAPI. Can you please tell me what are some concepts/ topics which I should be aware for developing efficient code. For eg from this video, I learnt that which function runs concurrently and which doesn't. I had no idea tbh about this before. If you could spare few minutes and share some stuff which I should know it would be great.
@Shane1994322
@Shane1994322 3 месяца назад
Clearly explained!! Thank you
@vikranttyagiRN
@vikranttyagiRN 3 месяца назад
Nice explanation. Concise and to the point.
@ashwinabrahamjacob525
@ashwinabrahamjacob525 Месяц назад
great video
@ChrisHalden007
@ChrisHalden007 4 месяца назад
Great video. Thanks
@myselfriz
@myselfriz 4 месяца назад
very well explanation.
@lucaspraciano4640
@lucaspraciano4640 5 месяцев назад
@adrianmisak07
@adrianmisak07 6 месяцев назад
great video
@thanhlongle6276
@thanhlongle6276 6 месяцев назад
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 6 месяцев назад
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 6 месяцев назад
@@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
@udaym4204
@udaym4204 4 месяца назад
can you make fastapi how run under the hood and how @app.exception_handler work Thanks awesome contentent
Далее
DataStreaming with LangChain & FastAPI
8:51
Просмотров 17 тыс.
Meni yerga urdingda
00:20
Просмотров 422 тыс.
FastAPI, Flask or Django - Which Should You Use?
9:49
The Essence of Coroutines
8:10
Просмотров 10 тыс.
Being Competent With Coding Is More Fun
11:13
Просмотров 81 тыс.
AsyncIO, await, and async - Concurrency in Python
9:12
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
Meni yerga urdingda
00:20
Просмотров 422 тыс.