性能优化
本指南帮助你优化 OpenClaw 的性能,提升响应速度和资源利用率。
响应速度优化
模型选择
不同模型的响应速度差异较大:
| 模型 | 响应速度 | 适用场景 |
|---|---|---|
| Claude 3.5 Sonnet | 中等 | 通用任务 |
| GPT-4 Turbo | 快 | 简单任务 |
| GPT-3.5 Turbo | 很快 | 快速响应 |
| Kimi-K2.5 | 中等 | 中文任务 |
| 本地模型 | 取决于硬件 | 隐私敏感 |
建议:
- 简单任务使用快速模型
- 复杂任务使用高级模型
- 考虑使用本地模型减少网络延迟
流式响应
启用流式响应提升体验:
json
{
"model": {
"streaming": true
}
}缓存配置
启用缓存减少重复计算:
json
{
"cache": {
"enabled": true,
"ttl": 3600,
"maxSize": "100MB",
"types": [
"embeddings",
"completions",
"searches"
]
}
}清除缓存:
bash
openclaw cache clear内存优化
记忆管理
限制记忆数量减少内存占用:
json
{
"memory": {
"enabled": true,
"maxEntries": 500,
"retention": 2592000,
"cleanupInterval": 3600
}
}手动清理:
bash
openclaw memory cleanup会话管理
定期清理过期会话:
json
{
"session": {
"timeout": 3600,
"maxAge": 86400,
"cleanup": {
"enabled": true,
"interval": 3600
}
}
}手动清理:
bash
openclaw sessions cleanup磁盘配额
限制存储使用:
json
{
"storage": {
"quota": {
"enabled": true,
"maxSize": "10GB",
"warningThreshold": 0.8
}
}
}并发优化
并发限制
控制并发请求数:
json
{
"concurrency": {
"maxRequests": 10,
"maxSkillsParallel": 5,
"queueSize": 100
}
}超时设置
合理设置超时:
json
{
"timeouts": {
"model": 60000,
"skill": 30000,
"command": 10000,
"browser": 30000
}
}模型优化
参数调优
根据任务调整参数:
json
{
"model": {
"temperature": 0.3, // 降低提高确定性
"maxTokens": 2048, // 限制输出长度
"topP": 0.9,
"frequencyPenalty": 0,
"presencePenalty": 0
}
}多模型策略
使用不同模型处理不同任务:
json
{
"modelStrategy": {
"simple": {
"provider": "openai",
"modelId": "gpt-3.5-turbo"
},
"complex": {
"provider": "anthropic",
"modelId": "claude-3-5-sonnet"
},
"code": {
"provider": "anthropic",
"modelId": "claude-3-5-sonnet"
}
}
}网络优化
连接池
启用连接池减少连接开销:
json
{
"network": {
"connectionPool": {
"enabled": true,
"maxConnections": 50,
"maxConnectionsPerHost": 10
}
}
}请求压缩
启用请求压缩:
json
{
"network": {
"compression": true
}
}代理优化
优化代理配置:
json
{
"proxy": {
"enabled": true,
"url": "http://127.0.0.1:7890",
"timeout": 10000,
"keepAlive": true
}
}技能优化
懒加载
延迟加载不常用的技能:
json
{
"skills": {
"lazyLoad": true,
"preload": ["filesystem", "memory"]
}
}技能缓存
缓存技能执行结果:
json
{
"skills": {
"cache": {
"enabled": true,
"ttl": 300
}
}
}移除不用的技能
bash
openclaw skills list
openclaw skills uninstall <unused-skill>浏览器优化
资源限制
限制浏览器资源使用:
json
{
"browser": {
"options": {
"headless": true,
"args": [
"--disable-gpu",
"--disable-dev-shm-usage",
"--no-sandbox"
]
},
"limits": {
"maxPages": 5,
"pageTimeout": 30000
}
}
}会话复用
复用浏览器会话:
json
{
"browser": {
"reuseSession": true,
"sessionTimeout": 300000
}
}监控和诊断
性能监控
查看性能指标:
bash
openclaw metrics性能报告
生成性能报告:
bash
openclaw performance report瓶颈分析
识别性能瓶颈:
bash
openclaw performance analyze资源监控
CPU 使用
bash
# 实时监控
openclaw monitor --cpu
# 查看历史
openclaw stats cpu --period 1h内存使用
bash
# 实时监控
openclaw monitor --memory
# 查看历史
openclaw stats memory --period 1h磁盘使用
bash
# 查看存储使用
openclaw stats storage优化检查清单
运行自动优化检查:
bash
openclaw optimize --check检查项目:
- [ ] 是否启用缓存
- [ ] 记忆数量是否合理
- [ ] 会话是否定期清理
- [ ] 技能是否懒加载
- [ ] 超时是否合理
- [ ] 并发是否受限
云端部署优化
服务器规格
选择合适的配置:
| 使用场景 | CPU | 内存 | 存储 |
|---|---|---|---|
| 个人使用 | 2核 | 2GB | 20GB |
| 团队使用 | 4核 | 8GB | 50GB |
| 高负载 | 8核 | 16GB | 100GB |
CDN 加速
使用 CDN 加速静态资源:
json
{
"cdn": {
"enabled": true,
"provider": "tencent",
"domain": "cdn.your-domain.com"
}
}负载均衡
高并发场景使用负载均衡:
yaml
# nginx.conf
upstream openclaw {
server localhost:3000;
server localhost:3001;
server localhost:3002;
}
server {
listen 80;
location / {
proxy_pass http://openclaw;
}
}常见问题
响应慢
可能原因:
- 模型响应慢 → 使用更快的模型
- 网络延迟 → 使用本地模型或代理
- 内存不足 → 清理记忆和会话
- 并发过高 → 限制并发数
内存占用高
解决方案:
- 减少记忆数量
- 定期清理会话
- 限制浏览器页面数
- 移除不用的技能
CPU 使用高
解决方案:
- 降低并发数
- 优化技能代码
- 使用更轻量的模型
- 检查是否有死循环