Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 165 622.4 as of 18.11.2022.
The aggregate volume of state owned share in 225 JSCs totaled UZS 133 689.2 billion, i.e. 80.7 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 165 616.4 as of 11.11.2022.
The aggregate volume of state owned share in 225 JSCs totaled UZS 133 690.1 billion, i.e. 80.7 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 630 and the aggregate volume of shares issues totaled UZS 165 616.2 as of 04.11.2022.
The aggregate volume of state owned share in 225 JSCs totaled UZS 133 690.3 billion, i.e. 80.7 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 165 616.2 as of 28.10.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 133 687.6 billion, i.e. 80.7 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 164 689.5 as of 21.10.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 133 687.6 billion, i.e. 81.2 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 164 619.5 as of 14.10.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 133 677.9 billion, i.e. 81.2 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 164 609.8 as of 07.10.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 133 677.9 billion, i.e. 81.2 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 164 597.6 as of 30.09.2022.
The aggregate volume of state owned share in 225 JSCs totaled UZS 133 665.7 billion, i.e. 81.2 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 164 397.9 as of 23.09.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 133 348.9 billion, i.e. 81.1 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 163 200.5 as of 16.09.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 132 889.5 billion, i.e. 81.4 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 631 and the aggregate volume of shares issues totaled UZS 163 200.4 as of 09.09.2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 132 895.8 billion, i.e. 81.4 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube
DEPO - #STATISTICS
CHANGES IN STRUCTURE OF SHAREHOLDERS
The number of JSCs totaled 630 and the aggregate volume of shares issues totaled UZS 163 190.4 as of 26 August 2022.
The aggregate volume of state owned share in 226 JSCs totaled UZS 132 895.8 billion, i.e. 81.4 %.
#structure#shareholders#share#infographics#statistics#changes
deponet.uz|Tg|Fb|Inst|Youtube