Skip to content

性能优化

本指南帮助你优化 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核2GB20GB
团队使用4核8GB50GB
高负载8核16GB100GB

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;
  }
}

常见问题

响应慢

可能原因:

  1. 模型响应慢 → 使用更快的模型
  2. 网络延迟 → 使用本地模型或代理
  3. 内存不足 → 清理记忆和会话
  4. 并发过高 → 限制并发数

内存占用高

解决方案:

  1. 减少记忆数量
  2. 定期清理会话
  3. 限制浏览器页面数
  4. 移除不用的技能

CPU 使用高

解决方案:

  1. 降低并发数
  2. 优化技能代码
  3. 使用更轻量的模型
  4. 检查是否有死循环

下一步

基于 MIT 许可发布