Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
FTX/Alameda unstake 197,637 $SOL, valued at 17.07M.
https://solscan.io/account/H4yiPhdSsmSMJTznXzmZvdqWuhxDRzzkoQMEWXZ6agFZ#transfers
https://x.com/OnchainLens/status/2031919069579132969
Follow @onchainlens for more onchain updates
FTX/Alameda unstaked 196,611 $SOL, valued at $15.97M.
https://solscan.io/account/H4yiPhdSsmSMJTznXzmZvdqWuhxDRzzkoQMEWXZ6agFZ#transfers
https://x.com/OnchainLens/status/2021521751658881497
Follow @OnchainLens for more Onchain Updates
FTX/Alameda unstaked 195,669 $SOL, valued at $27.98M.
https://solscan.io/account/HoBeML5zvsmNGn5fXXKADEdSKK9G7qSBFxVFwoRQsyMx#transfers
https://x.com/OnchainLens/status/2010864084745584724
Follow @OnchainLens for more Onchain Updates
A whale deposited 51,750 $SOL worth $4.75M into #Binance after being dormant for 7 months, realizing a loss of $4.37M
The whale initially withdrew 50,000 $SOL for $9.12M and sent it for staking.
https://solscan.io/account/HnsXQEWHrHQQa8E3ok1D1EkmK9Muwmt8C14urBhc9iyq#transfers
https://x.com/OnchainLens/status/2036701947693240644
Follow @onchainlens for more onchain updates
A whale withdrew 48,744 $SOL, worth $6.15M, from #OKX and sent it for staking.
In total, the whale has withdrawn and staked 1,231,861 $SOL ($186.09M) since August 22, 2025. Currently, these $SOL are valued at $155.68M, resulting in a loss of $30.4M.
https://solscan.io/account/GcJFx1MZJ8Zn7PwtRprnzrXz4NyApdm16yAkCFQ4JvG#transfers
https://x.com/OnchainLens/status/2002256392284221914
Follow @onchainlens for more onchain updates
A whale withdrew 100,000 $SOL worth $9.93M from #Bybit and sent it for staking after 2 months.
https://solscan.io/account/9bcNtnFMBgRuiXq2jF5XG8CVGzqfBCpm1sMrBPTEuboq#transfers
https://x.com/OnchainLens/status/2018845766056550470
Follow @OnchainLens for more Onchain Updates.
In the past 24 hours, a whale has unstaked 170K $SOL ($14.85M) and deposited it into #Kraken.
The whale still has 457,937 $SOL ($38.9M) staked.
https://solscan.io/account/7VMTVroogF6GhVunnUWF9hX8JiXqPHiZoG3VKAe64Ckt#transfers
https://x.com/OnchainLens/status/2037469340887593046
Follow @onchainlens for more onchain updates
A wallet linked to the Pump.fun team or investor deposited 2.34B $PUMP worth $4M into #Bitget.
https://solscan.io/account/5v7ZZg1D1si417WhUQF9Br2dRQEnd1sTbCfesscUCVKE#transfers
https://x.com/OnchainLens/status/2041552240666915231
Follow @onchainlens for more onchain updates
A wallet linked to the Pump.fun team deposited 1.757B $PUMP worth $3.54M into #Bitget.
The wallet still holds 12.3B $PUMP ($24.77M).
https://solscan.io/account/5v7ZZg1D1si417WhUQF9Br2dRQEnd1sTbCfesscUCVKE#transfers
https://x.com/OnchainLens/status/2029719672535544181
Follow @onchainlens for more onchain updates
After 5 months of dormancy, a whale withdrew 50,000 $SOL ($4.25M) from #Binance and #Bybit, then sent it for staking.
https://solscan.io/account/8iZyywnZu1yBPPNkQLgpPZyBtuzGG9rjNLGggKaGozXD#transfers
https://x.com/OnchainLens/status/2025436744360096170
Follow @onchainlens for more onchain updates
Trump Meme Team Allocation Wallet sent 5.267M $TRUMP, worth $22.44M, into a #BitGo Custody wallet. Are we selling via OTC? https://solscan.io/account/AduisyNJFAxo49tDQmJUN7Ujc2xAmgmfjJqTaPptPUU4#transfers https://x.com/OnchainLens/status/2018495068852871321…
Trump Meme Team Allocation Wallet sent 5.267M $TRUMP, worth $22.44M, into a #BitGo Custody wallet.
Are we selling via OTC?
https://solscan.io/account/AduisyNJFAxo49tDQmJUN7Ujc2xAmgmfjJqTaPptPUU4#transfers
https://x.com/OnchainLens/status/2018495068852871321
Follow @onchainlens for more onchain updates