Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
‼️Vulkan станет основной технологий для рендеринга UI в Android
Начиная, с Android 17 большая часть устройств перейдет на рендеринг UI с OpenGL ES на Vulkan, а поддержку OpenGL будет убрана и станет доступна через ANGLE для трансляции команд в Vulkan.
#android#android17#vulkan#opengl
#rust#d3d12#gpu#hacktoberfest#metal#opengl#rust#vulkan#webgpu
**wgpu** is a powerful graphics library for Rust that works on many platforms, including Windows, macOS, Linux, and the web. It supports various graphics APIs like Vulkan, Metal, and DirectX. This library is safe and portable, making it easy to create graphics and compute applications. Using **wgpu**, you can build fast and efficient graphics programs that run on different devices and browsers, which is beneficial for developers who want to create cross-platform applications.
https://github.com/gfx-rs/wgpu
#rust#bsd#gpu#linux#macos#opengl#rust#terminal#terminal_emulators#vte#windows
Alacritty is a fast, cross-platform terminal emulator that uses OpenGL for smooth performance, works on BSD, Linux, macOS, and Windows, and offers customizable settings while keeping things simple. It’s lightweight, integrates well with tools like window managers or terminal multiplexers, and is already reliable enough for daily use despite being in beta, making it ideal for users who want speed and flexibility without unnecessary features.
https://github.com/alacritty/alacritty
#cplusplus#3d_engine#arm64#cmake#cplusplus#cpp17#d3d11#directx#directx11#engine#game#game_engine#gamedev#mod#opengl#opensource#sdl#sdl2#stalker#x64#xray_engine
OpenXRay is a free, improved version of the X-Ray Engine for S.T.A.L.K.E.R. games like Call of Pripyat and Clear Sky. It adds 64-bit support, higher FPS, bug fixes, modding tools, and runs on Linux, macOS, and more. This benefits you with smoother, more stable gameplay, better performance on modern or non-Windows PCs, and easy access to new mods without changing the classic feel.
https://github.com/OpenXRay/xray-16