New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 echo_server.c 疑问 #35

Closed
xzzh999 opened this Issue Jun 5, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@xzzh999

xzzh999 commented Jun 5, 2017

你好,大牛,关于demo中的stackful中的echo_server.c 请教下:
环境:CentOS Linux release 7.2.1511 (Core)

运行./demo coroutine_echo_client 10 后服务器端回显正常,但是改成100 或者 1000后,
服务器端只打印了部分回显,其余的都是打印 wait 等待状态。这是什么原因呢?是因为
服务器端的栈开销太大导致的麽?

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Jun 5, 2017

Member

我这边测试ok,你可以启用debug编译,在运行下看看,如果有问题,会有断言和错误信息报出来的。。然后贴出来看下。

debug模式编译:

$ xmake f -m debug
$ xmake 

运行:

$ xmake run demo coroutine_echo_server
$ xmake run demo coroutine_echo_client 100
Member

waruqi commented Jun 5, 2017

我这边测试ok,你可以启用debug编译,在运行下看看,如果有问题,会有断言和错误信息报出来的。。然后贴出来看下。

debug模式编译:

$ xmake f -m debug
$ xmake 

运行:

$ xmake run demo coroutine_echo_server
$ xmake run demo coroutine_echo_client 100

@waruqi waruqi added the pending label Jun 5, 2017

@xzzh999

This comment has been minimized.

Show comment
Hide comment
@xzzh999

xzzh999 Jun 6, 2017

是这样的:我的编译方式没有完全按照规定的方式,因为使用xmake编译会有如下错误:

 error: runv(gcc -c -MM -g -Wall -Werror -std=c99 -Ibuild -Ibuild/tbox -D__tb_debug__ -D__tb_small__ 
 -D__tb_prefix__="tbox" -Ipkg/polarssl.pkg/inc/linux -Ipkg/polarssl.pkg/inc -Ipkg/pcre2.pkg/inc/linux -
  Ipkg/pcre2.pkg/inc -DPCRE2_CODE_UNIT_WIDTH=8 -m64 -I/usr/local/include -I/usr/include -o 
  /tmp/.xmake/_2310DDA45999AEBF2041158C3B714B00 src/tbox/tbox.c) failed(127)!

我直接用的makefile, 下面是我的编译方法:

 $ xmake f -m debug
 $ make

能编译通过,能生成 demo;

