# 内存占用测试

## 以下测试基于 soga v2.5.3，v2ray v4.41.1，xray v1.4.2

## 测试一

### 测试内容

soga 对 `VMess MD5` 认证信息的`数据结构`内存优化

### 测试说明

`VMess MD5`+`VMessAEAD` 认证，多名用户，`alterId`均为`0`

### 测试环境

Ubuntu 20.04，8G 内存，无 swap

### 测试方法

添加`10000`名用户，启动后静置`10`分钟，计算内存占用

### 测试数据

| 程序                                  | 内存占用    | 内存百分比(取原版最低值为100%) |
| ----------------------------------- | ------- | ------------------ |
| soga (默认配置)                         | `193MB` | **`46%`**          |
| soga (设置`v2ray_reduce_memory=true`) | `118MB` | **`28%`**          |
| v2ray (v4.41.1)                     | `424MB` | 100%               |

## 测试二

### 测试内容

模拟实际用户的使用情况，测试 soga 对大量连接的内存优化

### 测试说明

`VMess+MD5`认证，`websocket`传输模式，1 名用户，`alterId`为`0`

### 测试环境

Ubuntu 20.04，8G 内存，无 swap

### 测试方法

1. 客户端->代理程序->服务端(模拟网站)，使用客户端通过代理建立多条连接至服务端，客户端在`每条连接`中`每秒`随机发送 4KB\~16KB 的数据包至服务端，服务端在`每条连接`中`每秒`随机发送 4KB\~16KB 的数据包至客户端
2. 每条连接随机持续 30\~120 秒后关闭，每关闭一条连接后会立刻建立新连接，保持正在运行的`连接总数不变`
3. 连续运行 10 分钟后，内存占用基本趋于稳定，此时统计占用的内存

| 程序                      | 内存占用(1000条连接) | 内存百分比(取原版最低值为100%) |
| ----------------------- | ------------- | ------------------ |
| soga(默认16KB连接缓存)        | `179MB`       | **`55%`**          |
| v2ray(v4.41.1)，默认配置     | `1203MB`      | 368%               |
| v2ray(v4.41.1)，16KB连接缓存 | `380MB`       | 116%               |
| v2ray(v4.41.1)，禁用连接缓存   | `327MB`       | 100%               |
| xray(v1.4.2)，16KB连接缓存   | `416MB`       | 127%               |
| xray(v1.4.2)，禁用连接缓存     | `391MB`       | 120%               |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://soga.yougotme.cc/test/memory-test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
