TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #425 · 20 апр.

Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках. Выглядело это примерно так: from fastapi.concurrency import run_in_threadpool async def execute(data: DataRequest) -> DataResponse: try: result = await run_in_threadpool(sync_function, data) return DataResponse(data=result) except Exception as e: return DataResponse( error=str(e), success=False, ) В общем работает нормально. Для всех вызовов под капотом используется общий тредпул, всё работает предсказуемо. Но потребовалось изменить количество запускаемых в пуле потоков (по умолчанию создается 40 воркеров). Так как дело происходит с FastAPI, делается это через lifespan используя настройки anyio: import anyio @asynccontextmanager async def lifespan(app: FastAPI): limiter = anyio.to_thread.current_default_thread_limiter() limiter.total_tokens = 100 yield # если вдруг нужно вернуть обратно limiter.total_tokens = 40 Зачем менять количество воркеров? - уменьшить, если оперативки мало (один тред занимает ~8мб) - увеличить чтобы выдержать нагрузку Если есть предложения получше при тех же вводных - предлагайте😉 #async

Hashtags

Резултати

Пронајдени 2 слични објави

Пребарај: #dedipath

当前筛选 #dedipath清除筛选
VPS简测

@vps_test · Post #479 · 31.08.2023 г., 10:31

JJNEWS DediPath将要跑路(没提到洛杉矶区域,暂不清楚是否会全部跑) Dear mjj, We will are writing to you regarding your service at DediPath. With a heavy heart we must announce that DediPath will be discontinuing operations effective 8/31/23. Please migrate your data and take backups as soon as possible. In regards to our colocation customers if you are in the following locations please send a ticket to [email protected] for equipment removal: Dallas Las Vegas Denver Atlanta Jacksonville In regards to our colocation customers if you are in the following location please send a ticket to [email protected] for equipment removal: Seattle In regards to our colocation customers if you are in the following locations please send a ticket to [email protected] for equipment removal: Phoenix In regards to our colocation customers if you are in the following locations please send a ticket to [email protected] for equipment removal: Secaucus Redondo Beach San Jose If you have a domain registered with us please transfer it out ASAP. We are truly sorry for the inconvenience this has caused. We appreciate your business and support over the years and this is heart breaking to everyone at DediPath. Sincerely, DediPath #jjnews#dedipath

VPS简测

@vps_test · Post #131 · 07.06.2023 г., 02:58

DediPath Hybrid Server(高性能不超售服务器)原价11.4刀,官方5折->5.7刀 2C4G250G HDD 意外的是流媒体解锁,G口真不限流量!适合建站,中国移动部分省份用不了(比如江苏) #dedipath#1Gbps#不限流量#流媒体解锁