feat: 支持图片账号并发配置,并优化多账号并发占位与等待机制#111
Open
Jimmy-Bots wants to merge 3 commits intobasketikun:mainfrom
Open
Conversation
Contributor
Author
|
应该符合 issue #100 需求 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
本次改动主要优化图片生成链路中的账号并发控制能力,新增单账号图片并发配置,并补充更严格的账号占位与等待机制,减少高并发下多个请求同时竞争同一账号时的冲突与不稳定行为。
主要改动
1. 新增单账号图片并发配置
在管理员设置页新增“单账号图片并发”配置项,用于限制每个账号同时处理的图片请求数量。
当前配置会同时接入:
这样管理员可以直接通过设置页控制单账号允许的图片并发数,而不是依赖固定写死的行为。
2. 默认单账号图片并发调整为 3
本次将单账号图片并发默认值调整为
3,用于在默认情况下提升图片请求吞吐能力。默认值已在以下层面保持一致:
这样即使没有显式配置,也会采用统一的默认行为。
3. 图片账号分配改为严格占位
此前图片请求在选择账号后,再更新进行中计数,中间存在竞争窗口。
在高并发情况下,多个请求可能在计数尚未更新前先后选中同一个账号,导致单账号并发限制不够严格。
因此做出如下改动:
这样当单账号并发设置为
1时,多个几乎同时到达的请求不会再同时拿到同一个账号。4. 并发满额时支持等待而不是立即失败
在存在可用账号、但这些账号当前并发名额已满时,请求现在不会直接返回
no available image quota,而是会等待已有请求释放名额后再继续尝试获取账号。实现方式是:
这样在多用户同时生成图片时,请求行为会更符合“排队等空位”的直觉,而不是因为瞬时并发满额直接失败。
5. 保持账号不可用场景下的快速失败
本次等待机制只针对“账号可用但并发已满”的情况。
如果当前账号本身不可用,例如:
则仍然会按现有逻辑快速失败,而不会无意义地一直等待。
6. 刷新失败或账号失效时及时释放占位
如果某个请求占位后,在刷新账号状态时发现账号不可用或失效,会立即释放占位并尝试其他账号,避免并发名额被错误占住。
同时在图片请求成功、失败、上游拒绝等路径下,也都会释放对应占位,避免名额泄漏。
影响范围
备注