简体   繁体   English

如何在.Net中处理多达100k的HTTP连接

[英]How to handle up to 100k HTTP connections in .Net

I am creating a server to monitor the online presence of clients on a webpage. 我正在创建一个服务器来监控网页上客户端的在线状态。

  • There will be 80-100 000 (eighty thousand) simultaneous clients to monitor. 将有80-100万(八万)个并发客户端进行监控。
  • I'm using .Net to write this. 我用.Net写这个。

Clients will contact a (separate) server using JavaScript (on the HTML-page) to tell the server that they are alive/online. 客户端将使用JavaScript(在HTML页面上)联系(单独)服务器,以告知服务器它们是活动/在线的。

I'm considering one of two approaches: 我正在考虑两种方法之一:

  1. Persistent connections with keep-alive sent regularly. 与keep-alive的持续连接定期发送。 This will give me much higher precision on when clients disconnect and I don't need to update memory structure (onlineinfo) too often because we know when client comes and goes. 这将使我在客户端断开连接时具有更高的精度,并且我不需要经常更新内存结构(onlineinfo),因为我们知道客户端何时进出。 Additional benefits to network equipment / bandwidth. 网络设备/带宽的其他好处。

  2. Clients (re)connect at intervals to tell server they are alive. 客户端(重新)每隔一段时间连接一次,告诉服务器它们还活着。 This requires a lot of connections and will necessarily decrease the accuracy. 这需要大量的连接,并且必然会降低准确性。 I imagine intervals like 2-3 minutes is the best we can do. 我想像2-3分钟的间隔是我们能做的最好的。 80k/120=660 connections per second… ASP.Net don't execute too fast so I'm unsure about this. 80k / 120 =每秒660个连接...... ASP.Net执行速度不是太快,所以我对此不确定。 8 core system = ~10 ms per execution. 8核心系统=每次执行约10毫秒。

With this many connections there are obviously some limitations. 有了这么多的联系,显然有一些局限性。 I can't spawn that many threads simultaneously for instance. 例如,我无法同时生成那么多线程。 1 request to IIS spawning an ASP.Net application will use 1 thread until request is done. 1请求IIS产生ASP.Net应用程序将使用1个线程,直到请求完成。

Is the best option to write a stand-alone http-server? 是编写独立的http服务器的最佳选择吗? Doesn't .Nets TcpListener leverage httpd.sys (IIS)? 没有.Nets TcpListener利用httpd.sys(IIS)?

Any (constructive) thoughts on the subject would be appreciated. 关于这个问题的任何(建设性的)想法都将受到赞赏。

Edit: Adding some useful links to this post found by following links from Nicolas Repiquets answer: 编辑:通过以下来自Nicolas Repiquets的链接添加一些有用的链接到这篇文章:

100 000 persistent connections is not a viable option. 100 000个持久连接不是一个可行的选择。

Sending HTTP requests at interval is way more feasible, and writing a dedicated HTTP server is an interesting choice IMO. 以间隔发送HTTP请求更加可行,编写专用HTTP服务器是IMO的一个有趣选择。

Take a look at this question for some orientations. 看看这个问题的某些方向。

我知道你特意说.NET,但是你应该看看NodeJS,因为它正是你想要做的,但它是服务器端的JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM