Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
🍂 “Our Lord has written the promise of resurrection, not in books alone but in every leaf of springtime.”
– Martin Luther
🌻look at the trees with fallen leaves during autumn, they keep on standing and stand strong despite many of their leaves fall down; as if they know and trust that they will not stay in that condition forever - in fact, they'll shine more beautifully soon when the spring comes. so dear, whenever you are in crestfallen, trust that that too shall pass.. be sad, but don't lose hope that tomorrow can be better☺️
#life#thoughts#sadness#happiness#motivation
@quietworld🍃
🍂 something you dislike happened? you couldn't get something you wish for? you have been disappointed and someone hurt you? you lost someone? you failed at something you hope you're good at?
and you feel sad about it?
then be so. feel sad. be sad. cry if you must. cry your heart out. let it out. it heals to cry. it heals to allow yourself to feel things; be human. because yes it is difficult to go through those things.
& that doesn't mean that you are weak. to feel those feelings are not a sign of weakness at all ; just that we are human, we are born with the ability to feel those emotions.
your strength is not determined by your ability to suppress emotions, but by your ability to overcome it; by not letting it controls yourself longer than it should be.
there's light at the end of the tunnel if you keep going.
#thoughts#notetoself#selfreminder#strength#positivity#sadness#motivation
@quietworld🍃
Collachrymate means to cry with someone or cry a lot until tears fall. It is an old English word from the 1500s and 1600s.
This word is not used anymore today.
Unless ofcours we revive it.😉
@googlefactss
#Words#OldEnglish#Cry#Sadness#Tears😢💧
L'amore ed i sentimenti in generale stanno vivendo una brutta epoca, sostituiti il più delle volte da pulsioni eremitiche.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#illusione#illusion#solitudine#loneliness#luciajavorcekova
La guerra é portatrice di ingiustizie ed inganni, di questi ultimi uno dei più grandi é quello di pretendere di costruire un mondo migliore.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#guerra#war#violenza#violence#illusione#illusion
Non é entusiasmante prendere consapevolezza di essere quasi coetaneo di Homer Simpson.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#simpson#simpsonwave#homer#homersimpson
Secondo me a livello culturale siamo immersi in una sorta di nuovo barocco, nell'accezione più deteriore del termine.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#apparenza#appearance#illusione#illusion#spettacolo#show
Mi sono stancato di influencer e tiktoker vari, buoni solo a pietrificare l'attenzione verso cose futili.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#apparenza#appearance#appearance#illusione#illusion#incubo#nightmare
Parole inconsistenti e pii desideri.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#illusione#illusion#utopia#razzismo#racism#cgil
Trovare le parole giuste con tutti e saper cogliere le sfumature di tutte quelle che ricevo, l'ho sempre trovato uno sforzo estremo.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#disagio#unease#comunicazione#communication#linguaggio#language
L'attaccamento agli oggetti é uno degli ostacoli maggiori per la nostra felicità, come se infondessimo in essi parte della nostra anima.
#vaporonda#vaporwave#vapourwave#vaporart#seapunk#webpunk#glitch#glitchart#glitchartistscollective#chillwave#aesthetic#vaporwaveaesthetic#vaporwaveaesthetics#malinconia#melancholy#tristezza#sadness#sadboy#lofi#disagio#nostalgia#illusione#illusion#windows95#windows98#windowsxp