LiteClaw - 高性能 Go 版
约 462 字大约 2 分钟
2026-03-07
事件总线驱动的高性能 Go 实现,解决 Node.js 版本的 OOM 问题。
核心特性
事件驱动
- 事件总线架构
- 异步非阻塞
- 消息队列
- 发布订阅
内存优化
- 解决 OOM 问题
- 流式处理
- 内存池
- 垃圾回收优化
高性能
- Go 并发优势
- 低延迟
- 高吞吐
- 资源高效
简洁设计
- 核心代码 < 10000 行
- 依赖极少
- 易于维护
- 快速迭代
快速开始
安装
# 下载二进制
wget https://github.com/liteclaw/liteclaw/releases/latest/download/liteclaw
chmod +x liteclaw
# 或从源码
git clone https://github.com/liteclaw/liteclaw.git
cd liteclaw
go build -o liteclaw配置
# config.yaml
llm:
provider: openai
api_key: ${OPENAI_API_KEY}
event:
queue_size: 10000
workers: 4
memory:
max_buffer: 100
cleanup_interval: 300s运行
./liteclaw start技术架构
事件总线
// 事件总线
type EventBus struct {
subscribers map[string][]chan Event
mutex sync.RWMutex
}
func (eb *EventBus) Publish(topic string, event Event) {
eb.mutex.RLock()
defer eb.mutex.RUnlock()
for _, ch := range eb.subscribers[topic] {
ch <- event
}
}
func (eb *EventBus) Subscribe(topic string) <-chan Event {
ch := make(chan Event, 100)
eb.mutex.Lock()
eb.subscribers[topic] = append(eb.subscribers[topic], ch)
eb.mutex.Unlock()
return ch
}内存管理
// 内存池
type MemoryPool struct {
buffers sync.Pool
}
func NewMemoryPool() *MemoryPool {
return &MemoryPool{
buffers: sync.Pool{
New: func() interface{} {
return make([]byte, 0, 1024)
},
},
}
}
func (mp *MemoryPool) Get() []byte {
return mp.buffers.Get().([]byte)[:0]
}
func (mp *MemoryPool) Put(buf []byte) {
mp.buffers.Put(buf)
}Agent 核心
// 事件驱动 Agent
type Agent struct {
bus *EventBus
memory *MemoryPool
llm LLMProvider
}
func (a *Agent) Run(ctx context.Context) {
// 订阅消息
messages := a.bus.Subscribe("message")
for {
select {
case <-ctx.Done():
return
case msg := <-messages:
a.processMessage(msg)
}
}
}功能列表
相关链接
- GitHub: liteclaw/liteclaw