chore: 初始化仓库,导入项目基线代码

Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
runny committed 2026-11-16 18:12:23 +08:00
commit 7ec21f35b0
5767 files changed
+1436788

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
"""Reclaim large request buffers after their gRPC worker has returned."""
import ctypes
import gc
import sys
import threading
from concurrent.futures import ThreadPoolExecutor
_LARGE_REQUEST_BYTES = 16 * 1024 * 1024
_request_memory = threading.local()
_malloc_trim = (
getattr(ctypes.CDLL(None), "malloc_trim", None)
if sys.platform.startswith("linux")
else None
)
if _malloc_trim is not None:
_malloc_trim.argtypes = [ctypes.c_size_t]
_malloc_trim.restype = ctypes.c_int
def track_request_size(size: int) -> None:
if size >= _LARGE_REQUEST_BYTES:
_request_memory.reclaim = True
class RequestThreadPoolExecutor(ThreadPoolExecutor):
"""Collect PDF wrapper cycles and trim idle arenas after large RPC tasks."""
def submit(self, fn, /, *args, **kwargs):
return super().submit(self._run, fn, args, kwargs)
@staticmethod
def _run(fn, args, kwargs):
try:
return fn(*args, **kwargs)
finally:
if getattr(_request_memory, "reclaim", False):
_request_memory.reclaim = False
# Inside the RPC handler, gRPC still owns the request argument.
# Here its worker has returned, so the input arena can be freed.
gc.collect()
if _malloc_trim is not None:
_malloc_trim(0)