Commit 9faa1b92 authored by gejun's avatar gejun

move setting stacksize from faq to body

parent 779f32c0
......@@ -402,6 +402,17 @@ server的框架部分一般不针对个别client打印错误日志,因为当
-bvar_latency_p1=-1 # 同上
```
## 设置栈大小
brpc的Server是运行在bthread之上,默认栈大小为1MB,而pthread默认栈大小为10MB,所以在pthread上正常运行的程序,在bthread上可能遇到栈不足。
可设置如下的gflag以调整栈的大小:
```shell
--stack_size_normal=10000000 # 表示调整栈大小为10M左右
--tc_stack_normal=1 # 默认为8,表示每个worker缓存的栈的个数(以加快分配速度),size越大,缓存数目可以适当调小(以减少内存占用)
```
注意:不是说程序coredump就意味着”栈不够大“,只是因为这个试起来最容易,所以优先排除掉可能性。事实上百度内如此多的应用也很少碰到栈不够大的情况。
## 限制最大消息
为了保护server和client,当server收到的request或client收到的response过大时,server或client会拒收并关闭连接。此最大尺寸由[-max_body_size](http://brpc.baidu.com:8765/flags/max_body_size)控制,单位为字节。
......@@ -444,7 +455,7 @@ baidu_std和hulu_pbrpc协议支持传递附件,这段数据由用户自定义
## 验证client身份
如果server端要开启验证功能,需要实现`Authenticator`中的接口
如果server端要开启验证功能,需要实现`Authenticator`中的接口:
```c++
class Authenticator {
......@@ -904,14 +915,6 @@ brpc同一个进程中所有的server[共用线程](#worker线程数),如果
可能是server端的工作线程不够用了,出现了排队现象。排查方法请查看[高效率排查服务卡顿](server_debugging.md)。
### Q: 程序切换到brpc之后出现了像堆栈写坏的coredump
brpc的Server是运行在bthread之上,默认栈大小为1MB,而pthread默认栈大小为10MB,所以在pthread上正常运行的程序,在bthread上可能遇到栈不足。
注意:不是说程序core了就意味着”栈不够大“,只是因为这个试起来最容易,所以优先排除掉可能性。事实上百度内如此多的应用也很少碰到栈不够大的情况。
解决方案:添加以下gflags以调整栈大小,比如`--stack_size_normal=10000000 --tc_stack_normal=1`。第一个flag把栈大小修改为10MB,第二个flag表示每个工作线程缓存的栈的个数(避免每次都从全局拿).
### Q: Fail to open /proc/self/io
有些内核没这个文件,不影响服务正确性,但如下几个bvar会无法更新:
......
......@@ -403,6 +403,17 @@ Following are wrong settings:
-bvar_latency_p3=100 # the value must be inside [1,99] inclusive,otherwise gflags fails to parse
-bvar_latency_p1=-1 # ^
```
## Change stacksize
brpc server runs code in bthreads with stacksize=1MB by default, while stacksize of pthreads is 10MB. It's possible that programs running normally on pthreads may meet stack overflow on bthreads.
Set following gflags to enlarge the stacksize.
```shell
--stack_size_normal=10000000 # sets stacksize to roughly 10MB
--tc_stack_normal=1 # sets number of stacks cached by each worker pthread to prevent reusing from global pool each time, default value is 8
```
NOTE: It does mean that coredump of programs is likely to be caused by "stack overflow" on bthreads. We're talking about this simply because it's easy and quick to verify this factor and exclude the possibility.
## Limit sizes of messages
To protect servers and clients, when a request received by a server or a response received by a client is too large, the server or client rejects the message and closes the connection. The limit is controlled by [-max_body_size](http://brpc.baidu.com:8765/flags/max_body_size), in bytes.
......@@ -905,14 +916,6 @@ All brpc servers in one process [share worker pthreads](#Number-of-worker-pthrea
server-side worker pthreads may not be enough and requests are significantly delayed. Read [Server debugging](server_debugging.md) for steps on debugging server-side issues quickly.
### Q: Program may crash and generate coredumps unexplainable after switching to brpc
brpc server runs code in bthreads with stacksize=1MB by default, while stacksize of pthreads is 10MB. It's possible that programs running normally on pthreads may meet stack overflow on bthreads.
NOTE: It does mean that coredump of programs is likely to be caused by "stack overflow" on bthreads. We're talking about this simply because it's easy and quick to verify this factor and exclude the possibility.
Solution: Add following gflags to adjust the stacksize. For example: `--stack_size_normal=10000000 --tc_stack_normal=1`. The first flag sets stacksize to 10MB and the second flag sets number of stacks cached by each worker pthread (to prevent reusing from global each time)
### Q: Fail to open /proc/self/io
Some kernels do not provide this file. Correctness of the service is unaffected, but following bvars are not updated:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment