Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit e17b567

Browse files
committed
commit
1 parent 7dacb73 commit e17b567

File tree

12 files changed

+244
-7
lines changed

12 files changed

+244
-7
lines changed

Index.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
<!-- * HAProxy -->
4848
* [IPv6](proxy/IPv6.md)
4949
* [HTTP/2](proxy/HTTP2.md)
50-
* [性能指南](proxy/Performance.md)
50+
* [性能](proxy/Performance.md)
51+
* [性能测试](proxy/Benchmark.md)
5152
* 监控
5253
* [Agent概念](agents/Index.md)
5354
* [安装Agent](agents/Install.md)
@@ -79,8 +80,9 @@
7980
* 代理统计
8081
* 代理访问日志
8182
* 主机监控项
82-
* Javascript辅助函数
83-
* 数组
83+
* [Javascript辅助函数](javascript/Helper.md)
84+
* 数组
85+
* [代理服务上下文](javascript/ProxyContext.md)
8486
* 高级
8587
* [集群](advanced/cluster/Index.md)
8688
* [安装集群控制台](advanced/cluster/Install.md)

agents/Threshold.md

+50
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,53 @@ ${ROW.name}已使用80%
170170
javascript:new Date().getTime() / 1000 - ${timestamp}
171171
~~~
172172
例子中的`${timestamp}`从数值中获取。
173+
174+
## 格式化
175+
可以使用函数来格式化阈值:
176+
~~~
177+
值 | 函数1(参数1, 参数2, ...) | 函数2 | ...
178+
~~~
179+
如上所示,使用竖线`|`分隔多个函数,如果函数有参数的话,可以使用`(``)`来包含,多个参数之间用英文逗号`,`隔开。
180+
181+
目前支持的函数有:
182+
183+
### 转换为浮点数数字 - float
184+
v0.1.8.2加入,没有参数,或者参数为格式化字符串,随后跟更多格式化中的参数:
185+
~~~
186+
${ROW.percent | float} => 123.456712
187+
${ROW.percent | float('%.2f')} => "123.46"
188+
${ROW.percent | float('%.2f%s', ' Percent')} => "123.46 Percent"
189+
~~~
190+
191+
### 对数字四舍五入 - round
192+
v0.1.8.2加入,没有参数或者参数为需要保留的小数点个数:
193+
~~~
194+
${ROW.percent | round} => "123"
195+
${ROW.percent | round(2)} => "123.46"
196+
~~~
197+
198+
### 对数字进行取不小于它的整数 - ceil
199+
v0.1.8.2加入:
200+
~~~
201+
${ROW.percent | ceil} => "124"
202+
~~~
203+
204+
### 对数字进行取不大于它的整数 - floor
205+
v0.1.8.2加入:
206+
~~~
207+
${ROW.percent | floor} => "123"
208+
~~~
209+
210+
### 格式化 - format
211+
v0.1.8.2加入,参数为格式化字符串,随后跟更多格式化中的参数:
212+
~~~
213+
${ROW.percent | format('%.2f')} => "123.46"
214+
${ROW.percent | format('%.2f%s', ' Percent')} => "123.46 Percent"
215+
~~~
216+
217+
### 附加参数 - append
218+
v0.1.8.2加入,参数为格式化字符串,随后跟更多格式化中的参数:
219+
~~~
220+
${ROW.name | append('Book')} => GolangBook
221+
${ROW.name | append('A', 'B', 'C')} => GolangABC
222+
~~~

javascript/Helper.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Javascript辅助函数

javascript/ProxyContext.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# 代理服务上下文
2+
可以在Javascript中使用`context`来访问代理服务的上下文信息。
3+
4+
示例1:打印Server信息:
5+
~~~javascript
6+
console.log(context.server);
7+
~~~
8+
9+
示例2:根据Backend ID来查找一个后端服务器信息(从v0.1.9开始):
10+
~~~javascript
11+
var backend = context.server.findBackend("0biKxy56Y4sUoo9Z");
12+
console.log(backend.address);
13+
~~~
14+
15+
## http.Server对象
16+
~~~javascript
17+
http.Server = function (options) {
18+
this.isOn = true;
19+
this.id = "";
20+
this.filename = "";
21+
this.name = [];
22+
this.description = "";
23+
this.listen = [];
24+
this.backends = [];
25+
this.locations = [];
26+
this.http = true;
27+
this.ssl = {};
28+
29+
// 查找后端服务器
30+
this.findBackend = function (backendId) {};
31+
32+
// 查找路径规则
33+
this.findLocation = function (locationId) {};
34+
35+
};
36+
~~~
37+
38+
## http.Backend对象
39+
~~~javascript
40+
http.Backend = function (options) {
41+
this.isOn = true;
42+
this.id = "";
43+
this.address = "";
44+
this.weight = 0;
45+
this.isDown = false;
46+
this.isBackup = false;
47+
this.name = [];
48+
this.code = "";
49+
};
50+
~~~
51+
52+
## http.Location对象
53+
~~~javascript
54+
http.Location = function (options) {
55+
this.isOn = true;
56+
this.pattern = "";
57+
this.cachePolicy = "";
58+
this.fastcgi = [];
59+
this.id = "";
60+
this.index = [];
61+
this.root = "";
62+
this.rewrite = [];
63+
this.websocket = {};
64+
this.backends = [];
65+
66+
this.findBackend = function (backendId) {};
67+
}
68+
~~~
69+
70+
## http.Fastcgi对象
71+
~~~javascript
72+
http.Fastcgi = function (options) {
73+
this.id = "";
74+
this.isOn = true;
75+
this.pass = "";
76+
};
77+
~~~
78+
79+
## http.Rewrite对象
80+
~~~javascript
81+
http.Rewrite = function (options) {
82+
this.id = "";
83+
this.isOn = true;
84+
this.pattern = "";
85+
this.replace = "";
86+
};
87+
~~~

