Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
🔰Airdrop: Ebees
💸Value: 8000 #EBS worth of ($12)
🪐Referral: 2000 $EBS for Each ($3)
⏳Distribution Date: After TGE
💎Ratings: ⭐️⭐️⭐️⭐️⭐️
🔗Airdrop Link: https://t.me/EbeesAirdropRound2Bot
Note: Airdrop will end on 5th September and rewards will be distributed to the winners TRC-20 wallet on after .
TGE September 6th 2022
Disclaimer: Please do your own research (DYOR) before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens. Also we don't recommend you to invest in any new projects, just join airdrop for free
#EBS Television founder Aman Fissehatsion dies
Aman Fissehatsion, founder and Chief Executive Officer of EBS Television, has died after receiving medical treatment for an illness, the station announced today, 11 February 2026.
In a statement issued Wednesday, EBS Television said Aman “played an irreplaceable role in the growth of #Ethiopian media and the success of EBS.” The station described him as “a man of outstanding vision,” adding that while his passing represents a loss to both his family and the institution, “the vision of Aman Fissehatsion will continue.”
The management and staff of EBS Television also expressed what they described as deep sorrow over his death.
Prime Minister #Abiy Ahmed (PhD) extended condolences following the announcement. In a message posted on his official Facebook page, the Prime Minister said Aman was “one of those who played a crucial role in the development of Ethiopia’s private media.”
https://www.facebook.com/share/p/189cm3oGQX/
#java#ai#apache_kafka#aws#azure#cloud#cloud_first#cloud_native#ebs#gcp#kafka#llm#messaging#minio#s3#serverless#spot#streaming
AutoMQ provides a cloud-native alternative to Apache Kafka that runs on S3 storage, cutting costs by up to 90% while enabling instant scaling and eliminating cross-zone traffic fees. It offers high reliability, serverless operation, and full Kafka compatibility, making it easier and cheaper to manage large-scale data streaming without sacrificing performance or features.
https://github.com/AutoMQ/automq