Недавно делал быстрый прототип асинхронного приложения в котором требовалось вызывать много синхронного кода. Да, я знаю, что это не лучший дизайн, но нужно было быстрое решение на один процесс и без очередей. Поэтому я выполнял код в потоках.
Выглядело это примерно так:
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
被CMSIS-DSP的FFT创飞 (其实是没仔细读文档
arm官方文档明确指出了 arm_rfft_fast_f32 会原地修改输入缓冲区, 然而咱用库之前没仔细读文档
Due to the use of complex transform internally, the source buffer is modified by the rfft.
看到函数参数有输入和输出指针, 然后就想当然认为函数内部一定不会覆盖输入缓冲区, 再加上输入循环缓冲用的是zero-copy, 调用FFT也是直接传入了缓冲区指针, 所以相当于算了一次FFT后直接污染了整个缓冲区
#Debug
#debug#洋屁
playing Valheim with friends
started a Linux Dedicated Server w/ Azure Playfab Crossplay Support.
can't connect server using IP and Playfab API always connecting
> Unable to preload the following plugins: libparty.so
checking libparty.so using > ldd libparty.so
IT NEEDS libpulse-dev ???????
Why? Audio lib requested SRSLY?
sudo apt install libpulse-dev
all works...
https://pypi.python.org/pypi/django-debug-toolbar
A configurable set of panels that display various #debug information about the current #request/#response.
The #Django_Debug_Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel’s content.
Here’s a screenshot of the toolbar in action:
#swift#analysis#analytics#cocoapods#crashlytics#debug#debugger#debugging#hacktoberfest#layout_debugger#leak_detection#log#logs_analysis#networking#performance_analysis#sandbox#swift#swift6#ui#uikit#view
DebugSwift is a comprehensive toolkit that simplifies debugging for Swift iOS apps by providing real-time monitoring of network requests, performance metrics (CPU, memory, FPS), crash reports, and app resources like keychain and user defaults. It includes interface tools for visualizing layouts with grid overlays and touch indicators, plus memory leak detection and console logging. The main benefit is that you can quickly identify and fix issues during development without leaving your app—just shake your device to toggle the debug panel, making troubleshooting faster and more efficient.
https://github.com/DebugSwift/DebugSwift