Skip to content

Commit 910e0cd

Browse files
committed
fix pcre_jit config
1 parent 48bba1d commit 910e0cd

File tree

4 files changed

+72
-20
lines changed

4 files changed

+72
-20
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
## 优势
1313

14+
- [ ] 代表需要手动开启
15+
- [x] 代表内置开启
16+
1417
内置如下模块/特性:
1518

1619
- 内嵌模块
@@ -26,12 +29,12 @@
2629
- [x] [ssl配置](book/02配置样例/01ssl配置样例.md)
2730
- 调优列表
2831
- [x] [worker数量](book/03配置调优/01worker数量调优.md)
29-
- [x] [使用HTTP2](book/03配置调优/02使用HTTP2.md)
30-
- [x] [SSL会话缓存](book/03配置调优/03SSL会话缓存.md)
31-
- [x] [使用server_name代替if指令判断domain](book/03配置调优/04使用server_name代替if指令判断domain.md)
32-
- [x] [使用$request_uri代替正则](book/03配置调优/05使用$request_uri代替正则.md)
33-
- [x] [使用try_files指令来确保文件存在](book/03配置调优/06使用try_files指令来确保文件存在.md)
3432
- [x] [使用return代替rewrite做重定向](book/03配置调优/07使用return代替rewrite做重定向.md)
33+
- [ ] [使用HTTP2](book/03配置调优/02使用HTTP2.md)
34+
- [ ] [SSL会话缓存](book/03配置调优/03SSL会话缓存.md)
35+
- [ ] [使用server_name代替if指令判断domain](book/03配置调优/04使用server_name代替if指令判断domain.md)
36+
- [ ] [使用$request_uri代替正则](book/03配置调优/05使用$request_uri代替正则.md)
37+
- [ ] [使用try_files指令来确保文件存在](book/03配置调优/06使用try_files指令来确保文件存在.md)
3538

3639
### 构建介质
3740

book/03配置调优/08启用PCRE JIT以加速正则表达式的处理.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@
44
- [更多nginx文档](https://weiliang-ms.github.io/nginx/)
55
- [更多linux相关文档](https://weiliang-ms.github.io/wl-awesome/)
66

7-
> 解释说明
7+
> 使用`pcre_jit`的优势
88
9-
1. 正则检查规则可能非常耗时,尤其是复杂的正则表达式(regex)条件,允许对正则表达式使用`JIT`可以加快处理速度。
10-
2. 通过使用`PCRE`库编译`NGINX`,可以用`location`块执行复杂的操作,并使用强大的`rewrite`指令
11-
3.
9+
正则检查规则可能非常耗时,尤其是复杂的正则表达式(regex)条件,允许对正则表达式使用`JIT`可以加快处理速度。
1210

13-
> 使用样例
11+
通过使用`PCRE`库编译`NGINX`,可以用`location`块执行复杂的操作,并使用强大的`rewrite`指令
1412

15-
- 不建议实现方式
13+
`PCRE JIT`规则匹配引擎可以显著提高正则表达式的处理速度,带有`pcre_jit``NGINX`比没有它的`NGINX`快很多(处理正则表达式)。
14+
这个选项可以提高性能。
1615

17-
```nginx configuration
18-
```
16+
> 使用`pcre_jit`的劣势
1917
20-
- 建议实现方式
18+
在某些情况下,`pcre_jit`可能有负面影响,具体参考[PCRE性能优化](../优秀文档/PCRE性能优化.md)
2119

22-
```nginx configuration
20+
> 启用方式
21+
22+
- `pcre8.20+`
23+
- `nginx`编译时添加参数: `--with-pcre=path_to_pcre8.20+ --with-pcre-jit`
2324

24-
```
25+
> 使用方式
26+
27+
```nginx configuration
28+
http {
29+
...
30+
pcre_jit on;
31+
...
32+
}
33+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[原文:PCRE Performance Project](https://zherczeg.github.io/sljit/pcre.html)
2+
3+
## PCRE性能优化
4+
5+
### 简介
6+
7+
`PCRE-sljit`项目的目的是提高[pcre](http://www.pcre.org/) 库的模式匹配速度。
8+
9+
该项目通过使用`sljit`来完成的,`sljit`是一个即时(JIT)编译库,
10+
用于从`pcre_compile()`生成的内部字节码表示转换机器码。
11+
12+
`PCRE-sljit`在通用模式上提供了与基于`DFA`的引擎(如`re2`)相似的匹配速度,但仍然保持`PERL`兼容性。
13+
14+
该功能已经作为`PCRE 8.20`及以上版本的一部分发布,`JIT``8.32`中得到了很大的改进,并且引入了一个原生的接口。
15+
16+
### 关于性能优化
17+
18+
只有在匹配正则表达式占总运行时至少`4-5`%的情况下,`PCRE-JIT`才会对您有所帮助。
19+
20+
否则,由于二进制布局的改变,可能不会有任何性能提高(或者会看到性能下降)
21+
22+
不幸的是,由于`CPU`缓存布局、分支预测机制等原因,插入`nops`可以增加或减少最多可达`3%`的程序运行时间,。
23+
24+
在人为干预下,运行时间的变化幅度可能更大(例如±50%)。当任何函数被修改时,即使改变很小,它也会影响整个二进制布局,
25+
因为其他函数的入口偏移量也会被改变(特别是那些被链接器放在可执行文件中该函数之后的函数)。
26+
因此,当匹配正则表达式的比例非常低时,在使用`PCRE-JIT`时,您可能会遇到性能的轻微下降。
27+
28+
### Usage
29+
30+
TODO
31+
32+
### Motivation
33+
34+
### 工作原理
35+
36+
### Why is it faster?
37+
38+
### 编译时开销
39+
40+

rpmbuild/SOURCES/nginx.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ worker_rlimit_nofile 65535;
66
working_directory /var/dump/nginx;
77
pid /var/run/nginx.pid;
88

9+
# pcre JIT
10+
pcre_jit off;
11+
912
events {
1013
use epoll;
1114
worker_connections 10240;
@@ -19,7 +22,7 @@ http {
1922
large_client_header_buffers 4 512k;
2023
default_type application/octet-stream;
2124

22-
index index.php index.htm index.html index.$geo.html;
25+
index index.php index.htm index.html;
2326

2427
#web security
2528
#include conf/naxsi/naxsi_core.rules;
@@ -63,9 +66,6 @@ http {
6366
more_set_headers "Server: Unknown";
6467
absolute_redirect off;
6568

66-
# pcre JIT
67-
pcre_jit on;
68-
6969
# compress
7070
gzip on;
7171
gzip_min_length 1k;

0 commit comments

Comments
 (0)