非阻塞套接字VS的BeginXXX VS的SocketAsyncEventArgs [英] Non-blocking Sockets vs BeginXXX vs SocketAsyncEventArgs

查看:167
本文介绍了非阻塞套接字VS的BeginXXX VS的SocketAsyncEventArgs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请赐教关于当前.NET接口技术?

Can anyone please enlighten me about current .NET socket techniques?

  1. 非阻塞套接字

如果我设置Socket.Blocking = false,并使用异步操作 - 会发生什么事

If I set Socket.Blocking = false and use async operations - what will happen?

是否有轮询多个非阻塞套接字,而不是检查他们的可用性一个接任何方法(像平凡的select()或任何其他机制,一些IOCP相关的可能)除了Socket.Select( )?

Is there any method of polling multiple non-blocking sockets instead of checking them for availability one-by-one (something like trivial select() or any other mechanism, some IOCP-related may be) aside from Socket.Select()?

的BeginXXX并且让SocketAsyncEventArgs

难道他们对阻止套接字引擎盖下运行,只是掩盖线程创建?

Are they operating on blocking sockets under the hood and just hide thread creation?

将在手动创建线程等于使用的BeginXXX方法?

Will manual creation of threads be equal to using BeginXXX methods?

有没有使用的SocketAsyncEventArgs任何其他利弊其他然后它允许创建套接字和一切与之相关的池?

Is there any other pros on using SocketAsyncEventArgs other then it allows to create pool of sockets and everything related to them?

和最后一个问题:如果应用程序正在按某种重仓二进制代理的大部分逻辑单一线程中完成的 - 什么提供了更好的可扩展性:?非阻塞方式或异步操作

And one final question: if app is working as some kind of heavily loaded binary proxy with most logic done in single thread - what provides better scalability: non-blocking approach or async operations?

推荐答案

1 Socket.Select 应该这样做,虽然我不倾向于使用这种方法个人;特别是的IList 招人烦以高音量

1: Socket.Select should do that, although I don't tend to use that approach personally; in particular those IList get annoying at high volumes

2:不,各地的其他方式;的阻塞操作基本上使用非阻塞的背景,但与栅极。不,他们不引擎盖下创建线程 - 除非你的回调时,事情是入站。我这里有一个例子,它是服务使用的SocketAsyncEventArgs 12K连接 - 线程数是一样的东西20.在的SocketAsyncEventArgs 是:

2: no, other way around; the blocking operations are essentially using the non-blocking in the background, but with gates. No, they don't create threads under the hood - unless you count the callback when something is inbound. I have an example here that is serving 12k connections using SocketAsyncEventArgs - the thread count is something like 20. Among the intentions of SocketAsyncEventArgs is that:

  • 要容易得多,有效地集中,而无需大量的创建对象的/每个操作收集
  • 您可以处理的数据可用现在的场景非常有效,而不需要回调在所有(如果该方法返回false,你是为了立即处理数据 - 没有回调将是即将出版)

有关可伸缩性:异步

这篇关于非阻塞套接字VS的BeginXXX VS的SocketAsyncEventArgs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