Repository navigation
修复:运行容量的内存紧张只看网关自身并可在设置里关闭(#653) #654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: beta
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,15 +80,21 @@ fn effective(settings: &CapacitySettings, resources: monitor::Resources) -> Limi | |
| let memory_bytes = if settings.memory_mib == 0 { auto_memory.max(16 * MIB) } | ||
| else { settings.memory_mib.saturating_mul(MIB).min((resources.total_bytes * 3 / 4) as usize).max(16 * MIB) }; | ||
| let process_ceiling = resources.total_bytes.saturating_mul(4) / 5; | ||
| let memory_ceiling = resources.container_bytes.unwrap_or(resources.process_bytes) >= process_ceiling; | ||
| // macOS 优先以内核压力等级为准(1 正常 / 2 警告 / 4 危险): | ||
| // 2 级在正常桌面使用中就会触发,只有 4(critical)才代表真正紧张; | ||
| // 其它平台或取不到内核等级时沿用可用内存比例判据。进程/容器超总内存 4/5 的硬上限不变。 | ||
| let host_memory_pressure = match resources.os_pressure_level { | ||
| Some(level) => level >= 4, | ||
| None => resources.available_bytes < resources.total_bytes / 10, | ||
| }; | ||
| let memory_pressure = host_memory_pressure || memory_ceiling; | ||
| let used_bytes = resources.container_bytes.unwrap_or(resources.process_bytes); | ||
| // ── 内存压力只看网关自己,不看系统剩余 ────────────────────────── | ||
| // 以前的判据是「系统可用内存低于总内存 10%」或「本进程/容器占用 ≥ 总内存 4/5」。 | ||
| // 前者等于让别的程序替网关做主:编译一次 Rust(rustc 常吃 3~4 GB)就把可用内存 | ||
| // 压到 10% 以下,一个只占几百 MB 的网关立刻判定「内存紧张」,把所有对话请求 | ||
| // 排满 10 秒后回 503「系统或容器可用内存紧张」。网关自己能要多少内存本来就由 | ||
| // 分配预算(`MemoryBudget`)卡住,系统层面再加一道只会误伤 —— 用户的口径也是 | ||
| // 「网关本身没什么内存,不该做这种限制」。 | ||
| // 现在只有三种情况算紧张: | ||
| // - 自身占用 ≥ 总内存 4/5(真正的 OOM 硬顶,任何时候都保留); | ||
| // - 自身占用 ≥ 运行内存预算(设置项,`memory_guard` 打开时生效); | ||
| // - macOS 内核压力到 4 级(critical),同受 `memory_guard` 控制。 | ||
| let memory_pressure = used_bytes >= process_ceiling | ||
| || (settings.memory_guard | ||
| && (used_bytes >= memory_bytes || resources.os_pressure_level.is_some_and(|level| level >= 4))); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 统一预算比较两侧的整数类型。
比较前把预算转换为
|
||
| let cpu_pressure = resources.cpu_percent >= 90.0; | ||
| let automatic = settings.mode == CapacityMode::Auto; | ||
| let conversations = if automatic { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import * as React from 'react' | ||
| import { Button, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@ui' | ||
| import { Button, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch } from '@ui' | ||
| import type { CapacityApi, CapacitySettings, CapacitySnapshot } from './runtime-capacity' | ||
| import type { PluginTranslate } from './plugins-store' | ||
|
|
||
| const MIB = 1024 * 1024 | ||
| const fields = (t: PluginTranslate): Array<{ key: keyof Omit<CapacitySettings, 'mode' | 'providerLimits'>; label: string; min: number; max: number }> => [ | ||
| const fields = (t: PluginTranslate): Array<{ key: keyof Omit<CapacitySettings, 'mode' | 'memoryGuard' | 'providerLimits'>; label: string; min: number; max: number }> => [ | ||
| { key: 'maxConversations', label: t('对话并发上限'), min: 1, max: 4096 }, | ||
| { key: 'maxInteractive', label: t('登录与续期并发'), min: 4, max: 256 }, | ||
| { key: 'maxBackground', label: t('后台任务并发'), min: 1, max: 256 }, | ||
|
|
@@ -89,11 +89,19 @@ export function RuntimeCapacityPanel({ api, t, identity = '', onSaved }: { | |
| const effective = snapshot?.effective | ||
| const usage = snapshot?.usage | ||
| return <div className='space-y-4'> | ||
| <p className='text-[12px] leading-5 text-subtle'>{t('自动管理按可用内存调节容量;手动设置仍保留内存保护和上游账号限制。')}</p> | ||
| <p className='text-[12px] leading-5 text-subtle'>{t('自动管理按运行内存预算调节容量;手动设置仍保留内存保护和上游账号限制。')}</p> | ||
| <Select value={draft?.mode || 'auto'} disabled={!draft || busy} onValueChange={value => patch('mode', value)}> | ||
| <SelectTrigger className='w-full' aria-label={t('运行容量')}><SelectValue>{modes.find(mode => mode.value === (draft?.mode || 'auto'))?.label}</SelectValue></SelectTrigger> | ||
| <SelectContent>{modes.map(mode => <SelectItem key={mode.value} value={mode.value}>{mode.label}</SelectItem>)}</SelectContent> | ||
| </Select> | ||
| <div className='space-y-1.5'> | ||
| <div className='flex items-center justify-between gap-3 text-[12px]'> | ||
| <span>{t('内存紧张保护')}</span> | ||
| <Switch checked={draft?.memoryGuard ?? true} disabled={!draft || busy} | ||
| onCheckedChange={value => patch('memoryGuard', value)} aria-label={t('内存紧张保护')} /> | ||
| </div> | ||
| <p className='text-[12px] leading-5 text-subtle'>{t('只看本程序自己的占用:超过运行内存预算才暂停接收新任务;关闭后仅保留「本机占用达 4/5」的硬顶。编译、浏览器等其它程序占多少内存不影响网关。')}</p> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 说明 macOS 系统压力仍会触发保护。 开启保护时,即使网关占用低于预算, 请明确说明:开启时还会检查 macOS 严重内存压力;关闭后不再检查预算和系统压力,但保留占用硬顶。同步更新对应的本地化键。 依据路径要求:“检查 UI 展示、错误提示和默认值是否符合用户直觉”。
|
||
| </div> | ||
| {effective && usage ? <div className='grid grid-cols-2 gap-x-4 gap-y-2 rounded-md border border-hairline p-3 text-[12px] tabular-nums'> | ||
| <span>{t('正在处理')}</span><span className='text-right'>{usage.requests} / {effective.conversations}</span> | ||
| <span>{t('排队中')}</span><span className='text-right'>{usage.queued}</span> | ||
|
|
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恢复独立的
memory_ceiling变量。Line 115 仍用字段简写把
memory_ceiling写入Limits,但当前模块没有定义这个变量。Rust 服务因此无法编译。队列还单独使用这个字段拦截超过硬顶的请求,不能只保留memory_pressure。(raw.githubusercontent.com)先计算硬顶,再让压力判定复用它。这样关闭保护后仍保留硬顶。
修改示例
Committable suggestion