使用Netty用很少的线程发出大量的http GET请求

问题描述:

不幸的是,JDK的HttpUrlConnection或UrlConnection并非异步运行.因此,如果HTTP连接由于任何原因挂起,您最终将失去一个线程.另外,Selector的多路复用只允许使用几个线程来进行大量的HTTP GET调用. 因此,我一直在开发使用NIO的选择器并进行HTTP GET的代码.因此,该核心工作得很好,除了要完全支持HTTP 1.1外,我还必须支持Keep-Alive,chunked-transfer-mode和HTTP 1.1支持的其他几项功能.

Unfortunately, JDK's HttpUrlConnection or UrlConnection do not run asynchronously. So, if HTTP connections hang for any reason, you will end up loosing a thread. Plus, Selector's multiplexing allows for using only a few threads for making a high number of HTTP GET calls. So, I have been developing a code that uses NIO's Selector and makes HTTP GET. So, the core works well except that to fully support HTTP 1.1, I have to support Keep-Alive, chunked-transfer-mode, and several other things that HTTP 1.1 supports.

因此,我也一直在寻找使用Netty进行此操作的方法,但是我找不到一个示例,该示例演示了如何使用单个线程发出多个HTTP GET请求.

So, I have been also looking to do this with Netty, but I have not been able to find an example, which shows how to make several HTTP GET requests using a single thread.

因此,如果有人可以向我指出一个netty示例或任何其他适当的库,我将不胜感激. 谢谢

So, I would appreciate it if someone could point me to a netty example or any other appropriate library. Thanks

Netty的Channel EventLoop模型管理最小数量的线程以支持最大数量的客户端连接.它已植入框架中.

Netty's Channel EventLoop model manage a minimum number of threads to support a maximum number of client connections. It is baked into the framework.

API文档中有一些HTTP示例(源文件中有一个名为example的文件夹).根据曼宁(Manning)书中的示例,在 GitHub 上还有一些HTTP示例. href ="http://www.manning.com/maurer/" rel ="nofollow">行动中的Netty .本书的第15章-EventLoop和Thread-Model详细讨论了所有这些内容.

There are a few HTTP examples in the API Docs (there is a folder called example in the source files). There are also a few HTTP examples on GitHub based on the examples from the Manning book Netty in Action. Chapter 15 - EventLoop and Thread-Model of this book discusses all this in detail.