反复运行了几次 ./build/demo coroutine_echo_client 100 之后, 客户端打印:

     [tbox]: init: ..
     [tbox]: version: tbox_v1_6_2_201706061135_x86_64_sse2_elf by gnu c/c++ 4.8
     [tbox]: init: ok
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     ...
     [demo]: sending 0 ..
     [demo]: send ok!
     [demo]: sending 1 ..
     [demo]: send ok!
     [demo]: sending 2 ..
     [demo]: send ok!
     [demo]: sending 3 ..
     [demo]: send ok!
     [demo]: sending 4 ..
     [demo]: send ok!
     [demo]: sending 5 ..
     [demo]: send ok!
     [demo]: sending 6 ..
     [demo]: send ok!
     [demo]: sending 7 ..
     [demo]: send ok!
     [demo]: sending 8 ..
     [demo]: send ok!
     [demo]: sending 9 ..
     [demo]: send ok!
     ...
     [demo]: sending 96 ..
     [demo]: send ok!
     [demo]: sending 97 ..
     [demo]: send ok!
     [demo]: sending 98 ..
     [demo]: send ok!
     [demo]: sending 99 ..
     [demo]: send ok!
     [tbox]: [lock_profiler]:
     [tbox]: [lock_profiler]: lock: 0xbd1018, name: native_large_allocator, occupied: 0
     [tbox]: [lock_profiler]: lock: 0xbd2a20, name: allocator, occupied: 0
     [tbox]: [lock_profiler]: lock: 0xf5c4f8, name: timer, occupied: 0
     [tbox]: [lock_profiler]: lock: 0xf6a4a8, name: ltimer, occupied: 0
     [tbox]: [small_allocator]:
     [tbox]: [static_fixed_pool]: [16]: peak_size: 288, wast_rate: 4074/10000, pred_failed: 0, item_maxn:          245, free_count: 18, malloc_count: 18
     [tbox]: [static_fixed_pool]: [32]: peak_size: 32, wast_rate: 2558/10000, pred_failed: 0, item_maxn: 246, free_count: 1, malloc_count: 1
     [tbox]: [static_fixed_pool]: [64]: peak_size: 192, wast_rate: 1466/10000, pred_failed: 0, item_maxn: 247, free_count: 3, malloc_count: 3
     [tbox]: [static_fixed_pool]: [96]: peak_size: 2400, wast_rate: 1028/10000, pred_failed: 0, item_maxn: 248, free_count: 25, malloc_count: 25
     [tbox]: [static_fixed_pool]: [128]: peak_size: 7424, wast_rate: 791/10000, pred_failed: 0, item_maxn: 249, free_count: 58, malloc_count: 58
     [tbox]: [static_fixed_pool]: [192]: peak_size: 3456, wast_rate: 541/10000, pred_failed: 0, item_maxn: 250, free_count: 18, malloc_count: 18
     [tbox]: [static_fixed_pool]: [256]: peak_size: 1536, wast_rate: 411/10000, pred_failed: 0, item_maxn: 251, free_count: 6, malloc_count: 6
     [tbox]: [static_fixed_pool]: [384]: peak_size: 384, wast_rate: 278/10000, pred_failed: 0, item_maxn: 252, free_count: 1, malloc_count: 1
     [tbox]: [static_fixed_pool]: [512]: peak_size: 12288, wast_rate: 210/10000, pred_failed: 0, item_maxn: 253, free_count: 25, malloc_count: 25
     [tbox]: [static_fixed_pool]: [1024]: peak_size: 2048, wast_rate: 106/10000, pred_failed: 0, item_maxn: 254, free_count: 2, malloc_count: 2
     [tbox]: [static_fixed_pool]: [2048]: peak_size: 2048, wast_rate: 53/10000, pred_failed: 0, item_maxn: 255, free_count: 1, malloc_count: 1
     [tbox]: [native_large_allocator]:
     [tbox]: [native_large_allocator]: peak_size: 5036250
     [tbox]: [native_large_allocator]: wast_rate: 7/10000
     [tbox]: [native_large_allocator]: free_count: 139
     [tbox]: [native_large_allocator]: malloc_count: 139
     [tbox]: [native_large_allocator]: ralloc_count: 0
     [tbox]: exit: ok

服务器端打印: ./build/demo coroutine_echo_server

    [tbox]: init: ..
    [tbox]: version: tbox_v1_6_2_201706061135_x86_64_sse2_elf by gnu c/c++ 4.8
    [tbox]: init: ok
    [demo]: listening ..
    [demo]: wait ..
    [demo]: wait ..
    ...
   [demo]: echo: hello: 0
   [demo]: echo: hello: 1
   [demo]: echo: hello: 2
   [demo]: echo: hello: 3
   [demo]: echo: hello: 4
   [demo]: echo: hello: 5
   [demo]: echo: hello: 6
   [demo]: echo: hello: 7
   ...
   [demo]: echo: hello: 98
   [demo]: echo: hello: 99
  ...
  [demo]: echo: hello: 85
  [demo]: echo: hello: 86

用上面的方法跑了3-4次之后,前面3次都是正常的,后面就只出现部分打印了。

我没有直接用 xmake run demo coroutine_echo_server, 因为会报错,跟编译报错有关。
xmake编译运行报错的是 ar 库。

xzzh999 commented Jun 6, 2017

是这样的:我的编译方式没有完全按照规定的方式,因为使用xmake编译会有如下错误:

 error: runv(gcc -c -MM -g -Wall -Werror -std=c99 -Ibuild -Ibuild/tbox -D__tb_debug__ -D__tb_small__ 
 -D__tb_prefix__="tbox" -Ipkg/polarssl.pkg/inc/linux -Ipkg/polarssl.pkg/inc -Ipkg/pcre2.pkg/inc/linux -
  Ipkg/pcre2.pkg/inc -DPCRE2_CODE_UNIT_WIDTH=8 -m64 -I/usr/local/include -I/usr/include -o 
  /tmp/.xmake/_2310DDA45999AEBF2041158C3B714B00 src/tbox/tbox.c) failed(127)!

我直接用的makefile, 下面是我的编译方法:

 $ xmake f -m debug
 $ make

能编译通过,能生成 demo;

