FastAPI
الذهاب إلى القناة على Telegram
Sharing specialized content about the FastAPI framework, Python, and FastAPI deployment in the cloud. مطالب تخصصی فریم ورک FastAPI . پایتون محتوای فارسی و انگلیسی Discussion: https://t.me/fastapi_persian #fastapi #python #cloud
إظهار المزيد670
المشتركون
لا توجد بيانات24 ساعات
-37 أيام
+330 أيام
أرشيف المشاركات
670
چند روز پیش یه ریپازیتوری ساختم که توش نحوه دیپلوی یک اپلیکشن fastapi با گانی کورن روی داکر را پیاده سازی کردم . دیدم چند نفری لایک کردند خیلی خوشحال شدم . اومدم یه ویدیو درست کردم که بیشتر توضیح بدم . البته ویدیو خالی از اشکال نیست . البته کیفیت صدا خوبه ولی بعضی جاها gain مایکروفون کم شده و دیروز اینجا خیلی گرم بود و الیته تعطیل هم بودیم.. بعضی جاهاش بی حال حرف زدم و حتی خوابم هم میامد وسط ضبط حالا برای اولین کار ارایه میدهم .. اگر اشکال فنی هم داشت زیرش کامنت بذارید که من از شما یاد بگیرم بزرگواران.
https://www.youtube.com/watch?v=-rQnVtdzxeY
670
یکسری best practice برای تعیین مقدار pool size برای ارتباط با دیتا بیس
⸻
✅ Best Practices for PostgreSQL Connection Pool in FastAPI
1. Start Small and Scale with Load
• Begin with:
pool_size = 2 × number of CPU cores
• This is a good baseline and avoids overloading the DB.
⸻
2. Respect Your Database’s max_connections
• Never allow total pool sizes (across all app instances) to exceed your DB’s max_connections.
• Leave 20–30 connections reserved for:
• Migrations
• Admin tools (e.g., pgAdmin)
• Monitoring tools
• psql connections
• Cron jobs or background workers
⸻
3. Set max_overflow Carefully
• max_overflow allows temporary connections beyond the base pool size.
• Keep it small (e.g., 2–5) to handle burst traffic without exhausting the DB.
create_async_engine(DATABASE_URL, pool_size=10, max_overflow=5)
⸻
4. Use Connection Timeouts
• Prevent your app from hanging forever on blocked DB connections:
connect_args={"timeout": 30} # or use asyncpg-specific timeout settings
⸻
5. Use pool_recycle or pool_pre_ping
• Prevents stale or dead connections:
create_async_engine(..., pool_pre_ping=True)
• Or in databases lib:
Database(DATABASE_URL, min_size=5, max_size=10, timeout=30)
⸻
6. Monitor in Production
• Track:
• Active DB connections via pg_stat_activity
• Pool usage metrics (sqlalchemy.pool or custom logs)
• Request latency / timeouts
• Use APM tools like:
• Datadog
• Prometheus + Grafana
• pg_stat_monitor
⸻
7. Use pgbouncer for High-Scale Apps
• If you have many FastAPI instances or autoscaling:
• Use pgbouncer in transaction pooling mode to avoid connection exhaustion.
⸻
8. Test with Load
• Use tools like:
• Locust
• wrk
• Simulate real user traffic
• Watch for:
• Connection errors
• Timeouts
• Latency spikes670
نحوه دیپلوی یک اپلیکشن fastapi با گانی کورن روی داکر را پیاده سازی کردم
اگه فرصت شد یک ویدیو در موردش میسازم.
https://github.com/babakjahan/fastapi-collection/tree/main/production_app
670
خیلی ها سوال پرسیدن که چطوری پروژه را دیپلوی کنیم با gunicorn من یه سمپل درست کردم و توضیحات
دستورات را کامل تو ReadMe نوشتم
کافیه که توی فولدر app برنامه خودتون را قرار بدهید.
سعی میکنم اگر وقت شد یه ویدیو هم درست کنم ازش
https://github.com/babakjahan/fastapi-pojects/tree/main/production_app
670
گروه هکری گنجشک درنده؛ سورس کد صرافی نوبیتکس را منتشر کرد ( کل بک اند به زبان پایتون است) در قسمتهایی از فریم ورک Flask استفاده شده
670
نمونه کد:
updated_at_condition: DateCondition = Query(
default=None, description="condition to find the document based on updated date."
),670
Repost from Mohammad jalali || محمد جلالی
سلام بچه ها از لینک زیر و با (IP امریکا) میتونید ۱۵ ماه از هوش مصنوعی گوگل "جیمنای پرو" به رایگان استفاده کنید 😍✌️
🔸️ استفاده کنید... حدود ۳۰ میلیون بیوفتید جلو و منم دعا کنید 😁💙
🔹️ یادتون نره حتما با IP امریکا باید برید
http://one.google.com/join/ai-student
670
برنامه نویس رایگان به تیم خودتون اضافه کنید 🤔….
جناب جولز از طرف گوگل میتونه تیکت های کاری را به عنوان تسک قبول کنه و انجام بده و در برنچ خودش ثبت کنه و در نهایت پول ریکوست بده.
https://jules.google/docs/jules-in-90-seconds