log/Storage.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* `ElasticSearch` - 可以将日志输出到ElasticSearch中
1111
* `MySQL` - 可以将日志输出到MySQL的一个或一组表中
1212
* `TCP Socket` - 可以将日志输出到TCP Socket中,这样你就可以自己写一个TCP服务来接收这些日志
13+
* `Syslog` - 可以将日志通过输出到syslog中,只有在Linux下可以使用,在v0.1.9中加入
1314
* `命令行输入流` - 可以将日志输出到一个命令的输入流中(`stdin`),这样你可以通过读取输入流来接收这些日志
1415

1516
如果使用了模板,可以在这里查看支持的[模板变量](Index.md#模板变量)
@@ -23,7 +24,7 @@
2324

2425
## 命令输入流示例
2526
### 使用PHP读取日志
26-
写一个`log.php`放在当前用户可以访问的一个目录下,比如`/root/log.php`,然后写入内容:
27+
写一个`log.php`放在当前用户可以访问的一个目录下,比如`/root/log.php`并保证有可执行权限,然后写入内容:
2728
~~~php
2829
<?php
2930

@@ -60,3 +61,15 @@ fclose($stdin);
6061
* `参数` - 执行命令附加的参数
6162
* `工作目录` - 执行命令时所在的目录,通常可以不填
6263

64+
### 使用Shell读取日志
65+
相关的命令为:
66+
~~~bash
67+
#!/usr/bin/env bash
68+
69+
while read line
70+
do
71+
echo "$line" >> /var/log/teaweb-accesslog
72+
done
73+
~~~
74+
75+
你也可以修改其中的日志输出,改成通过TCP或者UDP发送等。

main/Summary.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# 简介
22
TeaWeb是一款集静态资源、缓存、代理、日志、统计、监控于一体的可视化智能WebServer,原理是通过HTTP代理的方式连接用户请求和开发者自己的后端服务,从而不仅实现对请求的转发处理,也可以实现自动的缓存、日志、统计、监控等功能,关于代理的部分,请访问[代理原理](../proxy/Architect.md)
33

4-
TeaWeb使用Go语言实现,在高可定制化前提下,保证高性能、高并发。
4+
TeaWeb使用Go语言实现,在高可定制化前提下,保证[高性能](../proxy/Benchmark.md)、高并发。
5+
6+
TeaWeb的愿景是做一个能让程序员和运维工程师喝着茶、唱着歌,就能把事情完成的一个智能化的简单易用的产品。

proxy/Benchmark.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# 性能测试
2+
可以使用[`wrk`](https://github.com/wg/wrk)或其他工具(`ab`命令比较老旧,不建议使用)对TeaWeb进行压力性能测试。
3+
4+
以下拿一个虚拟机作为示例:
5+
* 硬件:配置为2G内存、双核CPU,单核频率为2.4G
6+
* 操作系统:CentOS v7.5.1804
7+
* TeaWeb:版本为v0.1.8
8+
9+
## 命令说明
10+
`-c`为并发连接数,`-t`为线程数,`-d`为测试持续时间,默认单位为秒。
11+
12+
## 静态文件测试
13+
文件尺寸为:516B,测试命令:
14+
~~~bash
15+
/opt/wrk -c 1000 -t 16 -d 60 "http://192.168.2.30:8081/index.html"
16+
~~~
17+
18+
开启日志和统计的测试结果:
19+
~~~
20+
Running 1m test @ http://192.168.2.30:8081/index.html
21+
16 threads and 1000 connections
22+
Thread Stats Avg Stdev Max +/- Stdev
23+
Latency 92.37ms 75.08ms 896.79ms 68.53%
24+
Req/Sec 741.97 188.51 2.48k 79.70%
25+
708650 requests in 1.00m, 348.72MB read
26+
Requests/sec: 11797.25
27+
~~~
28+
29+
关闭日志和统计的测试结果:
30+
~~~
31+
Running 1m test @ http://192.168.2.30:8081/index.html
32+
16 threads and 1000 connections
33+
Thread Stats Avg Stdev Max +/- Stdev
34+
Latency 48.80ms 11.92ms 143.85ms 85.50%
35+
Req/Sec 1.28k 121.86 2.19k 69.84%
36+
1218313 requests in 1.00m, 599.53MB read
37+
Requests/sec: 20278.17
38+
Transfer/sec: 9.98MB
39+
~~~
40+
41+
## 代理测试
42+
代理后端的一个用Apache服务的gif图片文件,尺寸为2.6kb,Apache服务同TeaWeb在同一台服务器上,测试命令:
43+
~~~bash
44+
/opt/wrk -c 1000 -t 16 -d 60 "http://192.168.2.30:8081/images/apache_pb.gif"
45+
~~~
46+
47+
开启日志和统计的测试结果:
48+
~~~
49+
Running 1m test @ http://192.168.2.30:8081/images/apache_pb.gif
50+
16 threads and 1000 connections
51+
Thread Stats Avg Stdev Max +/- Stdev
52+
Latency 220.60ms 79.02ms 810.65ms 88.32%
53+
Req/Sec 285.02 109.75 550.00 70.08%
54+
271933 requests in 1.00m, 678.58MB read
55+
Requests/sec: 4525.87
56+
Transfer/sec: 11.29MB
57+
~~~
58+
59+
关闭日志和统计的测试结果:
60+
~~~
61+
Running 1m test @ http://192.168.2.30:8081/images/apache_pb.gif
62+
16 threads and 1000 connections
63+
Thread Stats Avg Stdev Max +/- Stdev
64+
Latency 151.39ms 18.79ms 539.18ms 74.86%
65+
Req/Sec 411.13 87.49 787.00 67.26%
66+
393091 requests in 1.00m, 0.96GB read
67+
Requests/sec: 6541.07
68+
Transfer/sec: 16.32MB
69+
~~~
70+
71+
当然,具体测试的时候,后端服务最好是静态文件,以便消除因为后端服务的速度太慢而导致测试结果低下的问题。
72+
73+
## 资源释放情况
74+
测试完成后,内存迅速恢复到95M左右,CPU恢复到5%以下。

proxy/Gzip.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* `Gzip内容最小长度` - Gzip需要压缩的内容的最小长度,也即当响应内容达到这个长度的时候才会启动Gzip压缩,0表示不限制,内容长度从文件尺寸或Content-Length中获取;
1414
* `Gzip文件MimeType` - 支持Gzip的文件的类型,默认为`text/html``application/json`,也支持类似于`text/*`的类型说明。通常只有文本文件需要压缩。
1515

16-
加入我们把级别设置为5`Gzip内容最小长度`设置为1k,保存后的信息为:
16+
假如我们把级别设置为5`Gzip内容最小长度`设置为1k,保存后的信息为:
1717
![gzip3.png](gzip3.png)
1818

1919
然后按照提示重启服务即可生效。

proxy/IPv6.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ IPv6是英文“Internet Protocol Version 6”(互联网协议第6版)的缩
3333
[::]:端口
3434
[::]:8081
3535
~~~
36-
来表达同样的意思。而且在TeaWeb中,`0.0.0.0``[::]`是可以通用的,两者的效果一样,对于同一个端口来说,同时只能使用一种版本。
36+
来表达同样的意思。而且在TeaWeb中,`0.0.0.0``[::]`是可以通用的,两者的效果一样,对于同一个端口来说,同时只能使用一种版本。
37+
38+
## 防火墙设置
39+
如果你启用了`ip6tables`,记得在`ip6tables`中添加对应端口的ACCEPT规则。

proxy/Performance.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212

1313
## 添加缓存
1414
根据缓存策略的不同有不同程度的加速效果,建议优先选择内存缓存。
15+
16+
## CPU比内存更重要
17+
增加CPU数量能让TeaWeb更快地处理请求,所以能够有效地提高并发。而TeaWeb前方百计地优化内存的使用,所以内存只有在突然增大的流量时才会急速增加到数百兆字节,高峰期过后,内存会得到很快的释放。

proxy/Variables.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
* `${arg.NAME}` - 单个参数值
6262
* `${headers}` - 所有Header信息组合字符串
6363
* `${header.NAME}` - 单个Header值
64+
* `${documentRoot}` - 当前请求的文档根目录,v0.1.9
6465

6566
## 响应相关变量
6667
* `${requestTime}` - 请求花费时间

settings/MongoDB.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
在Linux和MacOS上,解压MongoDB安装包后,建议的启动命令为:
1919
~~~bash
2020
cd MongoDB安装目录
21+
mkdir data
2122
bin/mongod --dbpath=./data/ --fork --logpath=./data/fork.log
2223
~~~
2324

0 commit comments

Comments
 (0)