反复运行了几次 ./build/demo coroutine_echo_client 100 之后, 客户端打印:

     [tbox]: init: ..
     [tbox]: version: tbox_v1_6_2_201706061135_x86_64_sse2_elf by gnu c/c++ 4.8
     [tbox]: init: ok
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     [demo]: connecting 127.0.0.1:9090 ..
     ...
     [demo]: sending 0 ..
     [demo]: send ok!
     [demo]: sending 1 ..
     [demo]: send ok!
     [demo]: sending 2 ..
     [demo]: send ok!
     [demo]: sending 3 ..
     [demo]: send ok!
     [demo]: sending 4 ..
     [demo]: send ok!
     [demo]: sending 5 ..
     [demo]: send ok!
     [demo]: sending 6 ..
     [demo]: send ok!
     [demo]: sending 7 ..
     [demo]: send ok!
     [demo]: sending 8 ..
     [demo]: send ok!
     [demo]: sending 9 ..
     [demo]: send ok!
     ...
     [demo]: sending 96 ..
     [demo]: send ok!
     [demo]: sending 97 ..
     [demo]: send ok!
     [demo]: sending 98 ..
     [demo]: send ok!
     [demo]: sending 99 ..
     [demo]: send ok!
     [tbox]: [lock_profiler]:
     [tbox]: [lock_profiler]: lock: 0xbd1018, name: native_large_allocator, occupied: 0
     [tbox]: [lock_profiler]: lock: 0xbd2a20, name: allocator, occupied: 0
     [tbox]: [lock_profiler]: lock: 0xf5c4f8, name: timer, occupied: 0
     [tbox]: [lock_profiler]: lock: 0xf6a4a8, name: ltimer, occupied: 0
     [tbox]: [small_allocator]:
     [tbox]: [static_fixed_pool]: [16]: peak_size: 288, wast_rate: 4074/10000, pred_failed: 0, item_maxn:          245, free_count: 18, malloc_count: 18
     [tbox]: [static_fixed_pool]: [32]: peak_size: 32, wast_rate: 2558/10000, pred_failed: 0, item_maxn: 246, free_count: 1, malloc_count: 1
     [tbox]: [static_fixed_pool]: [64]: peak_size: 192, wast_rate: 1466/10000, pred_failed: 0, item_maxn: 247, free_count: 3, malloc_count: 3
     [tbox]: [static_fixed_pool]: [96]: peak_size: 2400, wast_rate: 1028/10000, pred_failed: 0, item_maxn: 248, free_count: 25, malloc_count: 25
     [tbox]: [static_fixed_pool]: [128]: peak_size: 7424, wast_rate: 791/10000, pred_failed: 0, item_maxn: 249, free_count: 58, malloc_count: 58
     [tbox]: [static_fixed_pool]: [192]: peak_size: 3456, wast_rate: 541/10000, pred_failed: 0, item_maxn: 250, free_count: 18, malloc_count: 18
     [tbox]: [static_fixed_pool]: [256]: peak_size: 1536, wast_rate: 411/10000, pred_failed: 0, item_maxn: 251, free_count: 6, malloc_count: 6
     [tbox]: [static_fixed_pool]: [384]: peak_size: 384, wast_rate: 278/10000, pred_failed: 0, item_maxn: 252, free_count: 1, malloc_count: 1
     [tbox]: [static_fixed_pool]: [512]: peak_size: 12288, wast_rate: 210/10000, pred_failed: 0, item_maxn: 253, free_count: 25, malloc_count: 25
     [tbox]: [static_fixed_pool]: [1024]: peak_size: 2048, wast_rate: 106/10000, pred_failed: 0, item_maxn: 254, free_count: 2, malloc_count: 2
     [tbox]: [static_fixed_pool]: [2048]: peak_size: 2048, wast_rate: 53/10000, pred_failed: 0, item_maxn: 255, free_count: 1, malloc_count: 1
     [tbox]: [native_large_allocator]:
     [tbox]: [native_large_allocator]: peak_size: 5036250
     [tbox]: [native_large_allocator]: wast_rate: 7/10000
     [tbox]: [native_large_allocator]: free_count: 139
     [tbox]: [native_large_allocator]: malloc_count: 139
     [tbox]: [native_large_allocator]: ralloc_count: 0
     [tbox]: exit: ok

