This commit is contained in:
mereith 2024-11-20 13:53:26 +08:00
commit 3d0033c8e0
4 changed files with 185 additions and 0 deletions

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
# 使用官方 nginx 镜像作为基础镜像
FROM nginx:alpine
# 将当前目录下的 index.html 复制到 nginx 的默认网页目录
COPY index.html /usr/share/nginx/html/
# 暴露 80 端口
EXPOSE 80

55
README.md Normal file
View File

@ -0,0 +1,55 @@
# TCP 缓冲区计算器
一个简单的网页工具,用于计算 TCP 缓冲区大小和带宽延迟积BDP
## 功能特点
- 计算带宽延迟积BDP
- 提供推荐的 TCP 缓冲区设置
- 支持 Mbps 带宽输入
- 支持毫秒级 RTT 输入
- 提供 Docker 容器部署支持
## 快速开始
### Docker 部署
```shell
#拉取镜像
docker pull mereith/tcp-cal:latest
#运行容器
docker run -d -p 80:80 mereith/tcp-cal:latest
```
访问 `http://localhost:80` 即可使用计算器。
### 手动部署
直接将 `index.html` 文件部署到任何 Web 服务器即可。
## 使用方法
1. 输入带宽单位Mbps
2. 输入 RTT单位毫秒
3. 点击"计算"按钮
4. 查看计算结果和建议的 TCP 缓冲区设置
## 构建说明
项目包含 Docker 构建脚本,可以使用以下命令构建并推送镜像:
```bash
.build.sh
```
## 技术栈
- HTML5
- CSS3
- JavaScript
- Docker
- Nginx
## 许可证
MIT License

13
build.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
IMAGE=mereith/tcp-cal
VERSION=v0.0.1
echo "Building Docker image: ${IMAGE}:${VERSION}"
docker buildx build \
--platform linux/amd64 \
--tag ${IMAGE}:${VERSION} \
--tag ${IMAGE}:latest \
--push \
.

109
index.html Normal file
View File

@ -0,0 +1,109 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TCP缓冲区计算器</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.calculator {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.input-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 200px;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
padding: 15px;
background-color: #e8f5e9;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="calculator">
<h1>TCP缓冲区计算器</h1>
<div class="input-group">
<label for="bandwidth">带宽 (Mbps):</label>
<input type="number" id="bandwidth" placeholder="例如: 600">
</div>
<div class="input-group">
<label for="rtt">RTT (毫秒):</label>
<input type="number" id="rtt" placeholder="例如: 170">
</div>
<button onclick="calculateBDP()">计算</button>
<div class="result" id="result" style="display: none;">
<h3>计算结果:</h3>
<p>BDP (比特) = <span id="bdpBits"></span> bits</p>
<p>BDP (字节) = <span id="bdpBytes"></span> bytes</p>
<h3>建议的 TCP 缓冲区设置:</h3>
<p>net.ipv4.tcp_wmem="4096 16384 <span id="recommendedWmem"></span>"</p>
<p>net.ipv4.tcp_rmem="4096 87380 <span id="recommendedRmem"></span>"</p>
</div>
</div>
<script>
function calculateBDP() {
const bandwidth = document.getElementById('bandwidth').value;
const rtt = document.getElementById('rtt').value;
// 将带宽转换为 bps (Mbps to bps)
const bps = bandwidth * 1000000;
// 将 RTT 转换为秒
const rttSeconds = rtt / 1000;
// 计算 BDP (bits)
const bdpBits = bps * rttSeconds;
// 转换为字节
const bdpBytes = Math.ceil(bdpBits / 8);
document.getElementById('bdpBits').textContent = bdpBits.toLocaleString();
document.getElementById('bdpBytes').textContent = bdpBytes.toLocaleString();
document.getElementById('recommendedWmem').textContent = bdpBytes.toLocaleString();
document.getElementById('recommendedRmem').textContent = bdpBytes.toLocaleString();
document.getElementById('result').style.display = 'block';
}
</script>
</body>
</html>