Passing Autumn

The same 3 years, and some people from students to as the MVP, and I was in place, then the code to show off the autumn wind, a little sad, a little cool!

Bulletin
Content is very powerful ~ ~ ~ ~ ~ ~ Do not look outside the invasion not as sharp and brother, I felt kind of sense of loss ~ ~ ~

C# Socket服务端线程内存占用大

在开发在线网站压力测试的服务端开发中。。。

结果遇到了以下问题,服务端运行Socket时,发现客户端每增加一个链接,内存占用就多1M。

当链接2000个时,内存占用到2G,真可怕。。

经过多方查证,发现了原来是每个线程启动时,如果遇到Thread.Sleep,默认会有1M的堆栈大小,所以服务端的线程数,导致了大量内存的占用。

再经过重重分析,最后发现Thead类原来有个初始堆栈大小设置,通过设置,占用大小会小一倍。

具体代码为:

Thread thread=new Thread(..参数1...,512);

经过测试,把线程堆栈设为512或以下,实际占用的内存都是一样的,估计微软有个最低限制。

问题“C# Socket服务端线程内存占用大" 就简单记录到这了。
Autumn Park is QBlog the official site, created by the passing autumn, based on the framework data layers developed cyqdata support multi-user, multi-language, multi-database (access, mssql, oracle), directory level url and other powerful blog system
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"

2013/5/11 19:47:14 | Other | |

#1游客[注册][36.251.65.*]2013/6/1 23:58:04
如果是异步Socket 就不存在这个情况了吧! 因为你是用到线程异步????
  • Post Comment