服务器端打印: ./build/demo coroutine_echo_server

    [tbox]: init: ..
    [tbox]: version: tbox_v1_6_2_201706061135_x86_64_sse2_elf by gnu c/c++ 4.8
    [tbox]: init: ok
    [demo]: listening ..
    [demo]: wait ..
    [demo]: wait ..
    ...
   [demo]: echo: hello: 0
   [demo]: echo: hello: 1
   [demo]: echo: hello: 2
   [demo]: echo: hello: 3
   [demo]: echo: hello: 4
   [demo]: echo: hello: 5
   [demo]: echo: hello: 6
   [demo]: echo: hello: 7
   ...
   [demo]: echo: hello: 98
   [demo]: echo: hello: 99
  ...
  [demo]: echo: hello: 85
  [demo]: echo: hello: 86

用上面的方法跑了3-4次之后,前面3次都是正常的,后面就只出现部分打印了。

我没有直接用 xmake run demo coroutine_echo_server, 因为会报错,跟编译报错有关。
xmake编译运行报错的是 ar 库。

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Jun 6, 2017

Member

好的 我调下 另外执行make应该也是下载的master版本的xmake进行编译的,可以手动尝试更新下xmake版本为master 再试下编译

Member

waruqi commented Jun 6, 2017

好的 我调下 另外执行make应该也是下载的master版本的xmake进行编译的,可以手动尝试更新下xmake版本为master 再试下编译

@waruqi waruqi added bug and removed pending labels Jun 9, 2017

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Jun 9, 2017

Member

@xzzh999 你好,这是一个bug,我已经修复,你可以更新到最新代码,再试下。具体原因如下:

tbox的协程在linux下,默认使用了epoll的边缘触发模式,这个模式下检测对方连接关闭,在等待读事件到来时,还需要同时判断EPOLLRDHUP事件是否发生,来决定连接是否被对方关闭。。

tbox的epoll封装wait的时候,确实处理判断了EPOLLRDHUP事件,但是epoll_ctl时候,忘记加上它了,导致部分linux系统上,还是可能正常收到EPOLLRDHUP事件,但是你这的centos上如果不显式设置需要等待EPOLLRDHUP,那么wait的时候,就不会收到这个事件。。因此服务端会有很多连接一直没法关闭。。

现在已修复这个问题,你可以再试下,具体修复patch见:
c4913a5

Member

waruqi commented Jun 9, 2017

@xzzh999 你好,这是一个bug,我已经修复,你可以更新到最新代码,再试下。具体原因如下:

tbox的协程在linux下,默认使用了epoll的边缘触发模式,这个模式下检测对方连接关闭,在等待读事件到来时,还需要同时判断EPOLLRDHUP事件是否发生,来决定连接是否被对方关闭。。

tbox的epoll封装wait的时候,确实处理判断了EPOLLRDHUP事件,但是epoll_ctl时候,忘记加上它了,导致部分linux系统上,还是可能正常收到EPOLLRDHUP事件,但是你这的centos上如果不显式设置需要等待EPOLLRDHUP,那么wait的时候,就不会收到这个事件。。因此服务端会有很多连接一直没法关闭。。

现在已修复这个问题,你可以再试下,具体修复patch见:
c4913a5

@xzzh999

This comment has been minimized.

Show comment
Hide comment
@xzzh999

xzzh999 Jun 9, 2017

@waruqi OK,我周末再测试确认下~

xzzh999 commented Jun 9, 2017

@waruqi OK,我周末再测试确认下~

@xzzh999

This comment has been minimized.

Show comment
Hide comment
@xzzh999

xzzh999 Jun 11, 2017

用 master 分支编译的 xmake 可以编译 tbox了,没有报错。运行xmake run demo coroutine_echo_server
和 xmake run demo coroutine_echo_client 100 也没有报错了;

现在调试打印都是正常的。

xzzh999 commented Jun 11, 2017

用 master 分支编译的 xmake 可以编译 tbox了,没有报错。运行xmake run demo coroutine_echo_server
和 xmake run demo coroutine_echo_client 100 也没有报错了;

现在调试打印都是正常的。

@xzzh999 xzzh999 closed this Jun 11, 2017

@waruqi waruqi removed the need responese label Jun 11, 2017

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Jun 11, 2017

Member

😄

Member

waruqi commented Jun 11, 2017

😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment