hgoldfish / qtnetworkng

QtNetwork Next Generation. A coroutine based network framework for Qt/C++, with more simpler API than boost::asio.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coroutinegroup的一个问题

LooJee opened this issue · comments

你好,我写了一个并发的请求的客户端(用的是go,直接在for循环中创建goroutine来发起连接)来测试README里的socket server时,发现coroutinegroup里所有的cotoutine都是在没有新的连接过来时才执行的。这就导致了如果我的客户端到200个左右的时候,分配空间失败了,抛出了一个bad_alloc的异常。所以,我想请教以下,如何能避免这个问题?谢谢。

Are you Chinese, right? My English isn't very well, so I think it will be better that writing Chinese here.

In English:

What's your operation system and compiler? Can you attach your source code here?

QtNetworkNg use 8MB memory every coroutine in MacOS by default. 200 requests may consume 1.6GB memory, that can cause bad_alloc exception. For Linux, QtNetworkNg use MAP_GROWSDOWN to allocate memory, causing much smaller memory usage.

If you use QtNetworkNg to serve large number of requests, you should enlarge the limits of open files and the system parameter vm.max_map_count.

中文: 是啊,我是**人。能不能把你的源代码贴出来看看?QtNetworkNg 在 MacOS 下可能会消耗大量内存,每 coroutine 申请 8MB 作为栈空间。但在 Linux 下则大大减少。如果想要测试大并发,(在Linux下)需要修改系统的打开文件数和vm.max_map_count系统参数。Windows就算了,QtNetworkNg底层是 libev 不支持Windows大并发。MacOS 没测试过啊。

好的,我用的是windows,谢谢回复。