Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
15 hours ago, Antalpha (@AntalphaGlobal) sent 1,000 $XAUT (~$5.16M) into #Bybit, likely to sell.
https://intel.arkm.com/explorer/entity/antalpha
https://x.com/OnchainLens/status/2026838079651328216
Follow @onchainlens for more onchain updates
A newly created wallet withdrew 500 $XAUT worth $2.57M from #Bybit.
Address: 0xbe9De876a5Cf802F574899A2763aE6a5D5D93CBa
https://x.com/OnchainLens/status/2029186288763715651
Follow @onchainlens for more onchain updates
15 hours ago, Antalpha (@AntalphaGlobal) sent 1,000 $XAUT (~$5.16M) into #Bybit, likely to sell.
https://intel.arkm.com/explorer/entity/antalpha
https://x.com/OnchainLens/status/2026838079651328216
Follow @onchainlens for more onchain updates
13 hours ago, Antalpha (@AntalphaGlobal) sent 1,000 $XAUT (~$5M) into #Bybit, likely to sell.
They still hold 59,033 $XAUT (~$300.69M).
https://intel.arkm.com/explorer/entity/antalpha
https://x.com/OnchainLens/status/2025020760608440597
Follow @onchainlens for more onchain updates
A whale withdrew 593.98 $XAUT worth ($2.78M) from #Bybit in the past 3 days after being dormant for 8 months.
Address - 0x57655B342B7bf1a1134B572e43eB62BBE56BF7CF
Data - @nansen_ai
https://x.com/OnchainLens/status/2018184847295218173
Follow @onchainlens for more onchain updates
The newly created wallet "0x0E4" further withdrew 450 $XAUT worth ($2.51M)from #Bybit.
Now the whale holds 1.25K $XAUT worth $6.98M
Address - 0x0E4F3ed5B2A3dB2A2940c638418530e9f5c4927E
Data - @nansen_ai
https://x.com/OnchainLens/status/2016757455565574543
Follow @onchainlens for more onchain updates
The whale "0x0a5" bought 602.49 $XAUT, worth $3.05M, from #Bybit.
Over the past 4 days, the whale has bought 1,469.29 $XAUT, worth $7.33M, from #Bybit.
https://intel.arkm.com/explorer/address/0x0a5e3968f95d5aD4Fac72E1420A2BFFeedb7cbEB
https://x.com/OnchainLens/status/2015679418803552716
Follow @onchainlens for more onchain updates
A wallet linked to the Pendle Team (@pendle_fi) deposited 1.8M $PENDLE, worth $3.61M, into #Bybit after holding it for 3-4 years.
The wallet received these $PENDLE for $266K from the Pendle Vesting Wallet.
Address: 0xf82e1E9381A1d92B5897eBe2F9B61160222f1aeb
https://x.com/OnchainLens/status/2015378723818942854
Follow @onchainlens for more onchain updates
A whale bought 566.80 $XAUT worth ($2.79M) from #Bybit in the past 2 days.
The whale still hold $11.36M $USDT and likely to buy more.
Address - 0x0a5e3968f95d5aD4Fac72E1420A2BFFeedb7cbEB
Data - @nansen_ai
https://x.com/OnchainLens/status/2014673139159240920
Follow @onchainlens for more onchain updates
A whale deposited 665,035 $HYPE, worth $14.54M into #Bybit, making a profit of $7.04M.
The whale initially bought 651,895 $HYPE for $7.5M at a price of $11.5, between Dec 3, 2024, and Dec 8, 2024, and sent it for staking.
https://hyperbot.network/trader/0xffe664491482ae9db6ba9e55c2ed1ea55c700a52
https://hyperevmscan.io/address/0xffe664491482ae9db6ba9e55c2ed1ea55c700a52
https://x.com/OnchainLens/status/2014571958009250155
Follow @onchainlens for more onchain updates
A wallet linked to the Pendle Team (@pendle_fi) deposited 1.8M $PENDLE, worth $3.84M, into #Bybit after holding it for 3 years.
The wallet received these $PENDLE for $266K from the Pendle Vesting Wallet.
Address: 0x6b4166974fcf730d7933656d26d52922ee285cf0
https://x.com/OnchainLens/status/2014514593566248989
Follow @onchainlens for more onchain updates