本文介绍了.NET中是否可以使用非阻塞,单线程,异步Web服务器(如Node.js)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看,寻找一种创建单线程,基于事件的非阻塞异步Web服务器。

I was looking at this question, looking for a way to create a single-threaded, event-based nonblocking asynchronous web server in .NET.

,从主线程获取所有IO工作。许多更高级别的框架包装了这种功能,最着名的一个是。

What you are asking for is a way to queue and harvest Asynchronous Procedure Calls for all your IO work from the main thread. Many higher level frameworks wrap this kind functionality, the most famous one being libevent.

这里有一个很好的概述:。

.NET already takes care of scaling for you by have a special "IO Thread Pool" that handles IO access when you call the BeginXYZ methods. This IO Thread Pool must have at least 1 thread per processor on the box. see: ThreadPool.SetMaxThreads.

如果单线程应用程序是一个关键要求(有些疯狂的原因),当然可以使用(见)

If single threaded app is a critical requirement (for some crazy reason) you could, of course, interop all of this stuff in using DllImport (see an example here)

然而,这将是一个非常:

However it would be a very complex and risky task:

所以,总结一下。如果您想要使用APC和完成端口完成所有工作的单线程管理进程,则需要手动对其进行编码。建设它将是风险和棘手的。

So, to recap. If you want a single threaded managed process that does all its work using APC and completion ports, you are going to have to hand code it. Building it would be risky and tricky.

如果您只想要高级网络,则可以继续使用 BeginXYZ 和家庭并放心,它将表现良好,因为它使用APC。您在线程和.NET特定实现之间支付小费用编组的东西。

If you simply want high scale networking, you can keep using BeginXYZ and family and rest assured that it will perform well, since it uses APC. You pay a minor price marshalling stuff between threads and the .NET particular implementation.

来自:

一个有趣的事实是,单线程不是使用完整端口在Windows上执行异步套接字的最快方法,请参见:

An interesting, side fact, is that single threaded is not the fastest way to do async sockets on Windows using completion ports see: http://doc.sch130.nsc.ru/www.sysinternals.com/ntw2k/info/comport.shtml

这篇关于.NET中是否可以使用非阻塞,单线程,异步Web服务器(如Node.js)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 02:10